From 9a31cfa938ae8d10067d066fde29f1e4550a163f Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Mon, 27 Oct 2025 01:34:30 +0100 Subject: [PATCH] Fixes --- common/src/filters.ts | 2 +- web/components/filters/mobile-filters.tsx | 4 ++-- web/components/filters/use-filters.ts | 2 +- web/components/optional-profile-form.tsx | 23 ++++--------------- web/components/profile-about.tsx | 8 +++---- web/components/search-location.tsx | 2 +- .../widgets/choices-toggle-group.tsx | 2 +- .../util/string-or-string-array-to-text.ts | 2 +- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/common/src/filters.ts b/common/src/filters.ts index ebcfc5aa..21f33336 100644 --- a/common/src/filters.ts +++ b/common/src/filters.ts @@ -82,4 +82,4 @@ export const initialFilters: Partial = { export const FilterKeys = Object.keys(initialFilters) as (keyof FilterFields)[] -export type OriginLocation = { id: string; name: string, lat: number, lon: number } +export type OriginLocation = { id: string; name: string | null, lat: number, lon: number } diff --git a/web/components/filters/mobile-filters.tsx b/web/components/filters/mobile-filters.tsx index 459005ca..12b0e907 100644 --- a/web/components/filters/mobile-filters.tsx +++ b/web/components/filters/mobile-filters.tsx @@ -49,8 +49,8 @@ function MobileFilters(props: { const [openFilter, setOpenFilter] = useState(undefined) - function hasAny(filterArray: any[] | undefined) { - return filterArray && filterArray.length > 0 + function hasAny(filterArray: any[] | undefined | null): boolean { + return !!filterArray && filterArray.length > 0 } const [noMinAge, noMaxAge] = getNoMinMaxAge( diff --git a/web/components/filters/use-filters.ts b/web/components/filters/use-filters.ts index e6451559..f7a04c60 100644 --- a/web/components/filters/use-filters.ts +++ b/web/components/filters/use-filters.ts @@ -69,7 +69,7 @@ export const useFilters = (you: Profile | undefined) => { education_levels: you?.education_level ? [you.education_level] : undefined, pref_age_max: (you?.pref_age_max ?? MAX_INT) < 100 ? you?.pref_age_max : undefined, pref_age_min: (you?.pref_age_min ?? MIN_INT) > 18 ? you?.pref_age_min : undefined, - pref_relation_styles: you?.pref_relation_styles.length ? you.pref_relation_styles : undefined, + pref_relation_styles: you?.pref_relation_styles?.length ? you.pref_relation_styles : undefined, pref_romantic_styles: you?.pref_romantic_styles?.length ? you.pref_romantic_styles : undefined, diet: you?.diet?.length ? you.diet : undefined, political_beliefs: you?.political_beliefs?.length ? you.political_beliefs : undefined, diff --git a/web/components/optional-profile-form.tsx b/web/components/optional-profile-form.tsx index b3e91dc2..b5768cf0 100644 --- a/web/components/optional-profile-form.tsx +++ b/web/components/optional-profile-form.tsx @@ -1,4 +1,4 @@ -import {Fragment, useEffect, useRef, useState} from 'react' +import {Fragment, useRef, useState} from 'react' import {Title} from 'web/components/widgets/title' import {Col} from 'web/components/layout/col' import clsx from 'clsx' @@ -112,10 +112,6 @@ export const OptionalProfileUserForm = (props: { } } - const [trans, setTrans] = useState( - profile['gender'].includes('trans') - ) - function setProfileCity(inputCity: City | undefined) { if (!inputCity) { setProfile('geodb_city_id', null) @@ -142,17 +138,6 @@ export const OptionalProfileUserForm = (props: { } } - useEffect(() => { - const currentState = profile['gender'] - if (currentState === 'non-binary') { - setTrans(undefined) - } else if (trans && !currentState.includes('trans-')) { - setProfile('gender', 'trans-' + currentState.replace('trans-', '')) - } else if (!trans && currentState.includes('trans-')) { - setProfile('gender', currentState.replace('trans-', '')) - } - }, [trans, profile['gender']]) - return ( <> {/**/} @@ -214,7 +199,7 @@ export const OptionalProfileUserForm = (props: { setProfile('pref_gender', selected)} /> @@ -282,7 +267,7 @@ export const OptionalProfileUserForm = (props: { { setProfile('pref_relation_styles', selected) setLookingRelationship((selected || []).includes('relationship')) diff --git a/web/components/profile-about.tsx b/web/components/profile-about.tsx index 713c4b77..f5b836bd 100644 --- a/web/components/profile-about.tsx +++ b/web/components/profile-about.tsx @@ -113,9 +113,9 @@ function Seeking(props: { profile: Profile }) { const max = profile.pref_age_max const seekingGenderText = stringOrStringArrayToText({ text: - prefGender.length == 5 + prefGender?.length == 5 ? ['people'] - : prefGender.map((gender) => convertGenderPlural(gender as Gender)), + : prefGender?.map((gender) => convertGenderPlural(gender as Gender)), preText: 'Interested in', asSentence: true, capitalizeFirstLetterOption: false, @@ -150,7 +150,7 @@ function RelationshipType(props: { profile: Profile }) { const {profile} = props const relationshipTypes = profile.pref_relation_styles let seekingGenderText = stringOrStringArrayToText({ - text: relationshipTypes.map((rel) => + text: relationshipTypes?.map((rel) => convertRelationshipType(rel as RelationshipType).toLowerCase() ).sort(), preText: 'Seeking', @@ -161,7 +161,7 @@ function RelationshipType(props: { profile: Profile }) { asSentence: true, capitalizeFirstLetterOption: false, }) - if (relationshipTypes.includes('relationship')) { + if (relationshipTypes?.includes('relationship')) { const romanticStyles = profile.pref_romantic_styles ?.map((style) => REVERTED_ROMANTIC_CHOICES[style].toLowerCase()) .filter(Boolean) diff --git a/web/components/search-location.tsx b/web/components/search-location.tsx index 43ddcf10..7ab26e96 100644 --- a/web/components/search-location.tsx +++ b/web/components/search-location.tsx @@ -11,7 +11,7 @@ function isDigitString(value: string): boolean { export type City = { geodb_city_id: string - city: string + city: string | null region_code: string country: string country_code: string diff --git a/web/components/widgets/choices-toggle-group.tsx b/web/components/widgets/choices-toggle-group.tsx index cf05fa8c..7e0c0de8 100644 --- a/web/components/widgets/choices-toggle-group.tsx +++ b/web/components/widgets/choices-toggle-group.tsx @@ -15,7 +15,7 @@ export type ColorType = keyof typeof colorClasses export function ChoicesToggleGroup>( props: { - currentChoice: T[keyof T] | undefined + currentChoice: T[keyof T] | undefined | null choicesMap: T disabled?: boolean disabledOptions?: Array diff --git a/web/lib/util/string-or-string-array-to-text.ts b/web/lib/util/string-or-string-array-to-text.ts index e726ee28..28cc80db 100644 --- a/web/lib/util/string-or-string-array-to-text.ts +++ b/web/lib/util/string-or-string-array-to-text.ts @@ -1,7 +1,7 @@ import { filterDefined } from 'common/util/array' export default function stringOrStringArrayToText(fields: { - text: string[] | string + text: string[] | string | null | undefined preText?: string postText?: string asSentence?: boolean