Clean choice constants

This commit is contained in:
MartinBraquet
2025-11-12 18:39:56 +01:00
parent acd4c36531
commit 1a17862f45
6 changed files with 84 additions and 80 deletions

View File

@@ -1,12 +1,12 @@
import { faker } from "@faker-js/faker";
import {
RELATIONSHIP_CHOICES,
POLITICAL_CHOICES,
RELIGION_CHOICES,
DIET_CHOICES,
EDUCATION_CHOICES,
} from "../../../../web/components/filters/choices";
import { Races } from "../../../../web/components/race";
import {
RELATIONSHIP_CHOICES,
POLITICAL_CHOICES,
RELIGION_CHOICES,
DIET_CHOICES,
EDUCATION_CHOICES,
RACE_CHOICES,
} from "web/components/filters/choices";
class UserAccountInformation {
@@ -41,7 +41,7 @@ class UserAccountInformation {
diet = Object.values(DIET_CHOICES);
drinks_per_month = faker.number.int({min: 4, max:40});
height_in_inches = faker.number.float({min: 56, max: 78, fractionDigits:2});
ethnicity = Object.values(Races);
ethnicity = Object.values(RACE_CHOICES);
education_level = Object.values(EDUCATION_CHOICES);
company = faker.company.name();
occupation_title = faker.person.jobTitle();

View File

@@ -177,11 +177,23 @@ export const LANGUAGE_CHOICES = {
'Zulu': 'zulu',
}
export const REVERTED_RELATIONSHIP_CHOICES = invert(RELATIONSHIP_CHOICES)
export const REVERTED_RELATIONSHIP_STATUS_CHOICES = invert(RELATIONSHIP_STATUS_CHOICES)
export const REVERTED_ROMANTIC_CHOICES = invert(ROMANTIC_CHOICES)
export const REVERTED_POLITICAL_CHOICES = invert(POLITICAL_CHOICES)
export const REVERTED_DIET_CHOICES = invert(DIET_CHOICES)
export const REVERTED_EDUCATION_CHOICES = invert(EDUCATION_CHOICES)
export const REVERTED_RELIGION_CHOICES = invert(RELIGION_CHOICES)
export const REVERTED_LANGUAGE_CHOICES = invert(LANGUAGE_CHOICES)
export const RACE_CHOICES = {
'Black/African origin': 'african',
'East Asian': 'asian',
'South/Southeast Asian': 'south_asian',
'White/Caucasian': 'caucasian',
'Hispanic/Latino': 'hispanic',
'Middle Eastern': 'middle_eastern',
'Native American/Indigenous': 'native_american',
Other: 'other',
} as const
export const INVERTED_RELATIONSHIP_CHOICES = invert(RELATIONSHIP_CHOICES)
export const INVERTED_RELATIONSHIP_STATUS_CHOICES = invert(RELATIONSHIP_STATUS_CHOICES)
export const INVERTED_ROMANTIC_CHOICES = invert(ROMANTIC_CHOICES)
export const INVERTED_POLITICAL_CHOICES = invert(POLITICAL_CHOICES)
export const INVERTED_DIET_CHOICES = invert(DIET_CHOICES)
export const INVERTED_EDUCATION_CHOICES = invert(EDUCATION_CHOICES)
export const INVERTED_RELIGION_CHOICES = invert(RELIGION_CHOICES)
export const INVERTED_LANGUAGE_CHOICES = invert(LANGUAGE_CHOICES)
export const INVERTED_RACE_CHOICES = invert(RACE_CHOICES)

View File

@@ -13,7 +13,6 @@ import {updateProfile, updateUser} from 'web/lib/api'
import {Column} from 'common/supabase/utils'
import {User} from 'common/user'
import {track} from 'web/lib/service/analytics'
import {Races} from './race'
import {Carousel} from 'web/components/widgets/carousel'
import {tryCatch} from 'common/util/try-catch'
import {ProfileRow} from 'common/profiles/profile'
@@ -32,7 +31,7 @@ import {
DIET_CHOICES,
EDUCATION_CHOICES,
LANGUAGE_CHOICES,
POLITICAL_CHOICES,
POLITICAL_CHOICES, RACE_CHOICES,
RELATIONSHIP_CHOICES,
RELATIONSHIP_STATUS_CHOICES,
RELIGION_CHOICES,
@@ -555,7 +554,7 @@ export const OptionalProfileUserForm = (props: {
<Col className={clsx(colClassName)}>
<label className={clsx(labelClassName)}>Ethnicity/origin</label>
<MultiCheckbox
choices={Races}
choices={RACE_CHOICES}
selected={profile['ethnicity'] ?? []}
onChange={(selected) => setProfile('ethnicity', selected)}
/>

View File

@@ -1,15 +1,15 @@
import clsx from 'clsx'
import {convertRelationshipType, type RelationshipType,} from 'web/lib/util/convert-types'
import {convertRace, convertRelationshipType, type RelationshipType,} from 'web/lib/util/convert-types'
import stringOrStringArrayToText from 'web/lib/util/string-or-string-array-to-text'
import {ReactNode} from 'react'
import {
REVERTED_DIET_CHOICES,
REVERTED_EDUCATION_CHOICES,
REVERTED_LANGUAGE_CHOICES,
REVERTED_POLITICAL_CHOICES,
REVERTED_RELATIONSHIP_STATUS_CHOICES,
REVERTED_RELIGION_CHOICES,
REVERTED_ROMANTIC_CHOICES
INVERTED_DIET_CHOICES,
INVERTED_EDUCATION_CHOICES,
INVERTED_LANGUAGE_CHOICES,
INVERTED_POLITICAL_CHOICES,
INVERTED_RELATIONSHIP_STATUS_CHOICES,
INVERTED_RELIGION_CHOICES,
INVERTED_ROMANTIC_CHOICES
} from 'web/components/filters/choices'
import {BiSolidDrink} from 'react-icons/bi'
import {BsPersonHeart} from 'react-icons/bs'
@@ -24,7 +24,6 @@ import {fromNow} from 'web/lib/util/time'
import {convertGenderPlural, Gender} from 'common/gender'
import {HiOutlineGlobe} from 'react-icons/hi'
import {UserHandles} from 'web/components/user/user-handles'
import {convertRace} from './race'
import {Profile} from 'common/profiles/profile'
import {UserActivity} from "common/user";
import {ClockIcon} from "@heroicons/react/solid";
@@ -80,22 +79,22 @@ export default function ProfileAbout(props: {
<RelationshipType profile={profile}/>
<AboutRow
icon={<BsPersonHeart className="h-5 w-5"/>}
text={profile.relationship_status?.map(v => REVERTED_RELATIONSHIP_STATUS_CHOICES[v])}
text={profile.relationship_status?.map(v => INVERTED_RELATIONSHIP_STATUS_CHOICES[v])}
/>
<Education profile={profile}/>
<Occupation profile={profile}/>
<AboutRow
icon={<MdLanguage className="h-5 w-5"/>}
text={profile.languages?.map(v => REVERTED_LANGUAGE_CHOICES[v])}
text={profile.languages?.map(v => INVERTED_LANGUAGE_CHOICES[v])}
/>
<AboutRow
icon={<RiScales3Line className="h-5 w-5"/>}
text={profile.political_beliefs?.map(belief => REVERTED_POLITICAL_CHOICES[belief])}
text={profile.political_beliefs?.map(belief => INVERTED_POLITICAL_CHOICES[belief])}
suffix={profile.political_details}
/>
<AboutRow
icon={<PiHandsPrayingBold className="h-5 w-5"/>}
text={profile.religion?.map(belief => REVERTED_RELIGION_CHOICES[belief])}
text={profile.religion?.map(belief => INVERTED_RELIGION_CHOICES[belief])}
suffix={profile.religious_beliefs}
/>
<AboutRow
@@ -108,7 +107,7 @@ export default function ProfileAbout(props: {
<Drinks profile={profile}/>
<AboutRow
icon={<GiFruitBowl className="h-5 w-5"/>}
text={profile.diet?.map(e => REVERTED_DIET_CHOICES[e])}
text={profile.diet?.map(e => INVERTED_DIET_CHOICES[e])}
/>
<HasKids profile={profile}/>
<WantsKids profile={profile}/>
@@ -175,7 +174,7 @@ function RelationshipType(props: { profile: Profile }) {
})
if (relationshipTypes?.includes('relationship')) {
const romanticStyles = profile.pref_romantic_styles
?.map((style) => REVERTED_ROMANTIC_CHOICES[style].toLowerCase())
?.map((style) => INVERTED_ROMANTIC_CHOICES[style].toLowerCase())
.filter(Boolean)
if (romanticStyles && romanticStyles.length > 0) {
seekingGenderText += ` (${romanticStyles.join(', ')})`
@@ -198,7 +197,7 @@ function Education(props: { profile: Profile }) {
let text = ''
if (educationLevel) {
text += capitalizeAndRemoveUnderscores(REVERTED_EDUCATION_CHOICES[educationLevel])
text += capitalizeAndRemoveUnderscores(INVERTED_EDUCATION_CHOICES[educationLevel])
}
if (university) {
if (educationLevel) text += ' at '

View File

@@ -1,21 +0,0 @@
import { invert } from 'lodash'
// label -> backend
export const Races = {
'Black/African origin': 'african',
'East Asian': 'asian',
'South/Southeast Asian': 'south_asian',
'White/Caucasian': 'caucasian',
'Hispanic/Latino': 'hispanic',
'Middle Eastern': 'middle_eastern',
'Native American/Indigenous': 'native_american',
Other: 'other',
} as const
export type Race = (typeof Races)[keyof typeof Races]
const raceTolabel = invert(Races)
export function convertRace(race: Race) {
return raceTolabel[race]
}

View File

@@ -1,50 +1,65 @@
import {
REVERTED_DIET_CHOICES,
REVERTED_EDUCATION_CHOICES,
REVERTED_LANGUAGE_CHOICES,
REVERTED_POLITICAL_CHOICES,
REVERTED_RELATIONSHIP_CHOICES, REVERTED_RELATIONSHIP_STATUS_CHOICES,
REVERTED_RELIGION_CHOICES,
REVERTED_ROMANTIC_CHOICES
INVERTED_DIET_CHOICES,
INVERTED_EDUCATION_CHOICES,
INVERTED_LANGUAGE_CHOICES,
INVERTED_POLITICAL_CHOICES,
INVERTED_RACE_CHOICES,
INVERTED_RELATIONSHIP_CHOICES,
INVERTED_RELATIONSHIP_STATUS_CHOICES,
INVERTED_RELIGION_CHOICES,
INVERTED_ROMANTIC_CHOICES
} from "web/components/filters/choices";
export type RelationshipType = keyof typeof REVERTED_RELATIONSHIP_CHOICES
export type RelationshipStatusType = keyof typeof REVERTED_RELATIONSHIP_STATUS_CHOICES
export type RomanticType = keyof typeof REVERTED_ROMANTIC_CHOICES
export type DietType = keyof typeof REVERTED_DIET_CHOICES
export type PoliticalType = keyof typeof REVERTED_POLITICAL_CHOICES
export type EducationType = keyof typeof REVERTED_EDUCATION_CHOICES
export type ReligionType = keyof typeof REVERTED_RELIGION_CHOICES
export type LanguageType = keyof typeof REVERTED_LANGUAGE_CHOICES
export type RelationshipType = keyof typeof INVERTED_RELATIONSHIP_CHOICES
export function convertRelationshipType(relationshipType: RelationshipType) {
return REVERTED_RELATIONSHIP_CHOICES[relationshipType]
return INVERTED_RELATIONSHIP_CHOICES[relationshipType]
}
export type RelationshipStatusType = keyof typeof INVERTED_RELATIONSHIP_STATUS_CHOICES
export function convertRelationshipStatusTypes(relationshipStatusType: RelationshipStatusType) {
return REVERTED_RELATIONSHIP_STATUS_CHOICES[relationshipStatusType]
return INVERTED_RELATIONSHIP_STATUS_CHOICES[relationshipStatusType]
}
export type RomanticType = keyof typeof INVERTED_ROMANTIC_CHOICES
export function convertRomanticTypes(romanticType: RomanticType) {
return REVERTED_ROMANTIC_CHOICES[romanticType]
return INVERTED_ROMANTIC_CHOICES[romanticType]
}
export type DietType = keyof typeof INVERTED_DIET_CHOICES
export function convertDietTypes(dietType: DietType) {
return REVERTED_DIET_CHOICES[dietType]
return INVERTED_DIET_CHOICES[dietType]
}
export type PoliticalType = keyof typeof INVERTED_POLITICAL_CHOICES
export function convertPoliticalTypes(politicalType: PoliticalType) {
return REVERTED_POLITICAL_CHOICES[politicalType]
return INVERTED_POLITICAL_CHOICES[politicalType]
}
export type EducationType = keyof typeof INVERTED_EDUCATION_CHOICES
export function convertEducationTypes(educationType: EducationType) {
return REVERTED_EDUCATION_CHOICES[educationType]
return INVERTED_EDUCATION_CHOICES[educationType]
}
export type ReligionType = keyof typeof INVERTED_RELIGION_CHOICES
export function convertReligionTypes(religionType: ReligionType) {
return REVERTED_RELIGION_CHOICES[religionType]
return INVERTED_RELIGION_CHOICES[religionType]
}
export type LanguageType = keyof typeof INVERTED_LANGUAGE_CHOICES
export function convertLanguageTypes(languageType: LanguageType) {
return REVERTED_LANGUAGE_CHOICES[languageType]
return INVERTED_LANGUAGE_CHOICES[languageType]
}
export type RaceType = keyof typeof INVERTED_RACE_CHOICES
export function convertRace(race: RaceType) {
return INVERTED_RACE_CHOICES[race]
}