Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Hook up data

+74 -4
+74 -4
src/components/dialogs/nudges/TenMillion/index.tsx
··· 6 6 import {msg, Trans} from '@lingui/macro' 7 7 import {useLingui} from '@lingui/react' 8 8 9 + import {networkRetry} from '#/lib/async/retry' 9 10 import {getCanvas} from '#/lib/canvas' 10 11 import {shareUrl} from '#/lib/sharing' 11 12 import {sanitizeDisplayName} from '#/lib/strings/display-names' ··· 13 14 import {isNative} from '#/platform/detection' 14 15 import {useModerationOpts} from '#/state/preferences/moderation-opts' 15 16 import {useProfileQuery} from '#/state/queries/profile' 16 - import {useSession} from '#/state/session' 17 + import {useAgent, useSession} from '#/state/session' 17 18 import {useComposerControls} from 'state/shell' 18 19 import {formatCount} from '#/view/com/util/numeric/format' 19 20 // import {UserAvatar} from '#/view/com/util/UserAvatar' ··· 109 110 : undefined 110 111 }, [profile, moderationOpts]) 111 112 const [uri, setUri] = React.useState<string | null>(null) 113 + const [userNumber, setUserNumber] = React.useState<number>(0) 114 + const [error, setError] = React.useState('') 112 115 113 - const isLoadingData = isProfileLoading || !moderation || !profile 116 + const isLoadingData = 117 + isProfileLoading || !moderation || !profile || !userNumber 114 118 const isLoadingImage = !uri 115 119 116 - const userNumber = 56_738 // TODO 117 120 const percent = userNumber / 10_000_000 118 121 const Badge = getPercentBadge(percent) 122 + 123 + const agent = useAgent() 124 + React.useEffect(() => { 125 + async function fetchUserNumber() { 126 + if (agent.session?.accessJwt) { 127 + const res = await fetch( 128 + `https://bsky.social/xrpc/com.atproto.temp.getSignupNumber`, 129 + { 130 + headers: { 131 + Authorization: `Bearer ${agent.session.accessJwt}`, 132 + }, 133 + }, 134 + ) 135 + 136 + if (!res.ok) { 137 + throw new Error('Network request failed') 138 + } 139 + 140 + const data = await res.json() 141 + 142 + if (data.number) { 143 + setUserNumber(data.number) 144 + } 145 + } 146 + } 147 + 148 + networkRetry(3, fetchUserNumber).catch(() => { 149 + setError( 150 + _( 151 + msg`Oh no! We couldn't fetch your user number. Rest assured, we're glad you're here ❤️`, 152 + ), 153 + ) 154 + }) 155 + }, [ 156 + _, 157 + agent.session?.accessJwt, 158 + setUserNumber, 159 + controls.tenMillion, 160 + setError, 161 + ]) 119 162 120 163 const sharePost = () => { 121 164 if (uri) { ··· 421 464 <View 422 465 style={[a.absolute, a.inset_0, a.align_center, a.justify_center]}> 423 466 <GradientFill gradient={tokens.gradients.bonfire} /> 424 - {isLoadingData || isLoadingImage ? ( 467 + {error ? ( 468 + <View> 469 + <Text 470 + style={[ 471 + a.text_md, 472 + a.leading_snug, 473 + a.text_center, 474 + a.pb_md, 475 + { 476 + maxWidth: 300, 477 + }, 478 + ]}> 479 + (╯°□°)╯︵ ┻━┻ 480 + </Text> 481 + <Text 482 + style={[ 483 + a.text_xl, 484 + a.font_bold, 485 + a.leading_snug, 486 + a.text_center, 487 + { 488 + maxWidth: 300, 489 + }, 490 + ]}> 491 + {error} 492 + </Text> 493 + </View> 494 + ) : isLoadingData || isLoadingImage ? ( 425 495 <Loader size="xl" fill="white" /> 426 496 ) : ( 427 497 <Image