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