import { WebApplication } from '@/UIModels/Application' import { CollectionSort, CollectionSortProperty, sanitizeHtmlString, SNNote, } from '@standardnotes/snjs' import { FunctionComponent } from 'preact' import { Icon } from '@/Components/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?: CollectionSortProperty } 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', }) } 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.length ?
{note.title}
: null}
{!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}
{note.locked && ( )} {note.trashed && ( )} {note.archived && ( )} {note.pinned && ( )}
) }