From 8a0400d9bb453d86057ba1c66f9410c88e507834 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 1 Jul 2024 18:50:37 -0700 Subject: [PATCH] Wire up action captures --- src/components/ProgressGuide/List.tsx | 8 +------- src/screens/StarterPack/StarterPackScreen.tsx | 6 ++++++ src/state/queries/profile.ts | 7 +++++++ src/state/shell/progress-guide.tsx | 10 +++++----- src/view/com/home/HomeHeaderLayoutMobile.tsx | 12 ------------ src/view/com/util/post-ctrls/PostCtrls.tsx | 7 +++++++ 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/components/ProgressGuide/List.tsx b/src/components/ProgressGuide/List.tsx index 7177be3273..a8219debcf 100644 --- a/src/components/ProgressGuide/List.tsx +++ b/src/components/ProgressGuide/List.tsx @@ -4,7 +4,6 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import { - ProgressGuideAction, ProgressGuideName, useProgressGuide, useProgressGuideControls, @@ -19,12 +18,7 @@ export function ProgressGuideList({style}: {style: StyleProp}) { const t = useTheme() const {_} = useLingui() const guide = useProgressGuide(ProgressGuideName.Like10AndFollow7) - const {captureAction, endProgressGuide} = useProgressGuideControls() - - React.useEffect(() => { - const i = setInterval(() => captureAction(ProgressGuideAction.Like), 2e3) - return () => clearInterval(i) - }, [captureAction]) + const {endProgressGuide} = useProgressGuideControls() if (guide?.guide === ProgressGuideName.Like10AndFollow7) { return ( diff --git a/src/screens/StarterPack/StarterPackScreen.tsx b/src/screens/StarterPack/StarterPackScreen.tsx index 2b6f673b1f..f4f33d2bec 100644 --- a/src/screens/StarterPack/StarterPackScreen.tsx +++ b/src/screens/StarterPack/StarterPackScreen.tsx @@ -23,6 +23,10 @@ import { import {cleanError} from '#/lib/strings/errors' import {logger} from '#/logger' import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs' +import { + ProgressGuideAction, + useProgressGuideControls, +} from '#/state/shell/progress-guide' import {batchedUpdates} from 'lib/batchedUpdates' import {HITSLOP_20} from 'lib/constants' import {isBlockedOrBlocking, isMuted} from 'lib/moderation/blocked-and-muted' @@ -305,6 +309,7 @@ function Header({ const queryClient = useQueryClient() const setActiveStarterPack = useSetActiveStarterPack() const {requestSwitchToAccount} = useLoggedOutViewControls() + const {captureAction} = useProgressGuideControls() const [isProcessing, setIsProcessing] = React.useState(false) @@ -369,6 +374,7 @@ function Header({ starterPack: starterPack.uri, count: dids.length, }) + captureAction(ProgressGuideAction.Follow, dids.length) Toast.show(_(msg`All accounts have been followed!`)) } catch (e) { Toast.show(_(msg`An error occurred while trying to follow all`)) diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 6f7f2de792..af00faf276 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -25,6 +25,10 @@ import {STALE} from '#/state/queries' import {resetProfilePostsQueries} from '#/state/queries/post-feed' import {updateProfileShadow} from '../cache/profile-shadow' import {useAgent, useSession} from '../session' +import { + ProgressGuideAction, + useProgressGuideControls, +} from '../shell/progress-guide' import {RQKEY as RQKEY_LIST_CONVOS} from './messages/list-converations' import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts' import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts' @@ -274,12 +278,15 @@ function useProfileFollowMutation( const {currentAccount} = useSession() const agent = useAgent() const queryClient = useQueryClient() + const {captureAction} = useProgressGuideControls() + return useMutation<{uri: string; cid: string}, Error, {did: string}>({ mutationFn: async ({did}) => { let ownProfile: AppBskyActorDefs.ProfileViewDetailed | undefined if (currentAccount) { ownProfile = findProfileQueryData(queryClient, currentAccount.did) } + captureAction(ProgressGuideAction.Follow) logEvent('profile:follow', { logContext, didBecomeMutual: profile.viewer diff --git a/src/state/shell/progress-guide.tsx b/src/state/shell/progress-guide.tsx index 3f73e8fc03..034010f01c 100644 --- a/src/state/shell/progress-guide.tsx +++ b/src/state/shell/progress-guide.tsx @@ -34,11 +34,11 @@ const ProgressGuideContext = React.createContext(undefined) const ProgressGuideControlContext = React.createContext<{ startProgressGuide(guide: ProgressGuideName): void endProgressGuide(): void - captureAction(action: ProgressGuideAction): void + captureAction(action: ProgressGuideAction, count?: number): void }>({ startProgressGuide: (_guide: ProgressGuideName) => {}, endProgressGuide: () => {}, - captureAction: (_action: ProgressGuideAction) => {}, + captureAction: (_action: ProgressGuideAction, _count = 1) => {}, }) export function useProgressGuide(guide: ProgressGuideName) { @@ -85,7 +85,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { setActiveProgressGuide(undefined) }, - captureAction(action: ProgressGuideAction) { + captureAction(action: ProgressGuideAction, count = 1) { let guide = activeProgressGuide if (guide?.isComplete) { return @@ -94,7 +94,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { if (action === ProgressGuideAction.Like) { guide = { ...guide, - numLikes: (guide.numLikes || 0) + 1, + numLikes: (guide.numLikes || 0) + count, } if (guide.numLikes === 1) { firstLikeToastRef.current?.open() @@ -109,7 +109,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { if (action === ProgressGuideAction.Follow) { guide = { ...guide, - numFollows: (guide.numFollows || 0) + 1, + numFollows: (guide.numFollows || 0) + count, } } if (guide.numLikes >= 10 && guide.numFollows >= 7) { diff --git a/src/view/com/home/HomeHeaderLayoutMobile.tsx b/src/view/com/home/HomeHeaderLayoutMobile.tsx index 168340d7af..ed353cf168 100644 --- a/src/view/com/home/HomeHeaderLayoutMobile.tsx +++ b/src/view/com/home/HomeHeaderLayoutMobile.tsx @@ -6,10 +6,6 @@ import {useLingui} from '@lingui/react' import {useSession} from '#/state/session' import {useSetDrawerOpen} from '#/state/shell/drawer-open' -import { - ProgressGuideAction, - useProgressGuideControls, -} from '#/state/shell/progress-guide' import {useShellLayout} from '#/state/shell/shell-layout' import {HITSLOP_10} from 'lib/constants' import {useMinimalShellHeaderTransform} from 'lib/hooks/useMinimalShellTransform' @@ -38,19 +34,11 @@ export function HomeHeaderLayoutMobile({ const {headerHeight} = useShellLayout() const headerMinimalShellTransform = useMinimalShellHeaderTransform() const {hasSession} = useSession() - const {captureAction} = useProgressGuideControls() const onPressAvi = React.useCallback(() => { setDrawerOpen(true) }, [setDrawerOpen]) - React.useEffect(() => { - const i = setInterval(() => captureAction(ProgressGuideAction.Like), 1000) - return () => { - clearInterval(i) - } - }, [captureAction]) - return (