From cc6edaa17b84b8540c87009b92039d91e0ddf6f9 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 18 Jun 2024 21:43:23 -0700 Subject: [PATCH] tweak routes for edit --- src/Navigation.tsx | 5 +++ src/lib/routes/types.ts | 8 ++-- src/routes.ts | 6 +-- src/screens/StarterPack/StarterPackScreen.tsx | 4 +- src/screens/StarterPack/Wizard/index.tsx | 40 +++++++------------ 5 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 06f7ee3557..ec2dc6a69b 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -325,6 +325,11 @@ function commonScreens(Stack: typeof HomeTab, unreadCountLabel?: string) { getComponent={() => Wizard} options={{title: title(msg`Create a starter pack`), requireAuth: true}} /> + Wizard} + options={{title: title(msg`Edit your starter pack`), requireAuth: true}} + /> ) } diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index 46f9597def..1077d9a854 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -43,8 +43,8 @@ export type CommonNavigatorParams = { MessagesSettings: undefined Feeds: undefined StarterPack: {name: string; rkey: string} - StarterPackWizard: { - name?: string + StarterPackWizard: undefined + StarterPackEdit: { rkey?: string } } @@ -99,8 +99,8 @@ export type AllNavigatorParams = CommonNavigatorParams & { MessagesTab: undefined Messages: {animation?: 'push' | 'pop'} StarterPack: {name: string; rkey: string} - StarterPackWizard: { - name?: string + StarterPackWizard: undefined + StarterPackEdit: { rkey?: string } } diff --git a/src/routes.ts b/src/routes.ts index 3cd1e7a8c3..65a0f4be09 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -42,8 +42,6 @@ export const router = new Router({ MessagesSettings: '/messages/settings', MessagesConversation: '/messages/:conversation', StarterPack: '/starter-pack/:name/:rkey', - StarterPackWizard: [ - '/starter-pack/create/:name/:rkey', - '/starter-pack/create', - ], + StarterPackWizard: '/starter-pack/create', + StarterPackEdit: '/starter-pack/edit/:rkey', }) diff --git a/src/screens/StarterPack/StarterPackScreen.tsx b/src/screens/StarterPack/StarterPackScreen.tsx index 540d735fa2..cdae202c79 100644 --- a/src/screens/StarterPack/StarterPackScreen.tsx +++ b/src/screens/StarterPack/StarterPackScreen.tsx @@ -249,9 +249,7 @@ function Header({ variant="solid" color="secondary" size="small" - onPress={() => - navigation.navigate('StarterPackWizard', {name, rkey}) - }> + onPress={() => navigation.navigate('StarterPackEdit', {rkey})}> Edit diff --git a/src/screens/StarterPack/Wizard/index.tsx b/src/screens/StarterPack/Wizard/index.tsx index b4a65cb698..534460d0cf 100644 --- a/src/screens/StarterPack/Wizard/index.tsx +++ b/src/screens/StarterPack/Wizard/index.tsx @@ -36,7 +36,6 @@ import { useListMembersQuery, } from 'state/queries/list-members' import {useProfileQuery} from 'state/queries/profile' -import {useResolveDidQuery} from 'state/queries/resolve-uri' import { invalidateStarterPack, useStarterPackQuery, @@ -62,24 +61,21 @@ import {Provider} from './State' export function Wizard({ route, -}: NativeStackScreenProps) { - const {name, rkey} = route.params ?? {} +}: NativeStackScreenProps< + CommonNavigatorParams, + 'StarterPackEdit' | 'StarterPackWizard' +>) { + const {rkey} = route.params ?? {} const {currentAccount} = useSession() const moderationOpts = useModerationOpts() const {_} = useLingui() - const { - data: did, - isLoading: isLoadingDid, - isError: isErrorDid, - } = useResolveDidQuery(name) - const { data: starterPack, isLoading: isLoadingStarterPack, isError: isErrorStarterPack, - } = useStarterPackQuery({did, rkey}) + } = useStarterPackQuery({did: currentAccount!.did, rkey}) const listUri = starterPack?.list?.uri const { @@ -95,7 +91,7 @@ export function Wizard({ isError: isErrorProfile, } = useProfileQuery({did: currentAccount?.did}) - const isEdit = Boolean(name && rkey) + const isEdit = Boolean(rkey) const isReady = (!isEdit || (isEdit && starterPack && listItems)) && profile && @@ -105,14 +101,9 @@ export function Wizard({ return ( ) @@ -129,7 +120,6 @@ export function Wizard({ return ( { - if (!did || !rkey) return + if (!rkey) return if (initialListUri) { await invalidateListMembersQuery({queryClient, uri: initialListUri}) } await invalidateActorStarterPacksQuery({ queryClient, - did, + did: currentAccount!.did, }) await invalidateStarterPack({ queryClient, - did, + did: currentAccount!.did, rkey, }) } @@ -244,7 +232,7 @@ function WizardInner({ dispatch({type: 'SetProcessing', processing: true}) try { - if (did && rkey) { + if (rkey) { // Editing an existing starter pack let list: {uri: string; cid: string} | undefined = initialListUri ? {uri: initialListUri, cid: ''} @@ -457,7 +445,7 @@ function WizardInner({ {state.currentStep === 'Details' ? (