Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kolonka "Prostředí" může nabývat vícero hodnot #1128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions components/profile/OccupationSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@ export const OccupationSelect = ({
"looking-for-job": "Hledám práci",
"other": "Jiné",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Navrhuju ještě v rámci téhle změny zrušit možnost Jiné, s těmi checkboxy už mně definitivně nedává smysl :) V databázi projdu a zahodím.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smáznu.

};
const occupationSet = new Set(decodeSelection(occupation));

return (
<div>
<label className="mb-1 block">V jakém prostředí se pohybuješ?</label>
<p className="typo-caption mb-3">
Pokud toho děláš víc, vyber, co převažuje.
Pokud toho děláš víc, klidně vyber více možností.
</p>

<div>
{Object.entries(options).map(([id, label]) => (
<label key={id} className="mb-1 flex items-center">
<input
type="radio"
type="checkbox"
className="mr-3"
name="occupation"
disabled={disabled}
checked={occupation === id}
onChange={() => onChange(id)}
checked={occupationSet.has(id)}
onChange={() => onChange(encodeSelection(occupationSet, id))}
/>
<span>{label}</span>
</label>
Expand All @@ -45,3 +46,15 @@ export const OccupationSelect = ({
</div>
);
};

const encodeSelection = (occupation: Set<string>, id: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chvilku jsem tady bádal nad tím, jestli nemít samostatně něco jako flip<T>(values: Set<T>, value: T) a samostatně encode(values: Set<string>), ale je to samozřejmě naprostá podružnost :)

Copy link
Contributor Author

@drahoja9 drahoja9 Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jakože 2 obecný funkce?

  1. flip by buď odebrala z množiny nebo přidala do množiny prvek.
  2. encode by převáděla množinu na string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Přesně tak. Když pak budu číst encodeSelection(flip(occupationSet, id)), je mně to jasnější.

if (occupation.has(id)) {
occupation.delete(id);
} else {
occupation.add(id);
}
return Array.from(occupation).join("; ");
};

const decodeSelection = (occupation?: string) =>
occupation?.split(/;\s*/).filter((s) => s !== "");
Loading