mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-13 19:17:15 -04:00
Add location column
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -98,11 +98,11 @@ export const useFilters = (you: Lover | undefined) => {
|
||||
}
|
||||
|
||||
const yourFilters: Partial<FilterFields> = {
|
||||
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
|
||||
|
||||
@@ -65,19 +65,15 @@ export type locationType = {
|
||||
radius: number
|
||||
}
|
||||
|
||||
export type FilterFieldsWithLocation = FilterFields & {
|
||||
location: locationType
|
||||
}
|
||||
|
||||
|
||||
function formatFilters(filters: Partial<FilterFieldsWithLocation>): ReactElement | null {
|
||||
function formatFilters(filters: Partial<FilterFields>, 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<FilterFieldsWithLocation>): ReactElement
|
||||
} else {
|
||||
text = `${text}+`
|
||||
}
|
||||
ageEntry = <span>{text}</span>
|
||||
ageEntry = <span key='age'>{text}</span>
|
||||
}
|
||||
|
||||
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<FilterFieldsWithLocation>): 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<FilterFieldsWithLocation>): 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(<span key="location">{locString}</span>)
|
||||
}
|
||||
|
||||
if (entries.length === 0) return <span>Anything</span>
|
||||
|
||||
// Join with " • " separators
|
||||
return (
|
||||
@@ -176,7 +172,7 @@ function ButtonModal(props: {
|
||||
{(bookmarkedSearches || []).map((search) => (
|
||||
<li key={search.id}
|
||||
className="items-center justify-between gap-2 list-item marker:text-ink-500 marker:font-bold">
|
||||
{formatFilters(search.search_filters as Partial<FilterFields>)}
|
||||
{formatFilters(search.search_filters as Partial<FilterFields>, search.location as locationType)}
|
||||
<button
|
||||
onClick={async () => {
|
||||
await deleteBookmarkedSearch(search.id)
|
||||
|
||||
@@ -28,9 +28,8 @@ export const submitBookmarkedSearch = async (
|
||||
) => {
|
||||
if (!filters) return
|
||||
if (!userId) return
|
||||
const fullFilter = {...filters, ...{location: locationFilterProps}}
|
||||
|
||||
const row = {search_filters: fullFilter, creator_id: userId}
|
||||
const row = {search_filters: filters, location: locationFilterProps, creator_id: userId}
|
||||
const input = {
|
||||
...filterKeys(row, (key, _) => !['id', 'created_time', 'last_notified_at'].includes(key)),
|
||||
} as BookmarkedSearchSubmitType
|
||||
|
||||
Reference in New Issue
Block a user