Skip to content

Commit

Permalink
Merge pull request #515 from ephemeraHQ/ar/group-invite-updates
Browse files Browse the repository at this point in the history
feat: Group Invites Delete
  • Loading branch information
alexrisch authored Aug 15, 2024
2 parents 40a569c + 31563b4 commit 4bfc5a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 16 additions & 3 deletions containers/GroupScreenAddition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,8 +60,8 @@ export const GroupScreenAddition: FC<GroupScreenAdditionProps> = ({
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 });
Expand All @@ -81,6 +85,7 @@ export const GroupScreenAddition: FC<GroupScreenAdditionProps> = ({
saveGroupInviteLink(groupInvite.id, getGroupIdFromTopic(topic));
setGroupInviteLink(topic, groupInvite.inviteLink);
Clipboard.setString(groupInvite.inviteLink);
setShowSnack(true);
})
.catch((err) => {
console.error("Error creating group invite", err);
Expand All @@ -95,6 +100,12 @@ export const GroupScreenAddition: FC<GroupScreenAdditionProps> = ({
topic,
]);

const onDeleteInviteLink = useCallback(() => {
Haptics.impactAsync();
deleteGroupInviteLink(topic);
clearGroupInviteLink(topic);
}, [deleteGroupInviteLink, topic]);

const dismissSnackBar = useCallback(() => {
setShowSnack(false);
}, [setShowSnack]);
Expand Down Expand Up @@ -125,13 +136,15 @@ export const GroupScreenAddition: FC<GroupScreenAdditionProps> = ({
<TouchableOpacity
onPress={onCopyInviteLinkPress}
style={[styles.itemContainer, styles.inviteContainer]}
onLongPress={onDeleteInviteLink}
>
<Picto size={pictoSize} style={styles.icon} picto="link" />
<Text style={styles.text}>Copy Invite Link</Text>
</TouchableOpacity>
) : (
<TouchableOpacity
onPress={onCreateInviteLinkPress}
onLongPress={() => {}}
style={[styles.itemContainer, styles.inviteContainer]}
>
<Picto size={pictoSize} style={styles.icon} picto="link" />
Expand Down
8 changes: 8 additions & 0 deletions data/store/chatStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4bfc5a1

Please sign in to comment.