Wire up progress-guide persistence
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@
|
||||
"open-analyzer": "EXPO_PUBLIC_OPEN_ANALYZER=1 yarn build-web"
|
||||
},
|
||||
"dependencies": {
|
||||
"@atproto/api": "^0.12.22",
|
||||
"@atproto/api": "^0.12.23",
|
||||
"@bam.tech/react-native-image-resizer": "^3.0.4",
|
||||
"@braintree/sanitize-url": "^6.0.2",
|
||||
"@discord/bottom-sheet": "bluesky-social/react-native-bottom-sheet",
|
||||
|
||||
@@ -4,7 +4,6 @@ import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {
|
||||
ProgressGuideName,
|
||||
useProgressGuide,
|
||||
useProgressGuideControls,
|
||||
} from '#/state/shell/progress-guide'
|
||||
@@ -17,10 +16,10 @@ import {ProgressGuideTask} from './Task'
|
||||
export function ProgressGuideList({style}: {style: StyleProp<ViewStyle>}) {
|
||||
const t = useTheme()
|
||||
const {_} = useLingui()
|
||||
const guide = useProgressGuide(ProgressGuideName.Like10AndFollow7)
|
||||
const guide = useProgressGuide('like-10-and-follow-7')
|
||||
const {endProgressGuide} = useProgressGuideControls()
|
||||
|
||||
if (guide?.guide === ProgressGuideName.Like10AndFollow7) {
|
||||
if (guide) {
|
||||
return (
|
||||
<View style={[a.flex_col, a.gap_md, style]}>
|
||||
<View style={[a.flex_row, a.align_center]}>
|
||||
|
||||
@@ -34,4 +34,8 @@ export const DEFAULT_LOGGED_OUT_PREFERENCES: UsePreferencesQueryResponse = {
|
||||
userAge: 13, // TODO(pwi)
|
||||
interests: {tags: []},
|
||||
savedFeeds: [],
|
||||
bskyAppState: {
|
||||
queuedNudges: [],
|
||||
activeProgressGuide: undefined,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -342,3 +342,50 @@ export function useRemoveMutedWordMutation() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useQueueNudgesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (nudges: string | string[]) => {
|
||||
await agent.bskyAppQueueNudges(nudges)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDismissNudgesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (nudges: string | string[]) => {
|
||||
await agent.bskyAppDismissNudges(nudges)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useSetActiveProgressGuideMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (
|
||||
guide: AppBskyActorDefs.BskyAppProgressGuide | undefined,
|
||||
) => {
|
||||
await agent.bskyAppSetActiveProgressGuide(guide)
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,23 +6,22 @@ import {
|
||||
ProgressGuideToast,
|
||||
ProgressGuideToastRef,
|
||||
} from '#/components/ProgressGuide/Toast'
|
||||
import {useSetActiveProgressGuideMutation} from '../queries/preferences'
|
||||
|
||||
export enum ProgressGuideAction {
|
||||
Like = 'like',
|
||||
Follow = 'follow',
|
||||
}
|
||||
|
||||
export enum ProgressGuideName {
|
||||
Like10AndFollow7 = 'like-10-and-follow-7',
|
||||
}
|
||||
type ProgressGuideName = 'like-10-and-follow-7'
|
||||
|
||||
interface BaseProgressGuide {
|
||||
guide: ProgressGuideName
|
||||
guide: string
|
||||
isComplete: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
interface Like10AndFollow7ProgressGuide extends BaseProgressGuide {
|
||||
guide: ProgressGuideName.Like10AndFollow7
|
||||
numLikes: number
|
||||
numFollows: number
|
||||
}
|
||||
@@ -55,10 +54,11 @@ export function useProgressGuideControls() {
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const {_} = useLingui()
|
||||
const {mutate} = useSetActiveProgressGuideMutation()
|
||||
|
||||
const [activeProgressGuide, setActiveProgressGuide] =
|
||||
React.useState<ProgressGuide>({
|
||||
guide: ProgressGuideName.Like10AndFollow7,
|
||||
guide: 'like-10-and-follow-7',
|
||||
numLikes: 0,
|
||||
numFollows: 0,
|
||||
isComplete: false,
|
||||
@@ -71,17 +71,20 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const controls = React.useMemo(() => {
|
||||
return {
|
||||
startProgressGuide(guide: ProgressGuideName) {
|
||||
if (guide === ProgressGuideName.Like10AndFollow7) {
|
||||
setActiveProgressGuide({
|
||||
guide: ProgressGuideName.Like10AndFollow7,
|
||||
if (guide === 'like-10-and-follow-7') {
|
||||
const guideObj = {
|
||||
guide: 'like-10-and-follow-7',
|
||||
numLikes: 0,
|
||||
numFollows: 0,
|
||||
isComplete: false,
|
||||
})
|
||||
}
|
||||
mutate(guideObj)
|
||||
setActiveProgressGuide(guideObj)
|
||||
}
|
||||
},
|
||||
|
||||
endProgressGuide() {
|
||||
mutate(undefined)
|
||||
setActiveProgressGuide(undefined)
|
||||
},
|
||||
|
||||
@@ -90,7 +93,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
if (guide?.isComplete) {
|
||||
return
|
||||
}
|
||||
if (guide?.guide === ProgressGuideName.Like10AndFollow7) {
|
||||
if (guide?.guide === 'like-10-and-follow-7') {
|
||||
if (action === ProgressGuideAction.Like) {
|
||||
guide = {
|
||||
...guide,
|
||||
@@ -120,10 +123,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
mutate(guide)
|
||||
setActiveProgressGuide(guide)
|
||||
},
|
||||
}
|
||||
}, [activeProgressGuide, setActiveProgressGuide])
|
||||
}, [activeProgressGuide, setActiveProgressGuide, mutate])
|
||||
|
||||
return (
|
||||
<ProgressGuideContext.Provider value={activeProgressGuide}>
|
||||
|
||||
@@ -34,15 +34,16 @@
|
||||
jsonpointer "^5.0.0"
|
||||
leven "^3.1.0"
|
||||
|
||||
"@atproto/api@^0.12.22":
|
||||
version "0.12.22"
|
||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.22.tgz#1880a93a0caa4485cd8463bd1e10bf2424b9826c"
|
||||
integrity sha512-TIXSnf3qqyX40Ei/FkK4H24w+7s5rOc63TPwrGakRBOqIgSNBKOggei8I600fJ/AXB7HO6Vp9tBmDVOt2+021A==
|
||||
"@atproto/api@^0.12.23":
|
||||
version "0.12.23"
|
||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.12.23.tgz#b3409817d0b981a64f30d16e8257f0fe261338af"
|
||||
integrity sha512-fgQ30u+q9smX5g41eep7fISSkSAhRkX0inc81PZ82QwcHbFkC8ePaha/KP0CoTaPWKi7EsC89Z/8BEBCJo0oBA==
|
||||
dependencies:
|
||||
"@atproto/common-web" "^0.3.0"
|
||||
"@atproto/lexicon" "^0.4.0"
|
||||
"@atproto/syntax" "^0.3.0"
|
||||
"@atproto/xrpc" "^0.5.0"
|
||||
await-lock "^2.2.2"
|
||||
multiformats "^9.9.0"
|
||||
tlds "^1.234.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user