Skip to content

Commit

Permalink
reset-memories
Browse files Browse the repository at this point in the history
  • Loading branch information
Nibirian9 committed Mar 8, 2024
1 parent ed616b5 commit f40117d
Showing 1 changed file with 63 additions and 33 deletions.
96 changes: 63 additions & 33 deletions packages/app/src/pages/app/FriendProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import UserAvatar from "../../../components/UserAvatar"
import { getAvatarImage } from "../../../helpers/getAvatarImage"
import useGlobalStore from "../../../store/useGlobalStore"
import useRoomStyles from "../Room/useRoomStyles"
import { showNotification } from "@mantine/notifications"

export default function Profile () {
const navigate = useNavigate()
// const isMobile = useMediaQuery("(max-width: 900px)")
const supabase = useSupabaseClient<Database>()
const { classes: roomClasses } = useRoomStyles()
const { user } = useGlobalStore();

const {
currentRoom: {
Expand Down Expand Up @@ -48,6 +50,30 @@ export default function Profile () {
navigate("/login")
}

const resetMemories = async () => {
const userId = user.uid;
const agentId = friend.id;
const userIdsArray = `{${userId},${agentId}}`;

const { msgsError } = await supabase.from("messages").delete().eq("user_ids", userIdsArray);
if (msgsError) console.error(msgsError);

const { descriptionsError } = await supabase.from("descriptions").delete().eq("user_ids", userIdsArray);
if (descriptionsError) console.error(descriptionsError);

const { factsError } = await supabase.from("facts").delete().eq("user_ids", userIdsArray);
if (factsError) console.error(factsError);

const { goalsError } = await supabase.from("goals").delete().eq("user_ids", userIdsArray);
if (goalsError) console.error(goalsError);

showNotification({
title: "Memories reset",
message: "Memories have been reset successfully",
color: "green",
})
};

const theme = useMantineTheme()

return (
Expand Down Expand Up @@ -87,19 +113,6 @@ export default function Profile () {
</Text>
</Group>
}
{!friend?.is_agent &&
<>

<Group>
<Text>Location: {friend.location || "Not specified"}</Text>
</Group>
<Group>
<Text>Age: {friend.age || "Not specified"}</Text>
</Group>
<Group>
<Text>Pronouns: {friend.pronouns || "Not specified"}</Text>
</Group>
</>}
<>
<Group>
<Text>Location: {friend.location || "Not specified"}</Text>
Expand All @@ -114,27 +127,44 @@ export default function Profile () {
</Group>
</>
</Container>
{!friend?.is_agent &&
<Group
mb={"lg"}
mt={"4xl"}
style={{
gap: theme.spacing.xs
}}
{!friend?.is_agent ? (
<Group
mb={"lg"}
mt={"4xl"}
style={{
gap: theme.spacing.xs,
}}
>
<Button
fullWidth
variant="transparent"
size="md"
onClick={unfriend}
>
<Button
fullWidth
variant="transparent"
size="md"
onClick={unfriend}
>
<Text color={theme.white}>Unfriend</Text>
</Button>
<Button fullWidth variant="transparent" size="md" onClick={logout}>
<Text color={theme.colors.red[8]}>Block</Text>
</Button>
</Group>
}
<Text color={theme.white}>Unfriend</Text>
</Button>
<Button fullWidth variant="transparent" size="md" onClick={logout}>
<Text color={theme.colors.red[8]}>Block</Text>
</Button>
</Group>
) : (
<Group
mb={"lg"}
mt={"4xl"}
style={{
gap: theme.spacing.xs,
}}
>
<Button
fullWidth
variant="transparent"
size="md"
onClick={resetMemories}
>
<Text color={theme.colors.red[8]}>Reset Memories</Text>
</Button>
</Group>
)}
</div>
</div>
)
Expand Down

0 comments on commit f40117d

Please sign in to comment.