From f33a355a1ac1fb3e3d91e7e55a9fe9df53313e66 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 25 Apr 2023 20:47:07 -0500 Subject: [APP-562] Persist 'copied' state of invite codes (#535) * Persist 'copied' state of invite codes (close APP-562) * Dont show copied message if invite used --- src/view/com/modals/InviteCodes.tsx | 77 ++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'src/view/com/modals/InviteCodes.tsx') diff --git a/src/view/com/modals/InviteCodes.tsx b/src/view/com/modals/InviteCodes.tsx index 5e31e16a8..8d54a50b1 100644 --- a/src/view/com/modals/InviteCodes.tsx +++ b/src/view/com/modals/InviteCodes.tsx @@ -1,5 +1,6 @@ import React from 'react' import {StyleSheet, TouchableOpacity, View} from 'react-native' +import {observer} from 'mobx-react-lite' import { FontAwesomeIcon, FontAwesomeIconStyle, @@ -82,46 +83,42 @@ export function Component({}: {}) { ) } -function InviteCode({ - testID, - code, - used, -}: { - testID: string - code: string - used?: boolean -}) { - const pal = usePalette('default') - const [wasCopied, setWasCopied] = React.useState(false) +const InviteCode = observer( + ({testID, code, used}: {testID: string; code: string; used?: boolean}) => { + const pal = usePalette('default') + const store = useStores() - const onPress = React.useCallback(() => { - Clipboard.setString(code) - Toast.show('Copied to clipboard') - setWasCopied(true) - }, [code]) + const onPress = React.useCallback(() => { + Clipboard.setString(code) + Toast.show('Copied to clipboard') + store.invitedUsers.setInviteCopied(code) + }, [store, code]) - return ( - - - {code} - - {wasCopied ? ( - Copied - ) : !used ? ( - - ) : undefined} - - ) -} + return ( + + + {code} + + + {!used && store.invitedUsers.isInviteCopied(code) && ( + Copied + )} + {!used && ( + + )} + + ) + }, +) const styles = StyleSheet.create({ container: { @@ -163,11 +160,13 @@ const styles = StyleSheet.create({ inviteCode: { flexDirection: 'row', alignItems: 'center', - justifyContent: 'space-between', borderBottomWidth: 1, paddingHorizontal: 20, paddingVertical: 14, }, + codeCopied: { + marginRight: 8, + }, strikeThrough: { textDecorationLine: 'line-through', textDecorationStyle: 'solid', -- cgit 1.4.1