Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eric/preferences #1873

Merged
merged 14 commits into from
Nov 12, 2023
Merged

Eric/preferences #1873

merged 14 commits into from
Nov 12, 2023

Conversation

estrattonbailey
Copy link
Member

No description provided.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff was only used by preferences, so I co-located it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining items here will be removed as we update the things that rely on them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed after we replace our My Feeds page stuff

Comment on lines +37 to +40
const feedSourceNSIDs = {
feed: 'app.bsky.feed.generator',
list: 'app.bsky.graph.list',
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a clear source for these yet?

queryKey: usePreferencesQueryKey,
queryFn: async () => {
const res = await agent.getPreferences()
const preferences: UsePreferencesQueryResponse = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set defaults for all (or most at least) values here, and updated types to match

Comment on lines +108 to +111
// triggers a refetch
await queryClient.invalidateQueries({
queryKey: usePreferencesQueryKey,
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rn I'm refetching on every mutation, I figured a shadow cache was overkill for these mutations. We could use RQ cache too.

Comment on lines +37 to +42
export const ILLEGAL_LABEL_GROUP: LabelGroupConfig = {
id: 'illegal',
title: 'Illegal Content',
warning: 'Illegal Content',
values: ['csam', 'dmca-violation', 'nudity-nonconsensual'],
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These and the other three are unused?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah don't worry about that, there's a cleanup pass that needs to happen on the labeling layer to get everything 100%

},
}

export function getModerationOpts({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacement for rootStore.preferences.moderationOpts, but isn't used anywhere yet

Comment on lines +22 to +41
export type UsePreferencesQueryResponse = Omit<
BskyPreferences,
'contentLabels' | 'feedViewPrefs' | 'feeds'
> & {
/*
* Content labels previously included 'show', which has been deprecated in
* favor of 'ignore'. The API can return legacy data from the database, and
* we clean up the data in `usePreferencesQuery`.
*/
contentLabels: Record<ConfigurableLabelGroup, LabelPreference>
feedViewPrefs: BskyPreferences['feedViewPrefs']['home']
/**
* User thread-view prefs, including newer fields that may not be typed yet.
*/
threadViewPrefs: ThreadViewPreferences
userAge: number | undefined
feeds: Required<BskyPreferences['feeds']> & {
unpinned: string[]
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up some types here to include the labs values and computed values done in the hook

Comment on lines +3 to +10
/**
* Content labels previously included 'show', which has been deprecated in
* favor of 'ignore'. The API can return legacy data from the database, and
* we clean up the data in `usePreferencesQuery`.
*
* @deprecated
*/
export function temp__migrateLabelPref(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made this even more obvious

Comment on lines +82 to +86
setBirthDate({birthDate: model.birthDate})

if (IS_PROD(model.serviceUrl)) {
setSavedFeeds(DEFAULT_PROD_FEEDS)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effects, including setting default saved feeds

} from '#/state/queries/preferences'
import {useFeedSourceInfoQuery} from '#/state/queries/feed'

export const NewFeedSourceCard = observer(function FeedSourceCardImpl({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to migrate all usages yet, so built this alongside the old one for now

Comment on lines +31 to +32
const [value, setValue] = useState(initialValue)
const {mutate: setFeedViewPref} = useSetFeedViewPreferencesMutation()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little jumpy as the API requests succeeds and state updates, need to come back here later

Comment on lines +227 to +228
variables?.hideQuotePosts ??
preferences?.feedViewPrefs?.hideQuotePosts
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local optimistic updates here

Comment on lines +158 to +162
const {isPending: isPinPending, mutateAsync: pinFeed} = usePinFeedMutation()
const {isPending: isUnpinPending, mutateAsync: unpinFeed} =
useUnpinFeedMutation()
const {isPending: isMovePending, mutateAsync: setSavedFeeds} =
useSetSaveFeedsMutation()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No optimistic updates here bc I don't have a shared context to use variables and I didn't want to complicate things with the query cache. We can migrate to that if we need to, but for now this works well. Pending states disable buttons while async req is pending.

@estrattonbailey estrattonbailey marked this pull request as ready for review November 11, 2023 22:00
Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merge whenevs

@pfrazee pfrazee merged commit 05b728f into main Nov 12, 2023
3 of 4 checks passed
@pfrazee pfrazee deleted the eric/preferences branch November 12, 2023 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants