about summary refs log tree commit diff
path: root/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'src/state')
-rw-r--r--src/state/queries/starter-packs.ts20
-rw-r--r--src/state/shell/logged-out.tsx20
2 files changed, 15 insertions, 25 deletions
diff --git a/src/state/queries/starter-packs.ts b/src/state/queries/starter-packs.ts
index c279b6dc4..f441a8ed2 100644
--- a/src/state/queries/starter-packs.ts
+++ b/src/state/queries/starter-packs.ts
@@ -25,13 +25,22 @@ import {
   parseStarterPackUri,
 } from 'lib/strings/starter-pack'
 import {invalidateActorStarterPacksQuery} from 'state/queries/actor-starter-packs'
+import {STALE} from 'state/queries/index'
 import {invalidateListMembersQuery} from 'state/queries/list-members'
 import {useAgent} from 'state/session'
 
 const RQKEY_ROOT = 'starter-pack'
-const RQKEY = (did?: string, rkey?: string) => {
-  if (did?.startsWith('https://') || did?.startsWith('at://')) {
-    const parsed = parseStarterPackUri(did)
+const RQKEY = ({
+  uri,
+  did,
+  rkey,
+}: {
+  uri?: string
+  did?: string
+  rkey?: string
+}) => {
+  if (uri?.startsWith('https://') || uri?.startsWith('at://')) {
+    const parsed = parseStarterPackUri(uri)
     return [RQKEY_ROOT, parsed?.name, parsed?.rkey]
   } else {
     return [RQKEY_ROOT, did, rkey]
@@ -50,7 +59,7 @@ export function useStarterPackQuery({
   const agent = useAgent()
 
   return useQuery<StarterPackView>({
-    queryKey: RQKEY(did, rkey),
+    queryKey: RQKEY(uri ? {uri} : {did, rkey}),
     queryFn: async () => {
       if (!uri) {
         uri = `at://${did}/app.bsky.graph.starterpack/${rkey}`
@@ -64,6 +73,7 @@ export function useStarterPackQuery({
       return res.data.starterPack
     },
     enabled: Boolean(uri) || Boolean(did && rkey),
+    staleTime: STALE.MINUTES.FIVE,
   })
 }
 
@@ -76,7 +86,7 @@ export async function invalidateStarterPack({
   did: string
   rkey: string
 }) {
-  await queryClient.invalidateQueries({queryKey: RQKEY(did, rkey)})
+  await queryClient.invalidateQueries({queryKey: RQKEY({did, rkey})})
 }
 
 interface UseCreateStarterPackMutationParams {
diff --git a/src/state/shell/logged-out.tsx b/src/state/shell/logged-out.tsx
index 2c577fdd2..dc78d03d5 100644
--- a/src/state/shell/logged-out.tsx
+++ b/src/state/shell/logged-out.tsx
@@ -50,7 +50,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
   const activeStarterPack = useActiveStarterPack()
   const {hasSession} = useSession()
   const shouldShowStarterPack = Boolean(activeStarterPack?.uri) && !hasSession
-
   const [state, setState] = React.useState<State>({
     showLoggedOut: shouldShowStarterPack,
     requestedAccountSwitchTo: shouldShowStarterPack
@@ -60,25 +59,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
       : undefined,
   })
 
-  const [prevActiveStarterPack, setPrevActiveStarterPack] =
-    React.useState(activeStarterPack)
-  if (activeStarterPack?.uri !== prevActiveStarterPack?.uri) {
-    setPrevActiveStarterPack(activeStarterPack)
-    if (activeStarterPack) {
-      setState(s => ({
-        ...s,
-        showLoggedOut: true,
-        requestedAccountSwitchTo: 'starterpack',
-      }))
-    } else {
-      setState(s => ({
-        ...s,
-        showLoggedOut: false,
-        requestedAccountSwitchTo: undefined,
-      }))
-    }
-  }
-
   const controls = React.useMemo<Controls>(
     () => ({
       setShowLoggedOut(show) {