'use client'; import { ActionIcon, Anchor, Button, Card, Flex, Group, Input, Menu, Stack, Text, Textarea, VisuallyHidden, } from '@mantine/core'; import { IoEyeOffOutline } from 'react-icons/io5'; import { BsThreeDots, BsTrash2Fill } from 'react-icons/bs'; import { MdOutlineEdit } from 'react-icons/md'; import { notifications } from '@mantine/notifications'; import type { UrlCard, User } from '@/api-client'; import { useState } from 'react'; import { BsExclamation } from 'react-icons/bs'; import { LinkAvatar } from '@/components/link/MantineLink'; import { isBotAccount } from '@/features/platforms/bluesky/lib/utils/account'; import BotLabel from '@/features/profile/components/botLabel/BotLabel'; import useUpdateNote from '../../lib/mutations/useUpdateNote'; import useRemoveCardFromLibrary from '@/features/cards/lib/mutations/useRemoveCardFromLibrary'; import styles from './NoteCardInline.module.css'; interface Props { note: UrlCard['note']; cardContent: UrlCard['cardContent']; cardAuthor?: User; isOwner: boolean; onClose: () => void; } export default function NoteCardInline(props: Props) { const [noteText, setNoteText] = useState(props.note?.text ?? ''); const [editMode, setEditMode] = useState(false); const [showDeleteWarning, setShowDeleteWarning] = useState(false); const MAX_NOTE_LENGTH = 500; const removeNote = useRemoveCardFromLibrary(); const updateNote = useUpdateNote(); const handleDeleteNote = () => { if (!props.isOwner || !props.note) return; removeNote.mutate(props.note.id, { onError: () => { notifications.show({ message: 'Could not delete note', position: 'top-center', color: 'red', title: 'Error', loading: false, autoClose: false, withCloseButton: true, icon: , }); }, onSettled: () => { props.onClose(); }, }); }; const handleUpdateNote = () => { if (!props.note || !noteText) { props.onClose(); return; } if (props.note.text === noteText) { setEditMode(false); return; } updateNote.mutate( { cardId: props.note.id, note: noteText }, { onError: () => { notifications.show({ message: 'Could not update note', position: 'top-center', color: 'red', title: 'Error', loading: false, autoClose: false, withCloseButton: true, icon: , }); }, onSettled: () => { setEditMode(false); }, }, ); }; if (editMode) { return ( e.stopPropagation()} > Your note {noteText.length} / {MAX_NOTE_LENGTH}