fork
Configure Feed
Select the types of activity you want to include in your feed.
mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
fork
Configure Feed
Select the types of activity you want to include in your feed.
1import React from 'react'
2import {StyleSheet, View} from 'react-native'
3import {DismissableLayer} from '@radix-ui/react-dismissable-layer'
4import {useFocusGuards} from '@radix-ui/react-focus-guards'
5import {FocusScope} from '@radix-ui/react-focus-scope'
6import {RemoveScrollBar} from 'react-remove-scroll-bar'
7
8import {useModals} from '#/state/modals'
9import {ComposerOpts, useComposerState} from '#/state/shell/composer'
10import {
11 EmojiPicker,
12 EmojiPickerState,
13} from '#/view/com/composer/text-input/web/EmojiPicker.web'
14import {useBreakpoints, useTheme} from '#/alf'
15import {ComposePost, useComposerCancelRef} from '../com/composer/Composer'
16
17const BOTTOM_BAR_HEIGHT = 61
18
19export function Composer({}: {winHeight: number}) {
20 const state = useComposerState()
21 const isActive = !!state
22
23 // rendering
24 // =
25
26 if (!isActive) {
27 return <View />
28 }
29
30 return (
31 <>
32 <RemoveScrollBar />
33 <Inner state={state} />
34 </>
35 )
36}
37
38function Inner({state}: {state: ComposerOpts}) {
39 const ref = useComposerCancelRef()
40 const {isModalActive} = useModals()
41 const t = useTheme()
42 const {gtMobile} = useBreakpoints()
43 const [pickerState, setPickerState] = React.useState<EmojiPickerState>({
44 isOpen: false,
45 pos: {top: 0, left: 0, right: 0, bottom: 0},
46 })
47
48 const onOpenPicker = React.useCallback((pos: DOMRect | undefined) => {
49 if (!pos) return
50 setPickerState({
51 isOpen: true,
52 pos,
53 })
54 }, [])
55
56 const onClosePicker = React.useCallback(() => {
57 setPickerState(prev => ({
58 ...prev,
59 isOpen: false,
60 }))
61 }, [])
62
63 useFocusGuards()
64
65 return (
66 <FocusScope loop trapped asChild>
67 <DismissableLayer
68 role="dialog"
69 aria-modal
70 style={{
71 position: 'fixed',
72 top: 0,
73 left: 0,
74 width: '100%',
75 height: '100%',
76 backgroundColor: '#000c',
77 display: 'flex',
78 flexDirection: 'column',
79 alignItems: 'center',
80 }}
81 onFocusOutside={evt => evt.preventDefault()}
82 onInteractOutside={evt => evt.preventDefault()}
83 onDismiss={() => {
84 // TEMP: remove when all modals are ALF'd -sfn
85 if (!isModalActive) {
86 ref.current?.onPressCancel()
87 }
88 }}>
89 <View
90 style={[
91 styles.container,
92 !gtMobile && styles.containerMobile,
93 t.atoms.bg,
94 t.atoms.border_contrast_medium,
95 ]}>
96 <ComposePost
97 cancelRef={ref}
98 replyTo={state.replyTo}
99 quote={state.quote}
100 onPost={state.onPost}
101 mention={state.mention}
102 openEmojiPicker={onOpenPicker}
103 text={state.text}
104 imageUris={state.imageUris}
105 />
106 </View>
107 <EmojiPicker state={pickerState} close={onClosePicker} />
108 </DismissableLayer>
109 </FocusScope>
110 )
111}
112
113const styles = StyleSheet.create({
114 container: {
115 marginTop: 50,
116 maxWidth: 600,
117 width: '100%',
118 paddingVertical: 0,
119 borderRadius: 8,
120 marginBottom: 0,
121 borderWidth: 1,
122 // @ts-ignore web only
123 maxHeight: 'calc(100% - (40px * 2))',
124 overflow: 'hidden',
125 },
126 containerMobile: {
127 borderRadius: 0,
128 marginBottom: BOTTOM_BAR_HEIGHT,
129 // @ts-ignore web only
130 maxHeight: `calc(100% - ${BOTTOM_BAR_HEIGHT}px)`,
131 },
132})