feat: show menu options according to v4 specs
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
DisclosureButton,
|
DisclosureButton,
|
||||||
DisclosurePanel,
|
DisclosurePanel,
|
||||||
} from '@reach/disclosure';
|
} from '@reach/disclosure';
|
||||||
|
import { SNNote } from '@standardnotes/snjs/dist/@types';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
@@ -25,12 +26,21 @@ export const NotesOptions = observer(
|
|||||||
right: 0,
|
right: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const toggleOn = (condition: (note: SNNote) => boolean) => {
|
||||||
|
const notesMatchingAttribute = notes.filter(condition);
|
||||||
|
const notesNotMatchingAttribute = notes.filter((note) => !condition(note));
|
||||||
|
return (notesMatchingAttribute.length > notesNotMatchingAttribute.length);
|
||||||
|
};
|
||||||
|
|
||||||
const notes = Object.values(appState.notes.selectedNotes);
|
const notes = Object.values(appState.notes.selectedNotes);
|
||||||
const hidePreviews = notes.some((note) => note.hidePreview);
|
const hidePreviews = toggleOn(note => note.hidePreview);
|
||||||
const locked = notes.some((note) => note.locked);
|
const locked = toggleOn(note => note.locked);
|
||||||
const archived = notes.some((note) => note.archived);
|
const archived = notes.some((note) => note.archived);
|
||||||
|
const unarchived = notes.some((note) => !note.archived);
|
||||||
const trashed = notes.some((note) => note.trashed);
|
const trashed = notes.some((note) => note.trashed);
|
||||||
|
const notTrashed = notes.some((note) => !note.trashed);
|
||||||
const pinned = notes.some((note) => note.pinned);
|
const pinned = notes.some((note) => note.pinned);
|
||||||
|
const unpinned = notes.some((note) => !note.pinned);
|
||||||
|
|
||||||
const tagsButtonRef = useRef<HTMLButtonElement>();
|
const tagsButtonRef = useRef<HTMLButtonElement>();
|
||||||
|
|
||||||
@@ -141,48 +151,90 @@ export const NotesOptions = observer(
|
|||||||
</DisclosurePanel>
|
</DisclosurePanel>
|
||||||
</Disclosure>
|
</Disclosure>
|
||||||
)}
|
)}
|
||||||
<button
|
{unpinned && (
|
||||||
onBlur={closeOnBlur}
|
<button
|
||||||
className={`${buttonClass} py-1.5`}
|
onBlur={closeOnBlur}
|
||||||
onClick={() => {
|
className={`${buttonClass} py-1.5`}
|
||||||
appState.notes.setPinSelectedNotes(!pinned);
|
onClick={() => {
|
||||||
}}
|
appState.notes.setPinSelectedNotes(true);
|
||||||
>
|
}}
|
||||||
<Icon
|
>
|
||||||
type={pinned ? 'unpin' : 'pin'}
|
<Icon
|
||||||
className={iconClass}
|
type="pin"
|
||||||
/>
|
className={iconClass}
|
||||||
{appState.notes.selectedNotesCount > 1
|
/>
|
||||||
? pinned
|
Pin to top
|
||||||
? 'Unpin notes'
|
</button>
|
||||||
: 'Pin notes'
|
)}
|
||||||
: pinned
|
{pinned && (
|
||||||
? 'Unpin note'
|
<button
|
||||||
: 'Pin note'}
|
onBlur={closeOnBlur}
|
||||||
</button>
|
className={`${buttonClass} py-1.5`}
|
||||||
<button
|
onClick={() => {
|
||||||
onBlur={closeOnBlur}
|
appState.notes.setPinSelectedNotes(false);
|
||||||
className={`${buttonClass} py-1.5`}
|
}}
|
||||||
onClick={() => {
|
>
|
||||||
appState.notes.setArchiveSelectedNotes(!archived);
|
<Icon
|
||||||
}}
|
type="unpin"
|
||||||
>
|
className={iconClass}
|
||||||
<Icon
|
/>
|
||||||
type={archived ? 'unarchive' : 'archive'}
|
Unpin
|
||||||
className={iconClass}
|
</button>
|
||||||
/>
|
)}
|
||||||
{archived ? 'Unarchive' : 'Archive'}
|
{unarchived && (
|
||||||
</button>
|
<button
|
||||||
<button
|
onBlur={closeOnBlur}
|
||||||
onBlur={closeOnBlur}
|
className={`${buttonClass} py-1.5`}
|
||||||
className={`${buttonClass} py-1.5`}
|
onClick={() => {
|
||||||
onClick={async () => {
|
appState.notes.setArchiveSelectedNotes(true);
|
||||||
await appState.notes.setTrashSelectedNotes(!trashed);
|
}}
|
||||||
}}
|
>
|
||||||
>
|
<Icon
|
||||||
<Icon type={trashed ? 'restore' : 'trash'} className={iconClass} />
|
type="archive"
|
||||||
{trashed ? 'Restore' : 'Move to Trash'}
|
className={iconClass}
|
||||||
</button>
|
/>
|
||||||
|
Archive
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{archived && (
|
||||||
|
<button
|
||||||
|
onBlur={closeOnBlur}
|
||||||
|
className={`${buttonClass} py-1.5`}
|
||||||
|
onClick={() => {
|
||||||
|
appState.notes.setArchiveSelectedNotes(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
type="unarchive"
|
||||||
|
className={iconClass}
|
||||||
|
/>
|
||||||
|
Unarchive
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{notTrashed && (
|
||||||
|
<button
|
||||||
|
onBlur={closeOnBlur}
|
||||||
|
className={`${buttonClass} py-1.5`}
|
||||||
|
onClick={async () => {
|
||||||
|
await appState.notes.setTrashSelectedNotes(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon type='trash' className={iconClass} />
|
||||||
|
Move to Trash
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{trashed && (
|
||||||
|
<button
|
||||||
|
onBlur={closeOnBlur}
|
||||||
|
className={`${buttonClass} py-1.5`}
|
||||||
|
onClick={async () => {
|
||||||
|
await appState.notes.setTrashSelectedNotes(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon type='restore' className={iconClass} />
|
||||||
|
Restore
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
{appState.selectedTag?.isTrashTag && (
|
{appState.selectedTag?.isTrashTag && (
|
||||||
<button
|
<button
|
||||||
onBlur={closeOnBlur}
|
onBlur={closeOnBlur}
|
||||||
@@ -192,7 +244,7 @@ export const NotesOptions = observer(
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon type="close" className="fill-current color-danger mr-2" />
|
<Icon type="close" className="fill-current color-danger mr-2" />
|
||||||
<span className="color-danger">Delete Permanently</span>
|
<span className="color-danger">Delete permanently</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user