From 179648be09ed6962ab3383e0089e7ee859d27347 Mon Sep 17 00:00:00 2001 From: duogenesis <136373989+duogenesis@users.noreply.github.com> Date: Sun, 29 Oct 2023 15:24:26 +1100 Subject: [PATCH] Add menu to conversations --- components/conversation-screen.tsx | 166 +++++++++++++++++++++++++++++ components/top-nav-bar-button.tsx | 2 +- 2 files changed, 167 insertions(+), 1 deletion(-) diff --git a/components/conversation-screen.tsx b/components/conversation-screen.tsx index 73b7df4b..3c2db31b 100644 --- a/components/conversation-screen.tsx +++ b/components/conversation-screen.tsx @@ -7,8 +7,10 @@ import { Pressable, ScrollView, Text, + TextStyle, TextInput, View, + ViewStyle, } from 'react-native'; import { useCallback, @@ -38,8 +40,158 @@ import { import { getRandomString } from '../random/string'; import { api } from '../api/api'; import { TopNavBarButton } from './top-nav-bar-button'; +import { RotateCcw, Slash, X } from "react-native-feather"; +import { setHidden, setBlocked } from '../hide-and-block/hide-and-block'; + +const Menu = ({navigation, personId}) => { + const [isBlocked, setIsBlocked] = useState(); + const [isHidden, setIsHidden] = useState(); + const [isUpdatingIsBlocked, setIsUpdatingIsBlocked] = useState(false); + const [isUpdatingIsHidden, setIsUpdatingIsHidden] = useState(false); + + const isLoading = isBlocked === undefined || isHidden === undefined; + + const onPressMatch = useCallback(async () => { + if (isHidden === undefined) { + return; + } + + setIsUpdatingIsHidden(true); + const nextHiddenState = !isHidden; + if (await setHidden(personId, nextHiddenState)) { + setIsHidden(nextHiddenState); + setIsUpdatingIsHidden(false); + if (nextHiddenState) { + navigation.popToTop(); + } + } + }, [navigation, personId, isHidden]); + + const onPressBlock = useCallback(async () => { + if (isBlocked === undefined) { + return; + } + + setIsUpdatingIsBlocked(true); + const nextBlockedState = !isBlocked; + if (await setBlocked(personId, nextBlockedState)) { + setIsBlocked(nextBlockedState); + setIsUpdatingIsBlocked(false); + if (nextBlockedState) { + navigation.popToTop(); + } + } + }, [navigation, personId, isBlocked]); + + useEffect(() => { + (async () => { + const response = await api('get', `/prospect-profile/${personId}`); + if (response.ok) { + setIsBlocked(response.json.is_blocked); + setIsHidden(response.json.is_hidden); + } + })(); + }, [personId]); + + const pressableStyle: ViewStyle = { + flexDirection: 'row', + gap: 10, + }; + + const iconStyle = { + backgroundColor: isLoading ? '#ddd' : undefined, + borderRadius: 3, + }; + + const labelStyle: TextStyle = { + fontSize: 16, + fontWeight: '600', + color: isLoading ? '#ddd' : '#777', + backgroundColor: isLoading ? '#ddd' : undefined, + borderRadius: 3, + }; + + const iconStroke = isLoading ? "transparent" : "black"; + + return ( + + + {isUpdatingIsHidden && + + } + {!isUpdatingIsHidden && isHidden && + + } + {!isUpdatingIsHidden && !isHidden && + + } + + {isHidden ? 'Undo unmatch' : 'Unmatch'} + + + + {isUpdatingIsBlocked && + + } + {!isUpdatingIsBlocked && isBlocked && + + } + {!isUpdatingIsBlocked && !isBlocked && + + } + + {isBlocked ? 'Unblock' : 'Block and report'} + + + + ); +}; const ConversationScreen = ({navigation, route}) => { + const [showMenu, setShowMenu] = useState(false); const [messageFetchTimeout, setMessageFetchTimeout] = useState(false); const [messages, setMessages] = useState(null); const [lastMessageStatus, setLastMessageStatus] = useState< @@ -174,6 +326,10 @@ const ConversationScreen = ({navigation, route}) => { return onReceiveMessage(_onReceiveMessage, personId); }, []); + const toggleMenu = useCallback(() => { + setShowMenu(x => !x); + }, []); + return ( <> @@ -209,6 +365,16 @@ const ConversationScreen = ({navigation, route}) => { {name ?? '...'} + {isAvailableUser && + + } + {showMenu && + + } {messages === null && !messageFetchTimeout && diff --git a/components/top-nav-bar-button.tsx b/components/top-nav-bar-button.tsx index 3c20073f..84a5e11a 100644 --- a/components/top-nav-bar-button.tsx +++ b/components/top-nav-bar-button.tsx @@ -41,7 +41,7 @@ const TopNavBarButton = ({onPress, iconName, style}) => {