forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useState} from 'react'
2import {msg, Trans} from '@lingui/macro'
3import {useLingui} from '@lingui/react'
4
5import {wait} from '#/lib/async/wait'
6import {atoms as a, type TextStyleProp, useTheme} from '#/alf'
7import {CheckThick_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
8import {createStaticClick, InlineLinkText} from '#/components/Link'
9import {Loader} from '#/components/Loader'
10import {Span, Text} from '#/components/Typography'
11
12export function ResendEmailText({
13 onPress,
14 style,
15}: TextStyleProp & {
16 onPress: () => Promise<any>
17}) {
18 const t = useTheme()
19 const {_} = useLingui()
20 const [status, setStatus] = useState<'sending' | 'success' | null>(null)
21
22 const handleOnPress = async () => {
23 setStatus('sending')
24 try {
25 await wait(1000, onPress())
26 setStatus('success')
27 } finally {
28 setTimeout(() => {
29 setStatus(null)
30 }, 1000)
31 }
32 }
33
34 return (
35 <Text
36 style={[a.italic, a.leading_snug, t.atoms.text_contrast_medium, style]}>
37 <Trans>
38 Don't see an email?{' '}
39 <InlineLinkText
40 label={_(msg`Resend`)}
41 {...createStaticClick(() => {
42 handleOnPress()
43 })}>
44 Click here to resend.
45 </InlineLinkText>
46 </Trans>{' '}
47 <Span style={{top: 1}}>
48 {status === 'sending' ? (
49 <Loader size="xs" />
50 ) : status === 'success' ? (
51 <Check size="xs" fill={t.palette.positive_500} />
52 ) : null}
53 </Span>
54 </Text>
55 )
56}