From 7cf9eb7e926f4117c26c9c2885357a49fcea8a38 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 20 Jun 2024 15:19:48 -0500 Subject: [PATCH] Fix deletion invalidation, add guards --- src/lib/strings/starter-pack.ts | 10 +++++++ src/screens/StarterPack/StarterPackScreen.tsx | 26 ++++++++++++------- src/state/queries/starter-packs.ts | 13 +++++++++- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/lib/strings/starter-pack.ts b/src/lib/strings/starter-pack.ts index 3794651836..489d0b9231 100644 --- a/src/lib/strings/starter-pack.ts +++ b/src/lib/strings/starter-pack.ts @@ -89,3 +89,13 @@ export function getStarterPackOgCard( return `https://ogcard.cdn.bsky.app/start/${didOrStarterPack.creator.did}/${rkey}` } } + +export function createStarterPackUri({ + did, + rkey, +}: { + did: string + rkey: string +}): string | null { + return new AtUri(`at://${did}/app.bsky.graph.starterpack/${rkey}`).toString() +} diff --git a/src/screens/StarterPack/StarterPackScreen.tsx b/src/screens/StarterPack/StarterPackScreen.tsx index 26879aab32..8d4c8402da 100644 --- a/src/screens/StarterPack/StarterPackScreen.tsx +++ b/src/screens/StarterPack/StarterPackScreen.tsx @@ -368,10 +368,14 @@ function OverflowMenu({ const isOwn = starterPack.creator.did === currentAccount?.did const onDeleteStarterPack = async () => { + if (!starterPack.list) { + logger.error(`Unable to delete starterpack because list is missing`) + return + } + deleteStarterPack({ rkey: routeParams.rkey, - // TODO need to fix types - listUri: starterPack.list!.uri, + listUri: starterPack.list.uri, }) logEvent('starterPack:delete', {}) } @@ -449,14 +453,16 @@ function OverflowMenu({ - + {starterPack.list && ( + + )} diff --git a/src/state/queries/starter-packs.ts b/src/state/queries/starter-packs.ts index 128129329d..ea8224e787 100644 --- a/src/state/queries/starter-packs.ts +++ b/src/state/queries/starter-packs.ts @@ -18,6 +18,7 @@ import { import {until} from 'lib/async/until' import {createStarterPackList} from 'lib/generate-starterpack' import { + createStarterPackUri, httpStarterPackUriToAtUri, parseStarterPackUri, } from 'lib/strings/starter-pack' @@ -261,7 +262,6 @@ export function useDeleteStarterPackMutation({ throw new Error(`Requires logged in user`) } - // TODO parallel? await agent.app.bsky.graph.list.delete({ repo: agent.session.did, rkey: new AtUri(listUri).rkey, @@ -272,6 +272,17 @@ export function useDeleteStarterPackMutation({ }) }, onSuccess: async (_, {listUri, rkey}) => { + const uri = createStarterPackUri({ + did: agent.session!.did, + rkey, + }) + + if (uri) { + await whenAppViewReady(agent, uri, v => { + return Boolean(v?.data?.starterPack) === false + }) + } + await invalidateListMembersQuery({queryClient, uri: listUri}) await invalidateActorStarterPacksQuery({ queryClient,