diff --git a/app/people/[id]/page.tsx b/app/people/[id]/page.tsx index 156d783be..a42059b07 100644 --- a/app/people/[id]/page.tsx +++ b/app/people/[id]/page.tsx @@ -11,7 +11,11 @@ import { getPublicTeamEngagementsForUser, type TeamEngagement, } from "~/src/data/team-engagement"; -import { getUserProfile, type UserProfile } from "~/src/data/user-profile"; +import { + getUserProfile, + semicolonStrToArr, + type UserProfile, +} from "~/src/data/user-profile"; import { Route } from "~/src/routing"; import { defaultAvatarUrl } from "~/src/utils"; @@ -120,7 +124,7 @@ const ProfessionalProfileLink = ({ link }: { link: string }) => ( ); -const InfoTable = ({ profile }: { profile: UserProfile }) => { +function decodeOccupations(occupations?: string): string { const labels: Record = { "private-sector": "V soukromém sektoru", "non-profit": "V nezisku", @@ -130,9 +134,14 @@ const InfoTable = ({ profile }: { profile: UserProfile }) => { "parental-leave": "Jsem na rodičovské", "looking-for-job": "Hledám práci!", }; - const occupation = profile.occupation - ? labels[profile.occupation] - : undefined; + const occupationSet = new Set(semicolonStrToArr(occupations)); + return Array.from(occupationSet) + .map((id) => labels[id]) + .join("; "); +} + +const InfoTable = ({ profile }: { profile: UserProfile }) => { + const occupations = decodeOccupations(profile.occupation); return (
{profile.tags.length > 0 && ( @@ -146,7 +155,7 @@ const InfoTable = ({ profile }: { profile: UserProfile }) => { {profile.availableInDistricts && ( {profile.availableInDistricts} )} - {occupation && {occupation}} + {occupations && {occupations}}
); diff --git a/components/profile/OccupationSelect.tsx b/components/profile/OccupationSelect.tsx index 3566e05d6..1f741e237 100644 --- a/components/profile/OccupationSelect.tsx +++ b/components/profile/OccupationSelect.tsx @@ -1,3 +1,5 @@ +import { semicolonStrToArr } from "~/src/data/user-profile"; + export type Props = { occupation?: string; disabled?: boolean; @@ -17,26 +19,28 @@ export const OccupationSelect = ({ "studying": "Studuji", "parental-leave": "Jsem na rodičovské", "looking-for-job": "Hledám práci", - "other": "Jiné", }; + const occupationSet = new Set(semicolonStrToArr(occupation)); return (

- Pokud toho děláš víc, vyber, co převažuje. + Pokud toho děláš víc, klidně vyber více možností.

{Object.entries(options).map(([id, label]) => ( @@ -45,3 +49,20 @@ export const OccupationSelect = ({
); }; + +/** + * Toggles a value in a set. + */ +function flip(values: Set, value: T): Set { + const newValues = new Set(values); + if (newValues.has(value)) { + newValues.delete(value); + } else { + newValues.add(value); + } + return newValues; +} + +const encodeSelection = (occupation: Set) => { + return Array.from(occupation).join("; "); +}; diff --git a/src/data/user-profile.ts b/src/data/user-profile.ts index be5b65632..6d7ca6f7c 100644 --- a/src/data/user-profile.ts +++ b/src/data/user-profile.ts @@ -273,3 +273,11 @@ const normalize = (s: string) => .replace(/^\s+/, "") .replace(/\s+$/, "") .replace(/\s*\([^)]+\)$/, ""); + +/** + * Decode a semicolon-separated string into an array of strings. + * + * E.g. "foo; bar; baz" -> ["foo", "bar", "baz"] + */ +export const semicolonStrToArr = (occupation?: string) => + occupation?.split(/;\s*/).filter((s) => s !== "") ?? [];