import { WebApplication } from '@/UIModels/Application' import { CollectionSort, CollectionSortProperty, PrefKey } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { useState } from 'preact/hooks' import { Icon } from '@/Components/Icon' import { Menu } from '@/Components/Menu/Menu' import { MenuItem, MenuItemSeparator, MenuItemType } from '@/Components/Menu/MenuItem' type Props = { application: WebApplication closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void closeDisplayOptionsMenu: () => void isOpen: boolean } export const NotesListOptionsMenu: FunctionComponent = observer( ({ closeDisplayOptionsMenu, closeOnBlur, application, isOpen }) => { const [sortBy, setSortBy] = useState(() => application.getPreference(PrefKey.SortNotesBy, CollectionSort.CreatedAt)) const [sortReverse, setSortReverse] = useState(() => application.getPreference(PrefKey.SortNotesReverse, false)) const [hidePreview, setHidePreview] = useState(() => application.getPreference(PrefKey.NotesHideNotePreview, false)) const [hideDate, setHideDate] = useState(() => application.getPreference(PrefKey.NotesHideDate, false)) const [hideTags, setHideTags] = useState(() => application.getPreference(PrefKey.NotesHideTags, true)) const [hidePinned, setHidePinned] = useState(() => application.getPreference(PrefKey.NotesHidePinned, false)) const [showArchived, setShowArchived] = useState(() => application.getPreference(PrefKey.NotesShowArchived, false)) const [showTrashed, setShowTrashed] = useState(() => application.getPreference(PrefKey.NotesShowTrashed, false)) const [hideProtected, setHideProtected] = useState(() => application.getPreference(PrefKey.NotesHideProtected, false), ) const [hideEditorIcon, setHideEditorIcon] = useState(() => application.getPreference(PrefKey.NotesHideEditorIcon, false), ) const toggleSortReverse = () => { application.setPreference(PrefKey.SortNotesReverse, !sortReverse).catch(console.error) setSortReverse(!sortReverse) } const toggleSortBy = (sort: CollectionSortProperty) => { if (sortBy === sort) { toggleSortReverse() } else { setSortBy(sort) application.setPreference(PrefKey.SortNotesBy, sort).catch(console.error) } } const toggleSortByDateModified = () => { toggleSortBy(CollectionSort.UpdatedAt) } const toggleSortByCreationDate = () => { toggleSortBy(CollectionSort.CreatedAt) } const toggleSortByTitle = () => { toggleSortBy(CollectionSort.Title) } const toggleHidePreview = () => { setHidePreview(!hidePreview) application.setPreference(PrefKey.NotesHideNotePreview, !hidePreview).catch(console.error) } const toggleHideDate = () => { setHideDate(!hideDate) application.setPreference(PrefKey.NotesHideDate, !hideDate).catch(console.error) } const toggleHideTags = () => { setHideTags(!hideTags) application.setPreference(PrefKey.NotesHideTags, !hideTags).catch(console.error) } const toggleHidePinned = () => { setHidePinned(!hidePinned) application.setPreference(PrefKey.NotesHidePinned, !hidePinned).catch(console.error) } const toggleShowArchived = () => { setShowArchived(!showArchived) application.setPreference(PrefKey.NotesShowArchived, !showArchived).catch(console.error) } const toggleShowTrashed = () => { setShowTrashed(!showTrashed) application.setPreference(PrefKey.NotesShowTrashed, !showTrashed).catch(console.error) } const toggleHideProtected = () => { setHideProtected(!hideProtected) application.setPreference(PrefKey.NotesHideProtected, !hideProtected).catch(console.error) } const toggleEditorIcon = () => { setHideEditorIcon(!hideEditorIcon) application.setPreference(PrefKey.NotesHideEditorIcon, !hideEditorIcon).catch(console.error) } return (
Sort by
Date modified {sortBy === CollectionSort.UpdatedAt ? ( sortReverse ? ( ) : ( ) ) : null}
Creation date {sortBy === CollectionSort.CreatedAt ? ( sortReverse ? ( ) : ( ) ) : null}
Title {sortBy === CollectionSort.Title ? ( sortReverse ? ( ) : ( ) ) : null}
View
Show note preview
Show date Show tags Show editor icon
Other
Show pinned notes Show protected notes Show archived notes Show trashed notes
) }, )