import { WebApplication } from '@/ui_models/application'; import { CollectionSort, sanitizeHtmlString, SNNote, } from '@standardnotes/snjs'; import { FunctionComponent } from 'preact'; import { Icon } from './Icon'; type Props = { application: WebApplication; note: SNNote; tags: string[]; hideDate: boolean; hidePreview: boolean; hideTags: boolean; hideEditorIcon: 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.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 = ({ application, hideDate, hidePreview, hideTags, hideEditorIcon, note, onClick, onContextMenu, selected, sortedBy, tags, }) => { const flags = flagsForNote(note); const showModifiedDate = sortedBy === CollectionSort.UpdatedAt; const editorForNote = application.componentManager.editorForNote(note); const editorName = editorForNote?.name ?? 'Plain editor'; const [icon, tint] = application.iconsController.getIconAndTintForEditor( editorForNote?.identifier ); return (
{!hideEditorIcon && (
)}
{note.title}
{note.locked && ( )} {note.trashed && ( )} {note.archived && ( )} {note.pinned && ( )}
{!hidePreview && !note.hidePreview && !note.protected && (
{note.preview_html && (
)} {!note.preview_html && note.preview_plain && (
{note.preview_plain}
)} {!note.preview_html && !note.preview_plain && note.text && (
{note.text}
)}
)} {!hideDate || note.protected ? (
{note.protected && Protected {hideDate ? '' : ' • '}} {!hideDate && showModifiedDate && ( Modified {note.updatedAtString || 'Now'} )} {!hideDate && !showModifiedDate && ( {note.createdAtString || 'Now'} )}
) : null} {!hideTags && tags.length ? (
{tags.map((tag) => ( {tag} ))}
) : null} {flags.length ? (
{flags.map((flag) => (
{flag.text}
))}
) : null}
); };