From 31563b41153b8a895414f091f576407cce30db1c Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Thu, 15 Aug 2024 16:55:59 -0600 Subject: [PATCH] feat: Group Invites Delete Added ability to delete group invites Fixed snack not showing on first group invite creation --- containers/GroupScreenAddition.tsx | 19 ++++++++++++++++--- data/store/chatStore.ts | 8 ++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/containers/GroupScreenAddition.tsx b/containers/GroupScreenAddition.tsx index f8050774d..db1ff9a55 100644 --- a/containers/GroupScreenAddition.tsx +++ b/containers/GroupScreenAddition.tsx @@ -15,10 +15,14 @@ import { } from "@styles/colors"; import { PictoSizes } from "@styles/sizes"; import { createGroupInvite } from "@utils/api"; -import { saveGroupInviteLink } from "@utils/groupInvites"; +import { + saveGroupInviteLink, + deleteGroupInviteLink as clearGroupInviteLink, +} from "@utils/groupInvites"; import { getGroupIdFromTopic } from "@utils/groupUtils/groupId"; import { memberCanUpdateGroup } from "@utils/groupUtils/memberCanUpdateGroup"; import { navigate } from "@utils/navigation"; +import * as Haptics from "expo-haptics"; import { FC, useCallback, useState } from "react"; import { Alert, @@ -56,8 +60,8 @@ export const GroupScreenAddition: FC = ({ const { groupDescription } = useGroupDescription(topic); const groupInviteLink = useExistingGroupInviteLink(topic); - const { setGroupInviteLink } = useChatStore( - useSelect(["setGroupInviteLink"]) + const { setGroupInviteLink, deleteGroupInviteLink } = useChatStore( + useSelect(["setGroupInviteLink", "deleteGroupInviteLink"]) ); const onAddMemberPress = useCallback(() => { navigate("NewConversation", { addingToGroupTopic: topic }); @@ -81,6 +85,7 @@ export const GroupScreenAddition: FC = ({ saveGroupInviteLink(groupInvite.id, getGroupIdFromTopic(topic)); setGroupInviteLink(topic, groupInvite.inviteLink); Clipboard.setString(groupInvite.inviteLink); + setShowSnack(true); }) .catch((err) => { console.error("Error creating group invite", err); @@ -95,6 +100,12 @@ export const GroupScreenAddition: FC = ({ topic, ]); + const onDeleteInviteLink = useCallback(() => { + Haptics.impactAsync(); + deleteGroupInviteLink(topic); + clearGroupInviteLink(topic); + }, [deleteGroupInviteLink, topic]); + const dismissSnackBar = useCallback(() => { setShowSnack(false); }, [setShowSnack]); @@ -125,6 +136,7 @@ export const GroupScreenAddition: FC = ({ Copy Invite Link @@ -132,6 +144,7 @@ export const GroupScreenAddition: FC = ({ ) : ( {}} style={[styles.itemContainer, styles.inviteContainer]} > diff --git a/data/store/chatStore.ts b/data/store/chatStore.ts index 57a4a3027..8580e49d7 100644 --- a/data/store/chatStore.ts +++ b/data/store/chatStore.ts @@ -216,6 +216,7 @@ export type ChatStoreType = { [topic: string]: string; }; setGroupInviteLink: (topic: string, inviteLink: string) => void; + deleteGroupInviteLink: (topic: string) => void; }; const now = () => new Date().getTime(); @@ -801,6 +802,13 @@ export const initChatStore = (account: string) => { return { groupInviteLinks: newGroupInvites }; }); }, + deleteGroupInviteLink(topic) { + set((state) => { + const newGroupInvites = { ...state.groupInviteLinks }; + delete newGroupInvites[topic]; + return { groupInviteLinks: newGroupInvites }; + }); + }, }) as ChatStoreType, { name: `store-${account}-chat`, // Account-based storage so each account can have its own chat data