mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useRef} from 'react'
2import type {ListRenderItemInfo} from 'react-native'
3import {View} from 'react-native'
4import {AppBskyActorDefs, ModerationOpts} from '@atproto/api'
5import {GeneratorView} from '@atproto/api/dist/client/types/app/bsky/feed/defs'
6import {msg, Trans} from '@lingui/macro'
7import {useLingui} from '@lingui/react'
8
9import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
10import {isWeb} from '#/platform/detection'
11import {useSession} from '#/state/session'
12import {ListMethods} from '#/view/com/util/List'
13import {WizardAction, WizardState} from '#/screens/StarterPack/Wizard/State'
14import {atoms as a, native, useTheme, web} from '#/alf'
15import {Button, ButtonText} from '#/components/Button'
16import * as Dialog from '#/components/Dialog'
17import {
18 WizardFeedCard,
19 WizardProfileCard,
20} from '#/components/StarterPack/Wizard/WizardListCard'
21import {Text} from '#/components/Typography'
22
23function keyExtractor(
24 item: AppBskyActorDefs.ProfileViewBasic | GeneratorView,
25 index: number,
26) {
27 return `${item.did}-${index}`
28}
29
30export function WizardEditListDialog({
31 control,
32 state,
33 dispatch,
34 moderationOpts,
35 profile,
36}: {
37 control: Dialog.DialogControlProps
38 state: WizardState
39 dispatch: (action: WizardAction) => void
40 moderationOpts: ModerationOpts
41 profile: AppBskyActorDefs.ProfileViewBasic
42}) {
43 const {_} = useLingui()
44 const t = useTheme()
45 const {currentAccount} = useSession()
46 const initialNumToRender = useInitialNumToRender()
47
48 const listRef = useRef<ListMethods>(null)
49
50 const getData = () => {
51 if (state.currentStep === 'Feeds') return state.feeds
52
53 return [
54 profile,
55 ...state.profiles.filter(p => p.did !== currentAccount?.did),
56 ]
57 }
58
59 const renderItem = ({item}: ListRenderItemInfo<any>) =>
60 state.currentStep === 'Profiles' ? (
61 <WizardProfileCard
62 profile={item}
63 btnType="remove"
64 state={state}
65 dispatch={dispatch}
66 moderationOpts={moderationOpts}
67 />
68 ) : (
69 <WizardFeedCard
70 generator={item}
71 btnType="remove"
72 state={state}
73 dispatch={dispatch}
74 moderationOpts={moderationOpts}
75 />
76 )
77
78 return (
79 <Dialog.Outer control={control} testID="newChatDialog">
80 <Dialog.Handle />
81 <Dialog.InnerFlatList
82 ref={listRef}
83 data={getData()}
84 renderItem={renderItem}
85 keyExtractor={keyExtractor}
86 ListHeaderComponent={
87 <View
88 style={[
89 native(a.pt_4xl),
90 a.flex_row,
91 a.justify_between,
92 a.border_b,
93 a.px_sm,
94 a.mb_sm,
95 t.atoms.bg,
96 t.atoms.border_contrast_medium,
97 isWeb
98 ? [
99 a.align_center,
100 {
101 height: 48,
102 },
103 ]
104 : [a.pb_sm, a.align_end],
105 ]}>
106 <View style={{width: 60}} />
107 <Text style={[a.font_bold, a.text_xl]}>
108 {state.currentStep === 'Profiles' ? (
109 <Trans>Edit People</Trans>
110 ) : (
111 <Trans>Edit Feeds</Trans>
112 )}
113 </Text>
114 <View style={{width: 60}}>
115 {isWeb && (
116 <Button
117 label={_(msg`Close`)}
118 variant="ghost"
119 color="primary"
120 size="small"
121 onPress={() => control.close()}>
122 <ButtonText>
123 <Trans>Close</Trans>
124 </ButtonText>
125 </Button>
126 )}
127 </View>
128 </View>
129 }
130 stickyHeaderIndices={[0]}
131 style={[
132 web([a.py_0, {height: '100vh', maxHeight: 600}, a.px_0]),
133 native({
134 height: '100%',
135 paddingHorizontal: 0,
136 marginTop: 0,
137 paddingTop: 0,
138 }),
139 ]}
140 webInnerStyle={[a.py_0, {maxWidth: 500, minWidth: 200}]}
141 keyboardDismissMode="on-drag"
142 removeClippedSubviews={true}
143 initialNumToRender={initialNumToRender}
144 />
145 </Dialog.Outer>
146 )
147}