Handle pushing to starterpack screen when unauthed (#4692)
This commit is contained in:
parent
91c4aa7c2d
commit
8ebf9cc4b1
6 changed files with 143 additions and 132 deletions
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue