Mark pack as joined if signed up with that pack
This commit is contained in:
@@ -2,6 +2,7 @@ import React from 'react'
|
|||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
import {Image} from 'expo-image'
|
import {Image} from 'expo-image'
|
||||||
import {
|
import {
|
||||||
|
AppBskyActorDefs,
|
||||||
AppBskyGraphDefs,
|
AppBskyGraphDefs,
|
||||||
AppBskyGraphStarterpack,
|
AppBskyGraphStarterpack,
|
||||||
AtUri,
|
AtUri,
|
||||||
@@ -16,6 +17,7 @@ import {useQueryClient} from '@tanstack/react-query'
|
|||||||
|
|
||||||
import {cleanError} from '#/lib/strings/errors'
|
import {cleanError} from '#/lib/strings/errors'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
import {useProfileQuery} from '#/state/queries/profile'
|
||||||
import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs'
|
import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs'
|
||||||
import {HITSLOP_20} from 'lib/constants'
|
import {HITSLOP_20} from 'lib/constants'
|
||||||
import {makeProfileLink, makeStarterPackLink} from 'lib/routes/links'
|
import {makeProfileLink, makeStarterPackLink} from 'lib/routes/links'
|
||||||
@@ -38,6 +40,7 @@ import {atoms as a, useBreakpoints, useTheme} 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 {ArrowOutOfBox_Stroke2_Corner0_Rounded as ArrowOutOfBox} from '#/components/icons/ArrowOutOfBox'
|
import {ArrowOutOfBox_Stroke2_Corner0_Rounded as ArrowOutOfBox} from '#/components/icons/ArrowOutOfBox'
|
||||||
|
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
|
||||||
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
|
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
|
||||||
import {DotGrid_Stroke2_Corner0_Rounded as Ellipsis} from '#/components/icons/DotGrid'
|
import {DotGrid_Stroke2_Corner0_Rounded as Ellipsis} from '#/components/icons/DotGrid'
|
||||||
import {Pencil_Stroke2_Corner0_Rounded as Pencil} from '#/components/icons/Pencil'
|
import {Pencil_Stroke2_Corner0_Rounded as Pencil} from '#/components/icons/Pencil'
|
||||||
@@ -62,6 +65,7 @@ export function StarterPackScreen({route}: StarterPackScreeProps) {
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
|
||||||
const {name, rkey} = route.params
|
const {name, rkey} = route.params
|
||||||
|
const {currentAccount} = useSession()
|
||||||
const moderationOpts = useModerationOpts()
|
const moderationOpts = useModerationOpts()
|
||||||
const {
|
const {
|
||||||
data: did,
|
data: did,
|
||||||
@@ -73,17 +77,27 @@ export function StarterPackScreen({route}: StarterPackScreeProps) {
|
|||||||
isLoading: isLoadingStarterPack,
|
isLoading: isLoadingStarterPack,
|
||||||
isError: isErrorStarterPack,
|
isError: isErrorStarterPack,
|
||||||
} = useStarterPackQuery({did, rkey})
|
} = useStarterPackQuery({did, rkey})
|
||||||
|
const {
|
||||||
|
data: profile,
|
||||||
|
isError: isProfileError,
|
||||||
|
isLoading: isLoadingProfile,
|
||||||
|
} = useProfileQuery({did: currentAccount!.did})
|
||||||
|
|
||||||
const isValid =
|
const isValid =
|
||||||
starterPack &&
|
starterPack &&
|
||||||
AppBskyGraphDefs.validateStarterPackView(starterPack) &&
|
AppBskyGraphDefs.validateStarterPackView(starterPack) &&
|
||||||
AppBskyGraphStarterpack.validateRecord(starterPack.record)
|
AppBskyGraphStarterpack.validateRecord(starterPack.record)
|
||||||
|
|
||||||
if (!did || !starterPack || !isValid || !moderationOpts) {
|
if (!did || !starterPack || !isValid || !moderationOpts || !profile) {
|
||||||
return (
|
return (
|
||||||
<ListMaybePlaceholder
|
<ListMaybePlaceholder
|
||||||
isLoading={isLoadingDid || isLoadingStarterPack || !moderationOpts}
|
isLoading={
|
||||||
isError={isErrorDid || isErrorStarterPack || !isValid}
|
isLoadingDid ||
|
||||||
|
isLoadingStarterPack ||
|
||||||
|
!moderationOpts ||
|
||||||
|
isLoadingProfile
|
||||||
|
}
|
||||||
|
isError={isErrorDid || isErrorStarterPack || !isValid || isProfileError}
|
||||||
errorMessage={_(msg`That starter pack could not be found.`)}
|
errorMessage={_(msg`That starter pack could not be found.`)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -94,6 +108,7 @@ export function StarterPackScreen({route}: StarterPackScreeProps) {
|
|||||||
starterPack={starterPack}
|
starterPack={starterPack}
|
||||||
routeParams={route.params}
|
routeParams={route.params}
|
||||||
moderationOpts={moderationOpts}
|
moderationOpts={moderationOpts}
|
||||||
|
profile={profile}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -102,15 +117,18 @@ function StarterPackScreenInner({
|
|||||||
starterPack,
|
starterPack,
|
||||||
routeParams,
|
routeParams,
|
||||||
moderationOpts,
|
moderationOpts,
|
||||||
|
profile,
|
||||||
}: {
|
}: {
|
||||||
starterPack: AppBskyGraphDefs.StarterPackView
|
starterPack: AppBskyGraphDefs.StarterPackView
|
||||||
routeParams: StarterPackScreeProps['route']['params']
|
routeParams: StarterPackScreeProps['route']['params']
|
||||||
moderationOpts: ModerationOpts
|
moderationOpts: ModerationOpts
|
||||||
|
profile: AppBskyActorDefs.ProfileViewDetailed
|
||||||
}) {
|
}) {
|
||||||
const tabs = [
|
const tabs = [
|
||||||
...(starterPack.list ? ['People'] : []),
|
...(starterPack.list ? ['People'] : []),
|
||||||
...(starterPack.feeds?.length ? ['Feeds'] : []),
|
...(starterPack.feeds?.length ? ['Feeds'] : []),
|
||||||
]
|
]
|
||||||
|
const alreadyJoined = starterPack.uri === profile.joinedViaStarterPack?.uri
|
||||||
|
|
||||||
const qrCodeDialogControl = useDialogControl()
|
const qrCodeDialogControl = useDialogControl()
|
||||||
const shareDialogControl = useDialogControl()
|
const shareDialogControl = useDialogControl()
|
||||||
@@ -153,6 +171,7 @@ function StarterPackScreenInner({
|
|||||||
starterPack={starterPack}
|
starterPack={starterPack}
|
||||||
routeParams={routeParams}
|
routeParams={routeParams}
|
||||||
onOpenShareDialog={onOpenShareDialog}
|
onOpenShareDialog={onOpenShareDialog}
|
||||||
|
alreadyJoined={alreadyJoined}
|
||||||
/>
|
/>
|
||||||
)}>
|
)}>
|
||||||
{starterPack.list != null
|
{starterPack.list != null
|
||||||
@@ -203,10 +222,12 @@ function Header({
|
|||||||
starterPack,
|
starterPack,
|
||||||
routeParams,
|
routeParams,
|
||||||
onOpenShareDialog,
|
onOpenShareDialog,
|
||||||
|
alreadyJoined,
|
||||||
}: {
|
}: {
|
||||||
starterPack: AppBskyGraphDefs.StarterPackView
|
starterPack: AppBskyGraphDefs.StarterPackView
|
||||||
routeParams: StarterPackScreeProps['route']['params']
|
routeParams: StarterPackScreeProps['route']['params']
|
||||||
onOpenShareDialog: () => void
|
onOpenShareDialog: () => void
|
||||||
|
alreadyJoined: boolean
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
@@ -284,12 +305,19 @@ function Header({
|
|||||||
variant="solid"
|
variant="solid"
|
||||||
color="primary"
|
color="primary"
|
||||||
size="small"
|
size="small"
|
||||||
disabled={isProcessing}
|
disabled={isProcessing || alreadyJoined}
|
||||||
onPress={onFollowAll}>
|
onPress={onFollowAll}>
|
||||||
<ButtonText>
|
<ButtonText>
|
||||||
|
{alreadyJoined ? (
|
||||||
|
<Trans>Joined</Trans>
|
||||||
|
) : (
|
||||||
<Trans>Follow all</Trans>
|
<Trans>Follow all</Trans>
|
||||||
{isProcessing && <Loader size="xs" />}
|
)}
|
||||||
</ButtonText>
|
</ButtonText>
|
||||||
|
{isProcessing && <ButtonIcon icon={Loader} position="right" />}
|
||||||
|
{alreadyJoined && (
|
||||||
|
<ButtonIcon icon={Check} position="right" size="xs" />
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<OverflowMenu
|
<OverflowMenu
|
||||||
|
|||||||
Reference in New Issue
Block a user