Skip to content

Commit

Permalink
fix: remove locking closeOnBlur
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonella Sgarlatta committed May 7, 2021
1 parent 24eb348 commit 461f3cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
15 changes: 3 additions & 12 deletions app/assets/javascripts/components/NotesContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppState } from '@/ui_models/app_state';
import { toDirective, useCloseOnBlur } from './utils';
import { observer } from 'mobx-react-lite';
import { NotesOptions } from './NotesOptions';
import { useEffect, useRef, useState } from 'preact/hooks';
import { useEffect, useRef } from 'preact/hooks';

type Props = {
appState: AppState;
Expand All @@ -12,18 +12,12 @@ const NotesContextMenu = observer(({ appState }: Props) => {
const contextMenuRef = useRef<HTMLDivElement>();
const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(
contextMenuRef,
(open: boolean) => null
(open: boolean) => appState.notes.setContextMenuOpen(open)
);
const [submenuOpen, setSubmenuOpen] = useState(false);

const closeOnClickOutside = (event: MouseEvent) => {
if (!contextMenuRef.current?.contains(event.target as Node)) {
if (submenuOpen) {
setSubmenuOpen(false);
} else {
console.log('here');
appState.notes.setContextMenuOpen(false);
}
appState.notes.setContextMenuOpen(false);
}
};

Expand All @@ -43,9 +37,6 @@ const NotesContextMenu = observer(({ appState }: Props) => {
<NotesOptions
appState={appState}
closeOnBlur={closeOnBlur}
setLockCloseOnBlur={setLockCloseOnBlur}
submenuOpen={submenuOpen}
setSubmenuOpen={setSubmenuOpen}
/>
</div>
) : null;
Expand Down
11 changes: 2 additions & 9 deletions app/assets/javascripts/components/NotesOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import {
type Props = {
appState: AppState;
closeOnBlur: (event: { relatedTarget: EventTarget | null }) => void;
setLockCloseOnBlur: (lock: boolean) => void;
onSubmenuChange?: (submenuOpen: boolean) => void;
};

const MAX_TAGS_MENU_HEIGHT = 265;

export const NotesOptions = observer(
({ appState, closeOnBlur, setLockCloseOnBlur, onSubmenuChange }: Props) => {
({ appState, closeOnBlur, onSubmenuChange }: Props) => {
const [tagsMenuOpen, setTagsMenuOpen] = useState(false);
const [tagsMenuPosition, setTagsMenuPosition] = useState({
top: 0,
Expand All @@ -33,7 +32,6 @@ export const NotesOptions = observer(
const trashed = !notes.some((note) => !note.trashed);
const pinned = !notes.some((note) => !note.pinned);

const trashButtonRef = useRef<HTMLButtonElement>();
const tagsButtonRef = useRef<HTMLButtonElement>();

const iconClass = 'fill-current color-neutral mr-2';
Expand Down Expand Up @@ -176,13 +174,10 @@ export const NotesOptions = observer(
{archived ? 'Unarchive' : 'Archive'}
</button>
<button
ref={trashButtonRef}
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
setLockCloseOnBlur(true);
await appState.notes.setTrashSelectedNotes(!trashed, trashButtonRef);
setLockCloseOnBlur(false);
await appState.notes.setTrashSelectedNotes(!trashed);
}}
>
<Icon type={trashed ? IconType.Restore : IconType.Trash} className={iconClass} />
Expand All @@ -193,9 +188,7 @@ export const NotesOptions = observer(
onBlur={closeOnBlur}
className={`${buttonClass} py-1.5`}
onClick={async () => {
setLockCloseOnBlur(true);
await appState.notes.deleteNotesPermanently();
setLockCloseOnBlur(false);
}}
>
<Icon type={IconType.Close} className="fill-current color-danger mr-2" />
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/components/NotesOptionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const NotesOptionsPanel = observer(({ appState }: Props) => {
<NotesOptions
appState={appState}
closeOnBlur={closeOnBlur}
setLockCloseOnBlur={setLockCloseOnBlur}
onSubmenuChange={onSubmenuChange}
/>
)}
Expand Down
5 changes: 1 addition & 4 deletions app/assets/javascripts/ui_models/app_state/notes_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ export class NotesState {
}

async setTrashSelectedNotes(
trashed: boolean,
trashButtonRef: RefObject<HTMLButtonElement>
trashed: boolean
): Promise<void> {
if (trashed) {
const notesDeleted = await this.deleteNotes(false);
Expand All @@ -196,8 +195,6 @@ export class NotesState {
this.selectedNotes = {};
this.contextMenuOpen = false;
});
} else {
trashButtonRef.current?.focus();
}
} else {
this.application.changeItems<NoteMutator>(
Expand Down

0 comments on commit 461f3cc

Please sign in to comment.