clean up onSuccess callback

This commit is contained in:
Chenyu Huang
2025-08-19 15:59:12 -07:00
parent f42b5831bb
commit e32f280f47
3 changed files with 16 additions and 26 deletions
+5 -18
View File
@@ -35,16 +35,6 @@ import {TimesLarge_Stroke2_Corner0_Rounded} from '../icons/Times'
type StarterPackWithMembership = type StarterPackWithMembership =
AppBskyGraphGetStarterPacksWithMembership.StarterPackWithMembership AppBskyGraphGetStarterPacksWithMembership.StarterPackWithMembership
let dialogCallbacks: {
onSuccess?: () => void
} = {}
export function notifyDialogSuccess() {
if (dialogCallbacks.onSuccess) {
dialogCallbacks.onSuccess()
}
}
export type StarterPackDialogProps = { export type StarterPackDialogProps = {
control: Dialog.DialogControlProps control: Dialog.DialogControlProps
targetDid: string targetDid: string
@@ -60,19 +50,16 @@ export function StarterPackDialog({
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const requireEmailVerification = useRequireEmailVerification() const requireEmailVerification = useRequireEmailVerification()
React.useEffect(() => {
dialogCallbacks.onSuccess = () => {
if (!control.isOpen) {
control.open()
}
}
}, [control])
const navToWizard = React.useCallback(() => { const navToWizard = React.useCallback(() => {
control.close() control.close()
navigation.navigate('StarterPackWizard', { navigation.navigate('StarterPackWizard', {
fromDialog: true, fromDialog: true,
targetDid: targetDid, targetDid: targetDid,
onSuccess: () => {
if (!control.isOpen) {
control.open()
}
},
}) })
}, [navigation, control, targetDid]) }, [navigation, control, targetDid])
+5 -1
View File
@@ -79,7 +79,11 @@ export type CommonNavigatorParams = {
Start: {name: string; rkey: string} Start: {name: string; rkey: string}
StarterPack: {name: string; rkey: string; new?: boolean} StarterPack: {name: string; rkey: string; new?: boolean}
StarterPackShort: {code: string} StarterPackShort: {code: string}
StarterPackWizard: {fromDialog?: boolean; targetDid?: string} StarterPackWizard: {
fromDialog?: boolean
targetDid?: string
onSuccess?: () => void
}
StarterPackEdit: {rkey?: string} StarterPackEdit: {rkey?: string}
VideoFeed: VideoFeedSourceContext VideoFeed: VideoFeedSourceContext
} }
+6 -7
View File
@@ -54,7 +54,6 @@ import {StepProfiles} from '#/screens/StarterPack/Wizard/StepProfiles'
import {atoms as a, useTheme, web} from '#/alf' import {atoms as a, useTheme, web} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {useDialogControl} from '#/components/Dialog' import {useDialogControl} from '#/components/Dialog'
import {notifyDialogSuccess} from '#/components/dialogs/StarterPackDialog'
import * as Layout from '#/components/Layout' import * as Layout from '#/components/Layout'
import {ListMaybePlaceholder} from '#/components/Lists' import {ListMaybePlaceholder} from '#/components/Lists'
import {Loader} from '#/components/Loader' import {Loader} from '#/components/Loader'
@@ -73,6 +72,7 @@ export function Wizard({
const rkey = 'rkey' in params ? params.rkey : undefined const rkey = 'rkey' in params ? params.rkey : undefined
const fromDialog = 'fromDialog' in params ? params.fromDialog : false const fromDialog = 'fromDialog' in params ? params.fromDialog : false
const targetDid = 'targetDid' in params ? params.targetDid : undefined const targetDid = 'targetDid' in params ? params.targetDid : undefined
const onSuccess = 'onSuccess' in params ? params.onSuccess : undefined
const {currentAccount} = useSession() const {currentAccount} = useSession()
const moderationOpts = useModerationOpts() const moderationOpts = useModerationOpts()
@@ -144,6 +144,7 @@ export function Wizard({
profile={profile} profile={profile}
moderationOpts={moderationOpts} moderationOpts={moderationOpts}
fromDialog={fromDialog} fromDialog={fromDialog}
onSuccess={onSuccess}
/> />
</Provider> </Provider>
</Layout.Screen> </Layout.Screen>
@@ -156,12 +157,14 @@ function WizardInner({
profile, profile,
moderationOpts, moderationOpts,
fromDialog, fromDialog,
onSuccess,
}: { }: {
currentStarterPack?: AppBskyGraphDefs.StarterPackView currentStarterPack?: AppBskyGraphDefs.StarterPackView
currentListItems?: AppBskyGraphDefs.ListItemView[] currentListItems?: AppBskyGraphDefs.ListItemView[]
profile: AppBskyActorDefs.ProfileViewDetailed profile: AppBskyActorDefs.ProfileViewDetailed
moderationOpts: ModerationOpts moderationOpts: ModerationOpts
fromDialog?: boolean fromDialog?: boolean
onSuccess?: () => void
}) { }) {
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const {_} = useLingui() const {_} = useLingui()
@@ -231,7 +234,7 @@ function WizardInner({
// If launched from ProfileMenu dialog, notify the dialog and go back // If launched from ProfileMenu dialog, notify the dialog and go back
if (fromDialog) { if (fromDialog) {
navigation.goBack() navigation.goBack()
notifyDialogSuccess() onSuccess?.()
} else { } else {
// Original behavior for other entry points // Original behavior for other entry points
navigation.replace('StarterPack', { navigation.replace('StarterPack', {
@@ -366,11 +369,7 @@ function WizardInner({
</Container> </Container>
{state.currentStep !== 'Details' && ( {state.currentStep !== 'Details' && (
<Footer <Footer onNext={onNext} nextBtnText={currUiStrings.nextBtn} />
onNext={onNext}
nextBtnText={currUiStrings.nextBtn}
profile={profile}
/>
)} )}
<WizardEditListDialog <WizardEditListDialog
control={editDialogControl} control={editDialogControl}