diff --git a/backend/supabase/bookmarked_searches.sql b/backend/supabase/bookmarked_searches.sql index d3f44453..3902e213 100644 --- a/backend/supabase/bookmarked_searches.sql +++ b/backend/supabase/bookmarked_searches.sql @@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS bookmarked_searches ( created_time TIMESTAMPTZ DEFAULT now() NOT NULL, creator_id TEXT NOT NULL, search_filters JSONB, + location JSONB, last_notified_at TIMESTAMPTZ DEFAULT NULL, search_name TEXT DEFAULT NULL ); diff --git a/common/src/supabase/schema.ts b/common/src/supabase/schema.ts index faf8cabb..ab8075f1 100644 --- a/common/src/supabase/schema.ts +++ b/common/src/supabase/schema.ts @@ -20,6 +20,7 @@ export type Database = { creator_id: string id: number last_notified_at: string | null + location: Json | null search_filters: Json | null search_name: string | null } @@ -28,6 +29,7 @@ export type Database = { creator_id: string id?: never last_notified_at?: string | null + location?: Json | null search_filters?: Json | null search_name?: string | null } @@ -36,6 +38,7 @@ export type Database = { creator_id?: string id?: never last_notified_at?: string | null + location?: Json | null search_filters?: Json | null search_name?: string | null } diff --git a/web/components/filters/search.tsx b/web/components/filters/search.tsx index f1208940..2c840a8b 100644 --- a/web/components/filters/search.tsx +++ b/web/components/filters/search.tsx @@ -54,6 +54,7 @@ function getRandomPair(): string { } +const MAX_BOOKMARKED_SEARCHES = 10; export const Search = (props: { youLover: Lover | undefined | null starredUserIds: string[] @@ -196,8 +197,8 @@ export const Search = (props: { } loading={loadingBookmark} onClick={() => { - if (bookmarkedSearches.length >= 10) { - toast.error('You cannot bookmark more searches; please delete one first.') + if (bookmarkedSearches.length >= MAX_BOOKMARKED_SEARCHES) { + toast.error(`You can bookmark maximum ${MAX_BOOKMARKED_SEARCHES} searches; please delete one first.`) setOpenBookmarks(true) return } diff --git a/web/components/filters/use-filters.ts b/web/components/filters/use-filters.ts index acfec24d..936aa55a 100644 --- a/web/components/filters/use-filters.ts +++ b/web/components/filters/use-filters.ts @@ -98,11 +98,11 @@ export const useFilters = (you: Lover | undefined) => { } const yourFilters: Partial = { - genders: you?.pref_gender, - pref_gender: you ? [you.gender] : undefined, + genders: you?.pref_gender?.length ? you.pref_gender : undefined, + pref_gender: you?.gender?.length ? [you.gender] : undefined, pref_age_max: you?.pref_age_max, pref_age_min: you?.pref_age_min, - pref_relation_styles: you?.pref_relation_styles, + pref_relation_styles: you?.pref_relation_styles.length ? you.pref_relation_styles : undefined, wants_kids_strength: wantsKidsDatabaseToWantsKidsFilter( (you?.wants_kids_strength ?? 2) as wantsKidsDatabase ), @@ -115,10 +115,11 @@ export const useFilters = (you: Lover | undefined) => { !!you && !!location && location.id === you.geodb_city_id && - isEqual(filters.genders, yourFilters.genders) && - !!filters.pref_gender && - filters.pref_gender.length == 1 && - filters.pref_gender[0] == you.gender && + isEqual(filters.genders?.length ? filters.genders : undefined, yourFilters.genders?.length ? yourFilters.genders : undefined) && + // isEqual(filters.pref_gender?.length ? filters.pref_gender[0] : undefined, you.gender) && + // you?.pref_gender.length && + // filters.pref_gender.length == 1 && + // filters.pref_gender[0] == you.gender && filters.pref_age_max == yourFilters.pref_age_max && filters.pref_age_min == yourFilters.pref_age_min && filters.wants_kids_strength == yourFilters.wants_kids_strength diff --git a/web/components/searches/button.tsx b/web/components/searches/button.tsx index d05359cc..77e99e00 100644 --- a/web/components/searches/button.tsx +++ b/web/components/searches/button.tsx @@ -65,19 +65,15 @@ export type locationType = { radius: number } -export type FilterFieldsWithLocation = FilterFields & { - location: locationType -} - -function formatFilters(filters: Partial): ReactElement | null { +function formatFilters(filters: Partial, location: locationType | null): ReactElement | null { const entries: ReactElement[] = [] let ageEntry = null let ageMin: number | undefined = filters.pref_age_min if (ageMin == 18) ageMin = undefined let ageMax = filters.pref_age_max; - if (ageMax == 99) ageMax = undefined + if (ageMax == 99 || ageMax == 100) ageMax = undefined if (ageMin || ageMax) { let text: string = 'Age: ' if (ageMin) text = `${text}${ageMin}` @@ -90,13 +86,13 @@ function formatFilters(filters: Partial): ReactElement } else { text = `${text}+` } - ageEntry = {text} + ageEntry = {text} } Object.entries(filters).forEach(([key, value]) => { const typedKey = key as keyof FilterFields - if (!value) return + if (value === undefined || value === null) return if (typedKey == 'pref_age_min' || typedKey == 'pref_age_max' || typedKey == 'geodbCityIds') return if (Array.isArray(value) && value.length === 0) return if (initialFilters[typedKey] === value) return @@ -106,11 +102,6 @@ function formatFilters(filters: Partial): ReactElement let stringValue = value if (key === 'has_kids') stringValue = hasKidsNames[value as number] if (key === 'wants_kids_strength') stringValue = wantsKidsNames[value as number] - if (key === 'location') { - const locValue = value as locationType - if (!locValue?.location?.name) return - stringValue = `${locValue?.location?.name} (${locValue?.radius}mi)` - } if (Array.isArray(value)) stringValue = value.join(', ') if (!label) { @@ -133,7 +124,12 @@ function formatFilters(filters: Partial): ReactElement if (ageEntry) entries.push(ageEntry) - if (entries.length === 0) return null + if (location?.location?.name) { + const locString = `${location?.location?.name} (${location?.radius}mi)` + entries.push({locString}) + } + + if (entries.length === 0) return Anything // Join with " • " separators return ( @@ -176,7 +172,7 @@ function ButtonModal(props: { {(bookmarkedSearches || []).map((search) => (
  • - {formatFilters(search.search_filters as Partial)} + {formatFilters(search.search_filters as Partial, search.location as locationType)}