diff --git a/src/screens/Settings/InterestsSettings.tsx b/src/screens/Settings/InterestsSettings.tsx index e3b5fcb084..70aeb0acc2 100644 --- a/src/screens/Settings/InterestsSettings.tsx +++ b/src/screens/Settings/InterestsSettings.tsx @@ -1,5 +1,11 @@ import {useMemo, useState} from 'react' import {type TextStyle, View, type ViewStyle} from 'react-native' +import Animated, { + FadeIn, + FadeInDown, + FadeOut, + LinearTransition, +} from 'react-native-reanimated' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {type NativeStackScreenProps} from '@react-navigation/native-stack' @@ -46,20 +52,6 @@ export function InterestsSettingsScreen({}: Props) { - - - Your selected interests help us serve you content you care about. - - - - - {preferences ? ( ) : ( @@ -73,96 +65,33 @@ export function InterestsSettingsScreen({}: Props) { ) } -function Inner({ - preferences, - setIsSaving, -}: { +function Inner({}: { preferences: UsePreferencesQueryResponse setIsSaving: (isSaving: boolean) => void }) { const {_} = useLingui() - const agent = useAgent() - const qc = useQueryClient() const interestsDisplayNames = useInterestsDisplayNames() - const preselectedInterests = useMemo( - () => preferences.interests.tags || [], - [preferences.interests.tags], - ) - const [interests, setInterests] = useState(preselectedInterests) - - const saveInterests = useMemo(() => { - return debounce(async (interests: string[]) => { - const noEdits = - interests.length === preselectedInterests.length && - preselectedInterests.every(pre => { - return interests.find(int => int === pre) - }) - - if (noEdits) return - - setIsSaving(true) - - try { - await agent.setInterestsPref({tags: interests}) - qc.setQueriesData( - {queryKey: preferencesQueryKey}, - (old?: UsePreferencesQueryResponse) => { - if (!old) return old - old.interests.tags = interests - return old - }, - ) - await Promise.all([ - qc.resetQueries({queryKey: createSuggestedStarterPacksQueryKey()}), - qc.resetQueries({queryKey: createGetSuggestedFeedsQueryKey()}), - qc.resetQueries({queryKey: createGetSuggestedUsersQueryKey({})}), - ]) - - Toast.show( - _( - msg({ - message: 'Your interests have been updated!', - context: 'toast', - }), - ), - ) - } catch (error) { - Toast.show( - _( - msg({ - message: 'Failed to save your interests.', - context: 'toast', - }), - ), - 'xmark', - ) - } finally { - setIsSaving(false) - } - }, 1500) - }, [_, agent, setIsSaving, qc, preselectedInterests]) + const [interests, setInterests] = useState([]) const onChangeInterests = async (interests: string[]) => { setInterests(interests) - saveInterests(interests) } + const additional = interests.filter( + interest => + Object.keys(findRecursive(interest, INTERESTS) ?? {}).length > 0, + ) + + console.log('react', findRecursive('react', INTERESTS)) + return ( <> - {interests.length === 0 && ( - - We recommend selecting at least two interests. - - )} - - {INTERESTS.map(interest => { - const name = interestsDisplayNames[interest] - if (!name) return null + {Object.keys(INTERESTS).map(interest => { return ( + {additional.map(interest => { + const found = findRecursive(interest, INTERESTS) ?? {} + console.log(interest) + console.log(found) + console.log( + interests.map( + interest => interest + findRecursive(interest, found), + ), + ) + console.log( + interests + .map(interest => + Object.keys(findRecursive(interest, found) ?? {}), + ) + .filter(x => Boolean(x) && x.length > 0) + .flat(), + ) + const pills = [ + ...Object.keys(found), + ...interests + .map(interest => + Object.keys(findRecursive(interest, found) ?? {}), + ) + .filter(x => Boolean(x) && x.length > 0) + .flat(), + ] + return ( + + {interest} + + {pills.map((interest, index) => { + return ( + + + + + + ) + })} + + + ) + })} ) @@ -180,7 +159,6 @@ function Inner({ export function InterestButton({interest}: {interest: string}) { const t = useTheme() - const interestsDisplayNames = useInterestsDisplayNames() const ctx = Toggle.useItemContext() const styles = useMemo(() => { @@ -219,40 +197,91 @@ export function InterestButton({interest}: {interest: string}) { - {interestsDisplayNames[interest]} + {interest} ) } -const INTERESTS = [ - 'animals', - 'art', - 'books', - 'comedy', - 'comics', - 'culture', - 'dev', - 'education', - 'food', - 'gaming', - 'journalism', - 'movies', - 'music', - 'nature', - 'news', - 'pets', - 'photography', - 'politics', - 'science', - 'sports', - 'tech', - 'tv', - 'writers', -] +type Interests = Record< + string, + {} | Record>> +> + +function findRecursive( + interest: string, + interests: Interests, +): Interests | null { + if (interests[interest]) return interests[interest] + for (const key in interests) { + const found = findRecursive(key, interests[key]) + if (found) return found + } + return null +} + +const INTERESTS = { + animals: {}, + art: { + comics: {}, + illustration: { + 'digital art': {}, + 'hand drawn': {}, + 'furry art': {}, + }, + painting: { + watercolor: {}, + 'fine art': {}, + }, + 'fan art': {}, + sculpture: {}, + 'art history': {}, + }, + books: {}, + comedy: {}, + culture: {}, + dev: { + 'web dev': { + design: {}, + css: {}, + react: { + 'react native': {}, + }, + svelte: {}, + typescript: {}, + }, + 'game dev': {}, + atproto: {}, + }, + education: {}, + food: {}, + gaming: {}, + journalism: {}, + movies: {}, + music: {}, + nature: {}, + news: {}, + pets: { + cats: {}, + dogs: {}, + birds: { + parrots: {}, + canaries: {}, + finches: {}, + }, + fish: {}, + reptiles: {}, + bunnies: {}, + }, + photography: {}, + politics: {}, + science: {}, + sports: {}, + tech: {}, + tv: {}, + writers: {}, +}