Skip to content

Commit b94cdba

Browse files
committed
Add diet
1 parent 7252613 commit b94cdba

File tree

18 files changed

+185
-22
lines changed

18 files changed

+185
-22
lines changed

backend/api/src/get-profiles.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type profileQueryType = {
1717
pref_age_max?: number | undefined,
1818
pref_relation_styles?: String[] | undefined,
1919
pref_romantic_styles?: String[] | undefined,
20+
diet?: String[] | undefined,
2021
wants_kids_strength?: number | undefined,
2122
has_kids?: number | undefined,
2223
is_smoker?: boolean | undefined,
@@ -47,6 +48,7 @@ export const loadProfiles = async (props: profileQueryType) => {
4748
pref_age_max,
4849
pref_relation_styles,
4950
pref_romantic_styles,
51+
diet,
5052
wants_kids_strength,
5153
has_kids,
5254
is_smoker,
@@ -85,6 +87,8 @@ export const loadProfiles = async (props: profileQueryType) => {
8587
intersection(pref_relation_styles, l.pref_relation_styles).length) &&
8688
(!pref_romantic_styles ||
8789
intersection(pref_romantic_styles, l.pref_romantic_styles).length) &&
90+
(!diet ||
91+
intersection(diet, l.diet).length) &&
8892
(!wants_kids_strength ||
8993
wants_kids_strength == -1 ||
9094
!l.wants_kids_strength ||
@@ -162,6 +166,12 @@ export const loadProfiles = async (props: profileQueryType) => {
162166
{pref_romantic_styles}
163167
),
164168

169+
diet?.length &&
170+
where(
171+
`diet IS NULL OR diet = '{}' OR diet && $(diet)`,
172+
{diet}
173+
),
174+
165175
!!wants_kids_strength &&
166176
wants_kids_strength !== -1 &&
167177
where(

backend/email/emails/functions/mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const sinclairProfile: ProfileRow = {
4646
has_kids: 0,
4747
is_smoker: false,
4848
drinks_per_month: 0,
49-
is_vegetarian_or_vegan: null,
49+
diet: null,
5050
political_beliefs: ['e/acc', 'libertarian'],
5151
religious_belief_strength: null,
5252
religious_beliefs: null,
@@ -147,7 +147,7 @@ export const jamesProfile: ProfileRow = {
147147
has_kids: 0,
148148
is_smoker: false,
149149
drinks_per_month: 5,
150-
is_vegetarian_or_vegan: null,
150+
diet: null,
151151
political_beliefs: ['libertarian'],
152152
religious_belief_strength: null,
153153
religious_beliefs: '',

backend/supabase/profiles.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS profiles (
2727
height_in_inches INTEGER,
2828
id BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL,
2929
is_smoker BOOLEAN,
30-
is_vegetarian_or_vegan BOOLEAN,
30+
diet TEXT[],
3131
last_modification_time TIMESTAMPTZ DEFAULT now() NOT NULL,
3232
looking_for_matches BOOLEAN DEFAULT TRUE NOT NULL,
3333
messaging_status TEXT DEFAULT 'open'::TEXT NOT NULL,

common/src/api/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ export const API = (_apiTypeCheck = {
350350
pref_age_max: z.coerce.number().optional(),
351351
pref_relation_styles: arraybeSchema.optional(),
352352
pref_romantic_styles: arraybeSchema.optional(),
353+
diet: arraybeSchema.optional(),
353354
wants_kids_strength: z.coerce.number().optional(),
354355
has_kids: z.coerce.number().optional(),
355356
is_smoker: z.coerce.boolean().optional(),

common/src/api/zod-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const optionalProfilesSchema = z.object({
8080
education_level: z.string().optional(),
8181
is_smoker: z.boolean().optional(),
8282
drinks_per_month: z.number().min(0).optional(),
83-
is_vegetarian_or_vegan: z.boolean().optional(),
83+
diet: z.array(z.string()).optional(),
8484
has_kids: z.number().min(0).optional(),
8585
university: z.string().optional(),
8686
occupation_title: z.string().optional(),

common/src/filters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type FilterFields = {
2222
| 'wants_kids_strength'
2323
| 'pref_relation_styles'
2424
| 'pref_romantic_styles'
25+
| 'diet'
2526
| 'is_smoker'
2627
| 'has_kids'
2728
| 'pref_gender'
@@ -62,6 +63,7 @@ export const initialFilters: Partial<FilterFields> = {
6263
is_smoker: undefined,
6364
pref_relation_styles: undefined,
6465
pref_romantic_styles: undefined,
66+
diet: undefined,
6567
pref_gender: undefined,
6668
shortBio: undefined,
6769
orderBy: 'created_time',

common/src/supabase/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ export type Database = {
454454
height_in_inches: number | null
455455
id: number
456456
is_smoker: boolean | null
457-
is_vegetarian_or_vegan: boolean | null
457+
diet: string[] | null
458458
last_modification_time: string
459459
looking_for_matches: boolean
460460
messaging_status: string
@@ -502,7 +502,7 @@ export type Database = {
502502
height_in_inches?: number | null
503503
id?: number
504504
is_smoker?: boolean | null
505-
is_vegetarian_or_vegan?: boolean | null
505+
diet?: string[] | null
506506
last_modification_time?: string
507507
looking_for_matches?: boolean
508508
messaging_status?: string
@@ -550,7 +550,7 @@ export type Database = {
550550
height_in_inches?: number | null
551551
id?: number
552552
is_smoker?: boolean | null
553-
is_vegetarian_or_vegan?: boolean | null
553+
diet?: string[] | null
554554
last_modification_time?: string
555555
looking_for_matches?: boolean
556556
messaging_status?: string

web/components/filters/choices.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ export const POLITICAL_CHOICES = {
2727
'Independent / Other': 'other',
2828
}
2929

30+
export const DIET_CHOICES = {
31+
Omnivore: 'omnivore',
32+
Vegetarian: 'veg',
33+
Vegan: 'vegan',
34+
Keto: 'keto',
35+
Paleo: 'paleo',
36+
Pescetarian: 'pescetarian',
37+
Other: 'other',
38+
}
39+
3040
export const REVERTED_RELATIONSHIP_CHOICES = Object.fromEntries(
3141
Object.entries(RELATIONSHIP_CHOICES).map(([key, value]) => [value, key])
3242
);
@@ -37,4 +47,8 @@ export const REVERTED_ROMANTIC_CHOICES = Object.fromEntries(
3747

3848
export const REVERTED_POLITICAL_CHOICES = Object.fromEntries(
3949
Object.entries(POLITICAL_CHOICES).map(([key, value]) => [value, key])
50+
);
51+
52+
export const REVERTED_DIET_CHOICES = Object.fromEntries(
53+
Object.entries(DIET_CHOICES).map(([key, value]) => [value, key])
4054
);

web/components/filters/desktop-filters.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ChevronDownIcon, ChevronUpIcon} from '@heroicons/react/outline'
2-
import {RelationshipType, RomanticType} from 'web/lib/util/convert-relationship-type'
2+
import {DietType, RelationshipType, RomanticType} from 'web/lib/util/convert-types'
33
import {ReactNode} from 'react'
44
import {FaUserGroup} from 'react-icons/fa6'
55
import {Col} from 'web/components/layout/col'
@@ -21,6 +21,7 @@ import {hasKidsLabels} from "common/has-kids";
2121
import {HasKidsLabel} from "web/components/filters/has-kids-filter";
2222
import {RomanticFilter, RomanticFilterText} from "web/components/filters/romantic-filter";
2323
import {FaHeart} from "react-icons/fa";
24+
import {DietFilter, DietFilterText} from "web/components/filters/diet-filter";
2425

2526
export function DesktopFilters(props: {
2627
filters: Partial<FilterFields>
@@ -171,7 +172,7 @@ export function DesktopFilters(props: {
171172

172173
{includeRelationshipFilters && <>
173174

174-
{/* CONNECTION */}
175+
{/* RELATIONSHIP STYLE */}
175176
<CustomizeableDropdown
176177
buttonContent={(open) => (
177178
<DropdownButton
@@ -291,6 +292,32 @@ export function DesktopFilters(props: {
291292
</>
292293
}
293294

295+
{/* DIET */}
296+
<CustomizeableDropdown
297+
buttonContent={(open) => (
298+
<DropdownButton
299+
open={open}
300+
content={
301+
<Row className="items-center gap-1">
302+
<DietFilterText
303+
options={
304+
filters.diet as
305+
| DietType[]
306+
| undefined
307+
}
308+
highlightedClass={open ? 'text-primary-500' : undefined}
309+
/>
310+
</Row>
311+
}
312+
/>
313+
)}
314+
dropdownMenuContent={
315+
<DietFilter filters={filters} updateFilter={updateFilter}/>
316+
}
317+
popoverClassName="bg-canvas-50"
318+
menuWidth="w-50"
319+
/>
320+
294321
{/* Short Bios */}
295322
<ShortBioToggle
296323
updateFilter={updateFilter}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import clsx from 'clsx'
2+
import {convertDietTypes, DietType,} from 'web/lib/util/convert-types'
3+
import stringOrStringArrayToText from 'web/lib/util/string-or-string-array-to-text'
4+
import {MultiCheckbox} from 'web/components/multi-checkbox'
5+
6+
import {DIET_CHOICES} from "web/components/filters/choices";
7+
import {FilterFields} from "common/filters";
8+
9+
export function DietFilterText(props: {
10+
options: DietType[] | undefined
11+
highlightedClass?: string
12+
}) {
13+
const {options, highlightedClass} = props
14+
const length = (options ?? []).length
15+
16+
if (!options || length < 1) {
17+
return (
18+
<span className={clsx('text-semibold', highlightedClass)}>Any diet</span>
19+
)
20+
}
21+
22+
const convertedTypes = options.map((r) =>
23+
convertDietTypes(r)
24+
)
25+
26+
if (length > 1) {
27+
return (
28+
<span>
29+
<span className={clsx('font-semibold', highlightedClass)}>
30+
Multiple
31+
</span>
32+
</span>
33+
)
34+
}
35+
return (
36+
<div>
37+
<span className={clsx('font-semibold', highlightedClass)}>
38+
{stringOrStringArrayToText({
39+
text: convertedTypes,
40+
capitalizeFirstLetterOption: true,
41+
})}{' '}
42+
</span>
43+
</div>
44+
)
45+
}
46+
47+
export function DietFilter(props: {
48+
filters: Partial<FilterFields>
49+
updateFilter: (newState: Partial<FilterFields>) => void
50+
}) {
51+
const {filters, updateFilter} = props
52+
return (
53+
<MultiCheckbox
54+
selected={filters.diet ?? []}
55+
choices={DIET_CHOICES as any}
56+
onChange={(c) => {
57+
updateFilter({diet: c})
58+
}}
59+
/>
60+
)
61+
}

0 commit comments

Comments
 (0)