mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

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

at localize-dates 162 lines 6.3 kB view raw
1import React, {Fragment, useEffect, useRef} from 'react' 2import {StyleSheet} from 'react-native' 3import {SafeAreaView} from 'react-native-safe-area-context' 4import BottomSheet from '@discord/bottom-sheet/src' 5 6import {useModalControls, useModals} from '#/state/modals' 7import {usePalette} from 'lib/hooks/usePalette' 8import {FullWindowOverlay} from '#/components/FullWindowOverlay' 9import {createCustomBackdrop} from '../util/BottomSheetCustomBackdrop' 10import * as AddAppPassword from './AddAppPasswords' 11import * as AltImageModal from './AltImage' 12import * as EditImageModal from './AltImage' 13import * as ChangeEmailModal from './ChangeEmail' 14import * as ChangeHandleModal from './ChangeHandle' 15import * as ChangePasswordModal from './ChangePassword' 16import * as CreateOrEditListModal from './CreateOrEditList' 17import * as DeleteAccountModal from './DeleteAccount' 18import * as EditProfileModal from './EditProfile' 19import * as InAppBrowserConsentModal from './InAppBrowserConsent' 20import * as InviteCodesModal from './InviteCodes' 21import * as ContentLanguagesSettingsModal from './lang-settings/ContentLanguagesSettings' 22import * as PostLanguagesSettingsModal from './lang-settings/PostLanguagesSettings' 23import * as LinkWarningModal from './LinkWarning' 24import * as ListAddUserModal from './ListAddRemoveUsers' 25import * as SelfLabelModal from './SelfLabel' 26import * as UserAddRemoveListsModal from './UserAddRemoveLists' 27import * as VerifyEmailModal from './VerifyEmail' 28 29const DEFAULT_SNAPPOINTS = ['90%'] 30const HANDLE_HEIGHT = 24 31 32export function ModalsContainer() { 33 const {isModalActive, activeModals} = useModals() 34 const {closeModal} = useModalControls() 35 const bottomSheetRef = useRef<BottomSheet>(null) 36 const pal = usePalette('default') 37 const activeModal = activeModals[activeModals.length - 1] 38 39 const onBottomSheetChange = async (snapPoint: number) => { 40 if (snapPoint === -1) { 41 closeModal() 42 } 43 } 44 45 const onClose = () => { 46 bottomSheetRef.current?.close() 47 closeModal() 48 } 49 50 useEffect(() => { 51 if (isModalActive) { 52 bottomSheetRef.current?.snapToIndex(0) 53 } else { 54 bottomSheetRef.current?.close() 55 } 56 }, [isModalActive, bottomSheetRef, activeModal?.name]) 57 58 let snapPoints: (string | number)[] = DEFAULT_SNAPPOINTS 59 let element 60 if (activeModal?.name === 'edit-profile') { 61 snapPoints = EditProfileModal.snapPoints 62 element = <EditProfileModal.Component {...activeModal} /> 63 } else if (activeModal?.name === 'create-or-edit-list') { 64 snapPoints = CreateOrEditListModal.snapPoints 65 element = <CreateOrEditListModal.Component {...activeModal} /> 66 } else if (activeModal?.name === 'user-add-remove-lists') { 67 snapPoints = UserAddRemoveListsModal.snapPoints 68 element = <UserAddRemoveListsModal.Component {...activeModal} /> 69 } else if (activeModal?.name === 'list-add-remove-users') { 70 snapPoints = ListAddUserModal.snapPoints 71 element = <ListAddUserModal.Component {...activeModal} /> 72 } else if (activeModal?.name === 'delete-account') { 73 snapPoints = DeleteAccountModal.snapPoints 74 element = <DeleteAccountModal.Component /> 75 } else if (activeModal?.name === 'self-label') { 76 snapPoints = SelfLabelModal.snapPoints 77 element = <SelfLabelModal.Component {...activeModal} /> 78 } else if (activeModal?.name === 'alt-text-image') { 79 snapPoints = AltImageModal.snapPoints 80 element = <AltImageModal.Component {...activeModal} /> 81 } else if (activeModal?.name === 'edit-image') { 82 snapPoints = AltImageModal.snapPoints 83 element = <EditImageModal.Component {...activeModal} /> 84 } else if (activeModal?.name === 'change-handle') { 85 snapPoints = ChangeHandleModal.snapPoints 86 element = <ChangeHandleModal.Component {...activeModal} /> 87 } else if (activeModal?.name === 'invite-codes') { 88 snapPoints = InviteCodesModal.snapPoints 89 element = <InviteCodesModal.Component /> 90 } else if (activeModal?.name === 'add-app-password') { 91 snapPoints = AddAppPassword.snapPoints 92 element = <AddAppPassword.Component /> 93 } else if (activeModal?.name === 'content-languages-settings') { 94 snapPoints = ContentLanguagesSettingsModal.snapPoints 95 element = <ContentLanguagesSettingsModal.Component /> 96 } else if (activeModal?.name === 'post-languages-settings') { 97 snapPoints = PostLanguagesSettingsModal.snapPoints 98 element = <PostLanguagesSettingsModal.Component /> 99 } else if (activeModal?.name === 'verify-email') { 100 snapPoints = VerifyEmailModal.snapPoints 101 element = <VerifyEmailModal.Component {...activeModal} /> 102 } else if (activeModal?.name === 'change-email') { 103 snapPoints = ChangeEmailModal.snapPoints 104 element = <ChangeEmailModal.Component /> 105 } else if (activeModal?.name === 'change-password') { 106 snapPoints = ChangePasswordModal.snapPoints 107 element = <ChangePasswordModal.Component /> 108 } else if (activeModal?.name === 'link-warning') { 109 snapPoints = LinkWarningModal.snapPoints 110 element = <LinkWarningModal.Component {...activeModal} /> 111 } else if (activeModal?.name === 'in-app-browser-consent') { 112 snapPoints = InAppBrowserConsentModal.snapPoints 113 element = <InAppBrowserConsentModal.Component {...activeModal} /> 114 } else { 115 return null 116 } 117 118 if (snapPoints[0] === 'fullscreen') { 119 return ( 120 <SafeAreaView style={[styles.fullscreenContainer, pal.view]}> 121 {element} 122 </SafeAreaView> 123 ) 124 } 125 126 const Container = activeModal ? FullWindowOverlay : Fragment 127 128 return ( 129 <Container> 130 <BottomSheet 131 ref={bottomSheetRef} 132 snapPoints={snapPoints} 133 handleHeight={HANDLE_HEIGHT} 134 index={isModalActive ? 0 : -1} 135 enablePanDownToClose 136 android_keyboardInputMode="adjustResize" 137 keyboardBlurBehavior="restore" 138 backdropComponent={ 139 isModalActive ? createCustomBackdrop(onClose) : undefined 140 } 141 handleIndicatorStyle={{backgroundColor: pal.text.color}} 142 handleStyle={[styles.handle, pal.view]} 143 onChange={onBottomSheetChange}> 144 {element} 145 </BottomSheet> 146 </Container> 147 ) 148} 149 150const styles = StyleSheet.create({ 151 handle: { 152 borderTopLeftRadius: 10, 153 borderTopRightRadius: 10, 154 }, 155 fullscreenContainer: { 156 position: 'absolute', 157 top: 0, 158 left: 0, 159 bottom: 0, 160 right: 0, 161 }, 162})