Change size (#4957)
This commit is contained in:
parent
6616a6467e
commit
61f0be705d
11 changed files with 170 additions and 90 deletions
|
@ -23,6 +23,7 @@ import {useProgressGuideControls} from '#/state/shell/progress-guide'
|
|||
import {uploadBlob} from 'lib/api'
|
||||
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
||||
import {useSetHasCheckedForStarterPack} from 'state/preferences/used-starter-packs'
|
||||
import {getAllListMembers} from 'state/queries/list-members'
|
||||
import {
|
||||
useActiveStarterPack,
|
||||
useSetActiveStarterPack,
|
||||
|
@ -73,18 +74,20 @@ export function StepFinished() {
|
|||
starterPack: activeStarterPack.uri,
|
||||
})
|
||||
starterPack = spRes.data.starterPack
|
||||
|
||||
if (starterPack.list) {
|
||||
const listRes = await agent.app.bsky.graph.getList({
|
||||
list: starterPack.list.uri,
|
||||
limit: 50,
|
||||
})
|
||||
listItems = listRes.data.items
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Failed to fetch starter pack', {safeMessage: e})
|
||||
// don't tell the user, just get them through onboarding.
|
||||
}
|
||||
try {
|
||||
if (starterPack?.list) {
|
||||
listItems = await getAllListMembers(agent, starterPack.list.uri)
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Failed to fetch starter pack list items', {
|
||||
safeMessage: e,
|
||||
})
|
||||
// don't tell the user, just get them through onboarding.
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
BskyAgent,
|
||||
} from '@atproto/api'
|
||||
import {TID} from '@atproto/common-web'
|
||||
import chunk from 'lodash.chunk'
|
||||
|
||||
import {until} from '#/lib/async/until'
|
||||
|
||||
|
@ -29,10 +30,13 @@ export async function bulkWriteFollows(agent: BskyAgent, dids: string[]) {
|
|||
value: r,
|
||||
}))
|
||||
|
||||
await agent.com.atproto.repo.applyWrites({
|
||||
repo: session.did,
|
||||
writes: followWrites,
|
||||
})
|
||||
const chunks = chunk(followWrites, 50)
|
||||
for (const chunk of chunks) {
|
||||
await agent.com.atproto.repo.applyWrites({
|
||||
repo: session.did,
|
||||
writes: chunk,
|
||||
})
|
||||
}
|
||||
await whenFollowsIndexed(agent, session.did, res => !!res.data.follows.length)
|
||||
|
||||
const followUris = new Map()
|
||||
|
|
|
@ -32,6 +32,7 @@ import {getStarterPackOgCard} from 'lib/strings/starter-pack'
|
|||
import {isWeb} from 'platform/detection'
|
||||
import {updateProfileShadow} from 'state/cache/profile-shadow'
|
||||
import {useModerationOpts} from 'state/preferences/moderation-opts'
|
||||
import {getAllListMembers} from 'state/queries/list-members'
|
||||
import {useResolvedStarterPackShortLink} from 'state/queries/resolve-short-link'
|
||||
import {useResolveDidQuery} from 'state/queries/resolve-uri'
|
||||
import {useShortenLink} from 'state/queries/shorten-link'
|
||||
|
@ -327,42 +328,52 @@ function Header({
|
|||
|
||||
setIsProcessing(true)
|
||||
|
||||
let listItems: AppBskyGraphDefs.ListItemView[] = []
|
||||
try {
|
||||
const list = await agent.app.bsky.graph.getList({
|
||||
list: starterPack.list.uri,
|
||||
})
|
||||
const dids = list.data.items
|
||||
.filter(
|
||||
li =>
|
||||
li.subject.did !== currentAccount?.did &&
|
||||
!isBlockedOrBlocking(li.subject) &&
|
||||
!isMuted(li.subject) &&
|
||||
!li.subject.viewer?.following,
|
||||
)
|
||||
.map(li => li.subject.did)
|
||||
|
||||
const followUris = await bulkWriteFollows(agent, dids)
|
||||
|
||||
batchedUpdates(() => {
|
||||
for (let did of dids) {
|
||||
updateProfileShadow(queryClient, did, {
|
||||
followingUri: followUris.get(did),
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
logEvent('starterPack:followAll', {
|
||||
logContext: 'StarterPackProfilesList',
|
||||
starterPack: starterPack.uri,
|
||||
count: dids.length,
|
||||
})
|
||||
captureAction(ProgressGuideAction.Follow, dids.length)
|
||||
Toast.show(_(msg`All accounts have been followed!`))
|
||||
listItems = await getAllListMembers(agent, starterPack.list.uri)
|
||||
} catch (e) {
|
||||
Toast.show(_(msg`An error occurred while trying to follow all`), 'xmark')
|
||||
} finally {
|
||||
setIsProcessing(false)
|
||||
Toast.show(_(msg`An error occurred while trying to follow all`), 'xmark')
|
||||
logger.error('Failed to get list members for starter pack', {
|
||||
safeMessage: e,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const dids = listItems
|
||||
.filter(
|
||||
li =>
|
||||
li.subject.did !== currentAccount?.did &&
|
||||
!isBlockedOrBlocking(li.subject) &&
|
||||
!isMuted(li.subject) &&
|
||||
!li.subject.viewer?.following,
|
||||
)
|
||||
.map(li => li.subject.did)
|
||||
|
||||
let followUris: Map<string, string>
|
||||
try {
|
||||
followUris = await bulkWriteFollows(agent, dids)
|
||||
} catch (e) {
|
||||
setIsProcessing(false)
|
||||
Toast.show(_(msg`An error occurred while trying to follow all`), 'xmark')
|
||||
logger.error('Failed to follow all accounts', {safeMessage: e})
|
||||
}
|
||||
|
||||
setIsProcessing(false)
|
||||
batchedUpdates(() => {
|
||||
for (let did of dids) {
|
||||
updateProfileShadow(queryClient, did, {
|
||||
followingUri: followUris.get(did),
|
||||
})
|
||||
}
|
||||
})
|
||||
Toast.show(_(msg`All accounts have been followed!`))
|
||||
captureAction(ProgressGuideAction.Follow, dids.length)
|
||||
logEvent('starterPack:followAll', {
|
||||
logContext: 'StarterPackProfilesList',
|
||||
starterPack: starterPack.uri,
|
||||
count: dids.length,
|
||||
})
|
||||
}
|
||||
|
||||
if (!AppBskyGraphStarterpack.isRecord(record)) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
import {GeneratorView} from '@atproto/api/dist/client/types/app/bsky/feed/defs'
|
||||
import {msg} from '@lingui/macro'
|
||||
|
||||
import {STARTER_PACK_MAX_SIZE} from 'lib/constants'
|
||||
import {useSession} from 'state/session'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
|
||||
|
@ -73,9 +74,10 @@ function reducer(state: State, action: Action): State {
|
|||
updatedState = {...state, description: action.description}
|
||||
break
|
||||
case 'AddProfile':
|
||||
if (state.profiles.length >= 51) {
|
||||
if (state.profiles.length > STARTER_PACK_MAX_SIZE) {
|
||||
Toast.show(
|
||||
msg`You may only add up to 50 profiles`.message ?? '',
|
||||
msg`You may only add up to ${STARTER_PACK_MAX_SIZE} profiles`
|
||||
.message ?? '',
|
||||
'info',
|
||||
)
|
||||
} else {
|
||||
|
@ -91,8 +93,8 @@ function reducer(state: State, action: Action): State {
|
|||
}
|
||||
break
|
||||
case 'AddFeed':
|
||||
if (state.feeds.length >= 50) {
|
||||
Toast.show(msg`You may only add up to 50 feeds`.message ?? '', 'info')
|
||||
if (state.feeds.length >= 3) {
|
||||
Toast.show(msg`You may only add up to 3 feeds`.message ?? '', 'info')
|
||||
} else {
|
||||
updatedState = {...state, feeds: [...state.feeds, action.feed]}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import {useFocusEffect, useNavigation} from '@react-navigation/native'
|
|||
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {HITSLOP_10} from 'lib/constants'
|
||||
import {HITSLOP_10, STARTER_PACK_MAX_SIZE} from 'lib/constants'
|
||||
import {createSanitizedDisplayName} from 'lib/moderation/create-sanitized-display-name'
|
||||
import {CommonNavigatorParams, NavigationProp} from 'lib/routes/types'
|
||||
import {logEvent} from 'lib/statsig/statsig'
|
||||
|
@ -33,7 +33,7 @@ import {
|
|||
} from 'lib/strings/starter-pack'
|
||||
import {isAndroid, isNative, isWeb} from 'platform/detection'
|
||||
import {useModerationOpts} from 'state/preferences/moderation-opts'
|
||||
import {useListMembersQuery} from 'state/queries/list-members'
|
||||
import {useAllListMembersQuery} from 'state/queries/list-members'
|
||||
import {useProfileQuery} from 'state/queries/profile'
|
||||
import {
|
||||
useCreateStarterPackMutation,
|
||||
|
@ -78,11 +78,10 @@ export function Wizard({
|
|||
const listUri = starterPack?.list?.uri
|
||||
|
||||
const {
|
||||
data: profilesData,
|
||||
data: listItems,
|
||||
isLoading: isLoadingProfiles,
|
||||
isError: isErrorProfiles,
|
||||
} = useListMembersQuery(listUri, 50)
|
||||
const listItems = profilesData?.pages.flatMap(p => p.items)
|
||||
} = useAllListMembersQuery(listUri)
|
||||
|
||||
const {
|
||||
data: profile,
|
||||
|
@ -428,7 +427,8 @@ function Footer({
|
|||
{items.length > minimumItems && (
|
||||
<View style={[a.absolute, {right: 14, top: 31}]}>
|
||||
<Text style={[a.font_bold]}>
|
||||
{items.length}/{state.currentStep === 'Profiles' ? 50 : 3}
|
||||
{items.length}/
|
||||
{state.currentStep === 'Profiles' ? STARTER_PACK_MAX_SIZE : 3}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue