From cdae685ee12a0d7807c911a3116eeafd0a8307f5 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 2 Sep 2022 12:17:33 -0500 Subject: [PATCH] Move SharePost modal to new system --- src/state/models/shell.ts | 12 ++++- src/view/com/feed/Feed.tsx | 10 ++-- src/view/com/modals/Modal.tsx | 4 ++ src/view/com/modals/SharePost.native.tsx | 63 +++++++----------------- src/view/com/post-thread/PostThread.tsx | 7 +-- 5 files changed, 39 insertions(+), 57 deletions(-) diff --git a/src/state/models/shell.ts b/src/state/models/shell.ts index 6755393c..a2e83b5e 100644 --- a/src/state/models/shell.ts +++ b/src/state/models/shell.ts @@ -8,15 +8,23 @@ export class LinkActionsModel { } } +export class SharePostModel { + name = 'share-post' + + constructor(public href: string) { + makeAutoObservable(this) + } +} + export class ShellModel { isModalActive = false - activeModal: LinkActionsModel | undefined + activeModal: LinkActionsModel | SharePostModel | undefined constructor() { makeAutoObservable(this) } - openModal(modal: LinkActionsModel) { + openModal(modal: LinkActionsModel | SharePostModel) { this.isModalActive = true this.activeModal = modal } diff --git a/src/view/com/feed/Feed.tsx b/src/view/com/feed/Feed.tsx index 7c7fea58..4a2ecb61 100644 --- a/src/view/com/feed/Feed.tsx +++ b/src/view/com/feed/Feed.tsx @@ -1,15 +1,16 @@ -import React, {useRef} from 'react' +import React from 'react' import {observer} from 'mobx-react-lite' import {Text, View, FlatList} from 'react-native' import {FeedViewModel, FeedViewItemModel} from '../../../state/models/feed-view' import {FeedItem} from './FeedItem' -import {ShareModal} from '../modals/SharePost' +import {SharePostModel} from '../../../state/models/shell' +import {useStores} from '../../../state' export const Feed = observer(function Feed({feed}: {feed: FeedViewModel}) { - const shareSheetRef = useRef<{open: (_uri: string) => void}>() + const store = useStores() const onPressShare = (uri: string) => { - shareSheetRef.current?.open(uri) + store.shell.openModal(new SharePostModel(uri)) } // TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf // VirtualizedList: You have a large list that is slow to update - make sure your @@ -41,7 +42,6 @@ export const Feed = observer(function Feed({feed}: {feed: FeedViewModel}) { /> )} {feed.isEmpty && This feed is empty!} - ) }) diff --git a/src/view/com/modals/Modal.tsx b/src/view/com/modals/Modal.tsx index 172dd0ad..dc5b719b 100644 --- a/src/view/com/modals/Modal.tsx +++ b/src/view/com/modals/Modal.tsx @@ -6,6 +6,7 @@ import {useStores} from '../../../state' import {createCustomBackdrop} from '../util/BottomSheetCustomBackdrop' import * as LinkActionsModal from './LinkActions' +import * as SharePostModal from './SharePost.native' export const Modal = observer(function Modal() { const store = useStores() @@ -28,6 +29,9 @@ export const Modal = observer(function Modal() { if (store.shell.activeModal?.name === 'link-actions') { snapPoints = LinkActionsModal.snapPoints element = + } else if (store.shell.activeModal?.name === 'share-post') { + snapPoints = SharePostModal.snapPoints + element = } else { return } diff --git a/src/view/com/modals/SharePost.native.tsx b/src/view/com/modals/SharePost.native.tsx index 6fc1d1ad..01692fb7 100644 --- a/src/view/com/modals/SharePost.native.tsx +++ b/src/view/com/modals/SharePost.native.tsx @@ -1,63 +1,36 @@ -import React, {forwardRef, useState, useImperativeHandle, useRef} from 'react' +import React from 'react' import {Button, StyleSheet, Text, TouchableOpacity, View} from 'react-native' -import BottomSheet from '@gorhom/bottom-sheet' import Toast from '../util/Toast' import Clipboard from '@react-native-clipboard/clipboard' import {s} from '../../lib/styles' -import {createCustomBackdrop} from '../util/BottomSheetCustomBackdrop' +import {useStores} from '../../../state' -export const ShareModal = forwardRef(function ShareModal({}: {}, ref) { - const [isOpen, setIsOpen] = useState(false) - const [uri, setUri] = useState('') - const bottomSheetRef = useRef(null) - - useImperativeHandle(ref, () => ({ - open(uri: string) { - console.log('sharing', uri) - setUri(uri) - setIsOpen(true) - bottomSheetRef.current?.expand() - }, - })) +export const snapPoints = ['30%'] +export function Component({href}: {href: string}) { + const store = useStores() const onPressCopy = () => { - Clipboard.setString(uri) - console.log('showing') + Clipboard.setString(href) Toast.show('Link copied', { position: Toast.positions.TOP, }) + store.shell.closeModal() } - const onShareBottomSheetChange = (snapPoint: number) => { - if (snapPoint === -1) { - console.log('unsharing') - setIsOpen(false) - } - } - const onClose = () => { - bottomSheetRef.current?.close() - } + const onClose = () => store.shell.closeModal() return ( - - - Share this post - {uri} -