import { CollectionSort, SNNote } from '@standardnotes/snjs'; import { FunctionComponent } from 'preact'; type Props = { note: SNNote; tags: string; hideDate: boolean; hidePreview: boolean; hideTags: boolean; onClick: () => void; onContextMenu: (e: MouseEvent) => void; selected: boolean; sortedBy?: CollectionSort; }; type NoteFlag = { text: string; class: 'info' | 'neutral' | 'warning' | 'success' | 'danger'; }; const flagsForNote = (note: SNNote) => { const flags = [] as NoteFlag[]; if (note.pinned) { flags.push({ text: 'Pinned', class: 'info', }); } if (note.archived) { flags.push({ text: 'Archived', class: 'warning', }); } if (note.locked) { flags.push({ text: 'Editing Disabled', class: 'neutral', }); } if (note.trashed) { flags.push({ text: 'Deleted', class: 'danger', }); } if (note.conflictOf) { flags.push({ text: 'Conflicted Copy', class: 'danger', }); } if (note.errorDecrypting) { if (note.waitingForKey) { flags.push({ text: 'Waiting For Keys', class: 'info', }); } else { flags.push({ text: 'Missing Keys', class: 'danger', }); } } if (note.deleted) { flags.push({ text: 'Deletion Pending Sync', class: 'danger', }); } return flags; }; export const NotesListItem: FunctionComponent = ({ hideDate, hidePreview, hideTags, note, onClick, onContextMenu, selected, sortedBy, tags, }) => { const flags = flagsForNote(note); const showModifiedDate = sortedBy === CollectionSort.UpdatedAt; return (
{flags && flags.length > 0 ? (
{flags.map((flag) => (
{flag.text}
))}
) : null}
{note.title}
{!hidePreview && !note.hidePreview && !note.protected ? (
{note.preview_html ? (
) : null} {!note.preview_html && note.preview_plain ? (
{note.preview_plain}
) : null} {!note.preview_html && !note.preview_plain ? (
{note.text}
) : null}
) : null} {!hideDate || note.protected ? (
{note.protected ? ( Protected {hideDate ? '' : ' • '} ) : null} {!hideDate && showModifiedDate ? ( Modified {note.updatedAtString || 'Now'} ) : null} {!hideDate && !showModifiedDate ? ( {note.createdAtString || 'Now'} ) : null}
) : null} {!hideTags && (
{tags}
)}
); };