import useGetCardFromMyLibrary from '@/features/cards/lib/queries/useGetCardFromMyLibrary'; import { Anchor, AspectRatio, Avatar, Card, Group, Stack, Tooltip, Text, Image, Textarea, Button, } from '@mantine/core'; import { UrlCard, User } from '@semble/types'; import Link from 'next/link'; import { Fragment, useState } from 'react'; import useUpdateNote from '../../lib/mutations/useUpdateNote'; import { notifications } from '@mantine/notifications'; import useRemoveCardFromLibrary from '@/features/cards/lib/mutations/useRemoveCardFromLibrary'; interface Props { onClose: () => void; note: UrlCard['note']; cardContent: UrlCard['cardContent']; cardAuthor?: User; domain: string; } export default function NoteCardModalContent(props: Props) { const cardStatus = useGetCardFromMyLibrary({ url: props.cardContent.url }); const isMyCard = props.cardAuthor?.id === cardStatus.data.card?.author.id; const [note, setNote] = useState(isMyCard ? props.note?.text : ''); const [editMode, setEditMode] = useState(false); const [showDeleteWarning, setShowDeleteWarning] = useState(false); const removeNote = useRemoveCardFromLibrary(); const updateNote = useUpdateNote(); const handleDeleteNote = () => { if (!isMyCard || !props.note) return; removeNote.mutate(props.note.id, { onError: () => { notifications.show({ message: 'Could not delete note.', position: 'top-center', }); }, onSettled: () => { props.onClose(); }, }); }; const handleUpdateNote = () => { if (!props.note || !note) { props.onClose(); return; } if (props.note.text === note) { props.onClose(); return; } updateNote.mutate( { cardId: props.note?.id, note: note, }, { onError: () => { notifications.show({ message: 'Could not update note.', position: 'top-center', }); }, onSettled: () => { setEditMode(false); }, }, ); }; if (editMode) { return (