import React from 'react'; import { Link, confirm, ItemMenu } from 'UI'; import { tagProps, Note } from 'App/services/NotesService'; import { formatTimeOrDate } from 'App/date'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; import copy from 'copy-to-clipboard'; import { toast } from 'react-toastify'; import { session } from 'App/routes'; import { Tag } from 'antd'; import TeamBadge from './TeamBadge'; import { useTranslation } from 'react-i18next'; interface Props { note: Note; } function NoteItem(props: Props) { const { settingsStore, notesStore } = useStore(); const { timezone } = settingsStore.sessionSettings; const { t } = useTranslation(); const onCopy = () => { copy( `${window.location.origin}/${window.location.pathname.split('/')[1]}${session( props.note.sessionId, )}${props.note.timestamp > 0 ? `?jumpto=${props.note.timestamp}¬e=${props.note.noteId}` : `?note=${props.note.noteId}`}`, ); toast.success(t('Note URL copied to clipboard')); }; const onDelete = async () => { if ( await confirm({ header: t('Confirm'), confirmButton: t('Yes, delete'), confirmation: t('Are you sure you want to delete this note?'), }) ) { notesStore.deleteNote(props.note.noteId).then((r) => { notesStore.fetchNotes(); toast.success(t('Note deleted')); }); } }; const menuItems = [ { icon: 'link-45deg', text: t('Copy Link'), onClick: onCopy }, { icon: 'trash', text: t('Delete'), onClick: onDelete }, ]; const safeStrMessage = props.note.message.length > 150 ? `${props.note.message.slice(0, 150)}...` : props.note.message; return (
0 ? `?jumpto=${props.note.timestamp}¬e=${props.note.noteId}` : `?note=${props.note.noteId}`) } >
{props.note.tag ? ( {props.note.tag} ) : null}
{safeStrMessage}
{t('By')}{' '} {props.note.userName},{' '} {formatTimeOrDate( props.note.createdAt as unknown as number, timezone, )}
{!props.note.isPublic ? null : }
{/*
*/}
); } export default observer(NoteItem);