fix: insert template note before opening editor menu (#838)
This commit is contained in:
@@ -963,6 +963,12 @@ export class NoteView extends PureComponent<Props, State> {
|
|||||||
observer.observe(editor.parentElement as HTMLElement, { childList: true });
|
observer.observe(editor.parentElement as HTMLElement, { childList: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ensureNoteIsInsertedBeforeUIAction = async () => {
|
||||||
|
if (this.controller.isTemplateNote) {
|
||||||
|
await this.controller.insertTemplatedNote();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.state.showProtectedWarning) {
|
if (this.state.showProtectedWarning) {
|
||||||
return (
|
return (
|
||||||
@@ -1072,17 +1078,23 @@ export class NoteView extends PureComponent<Props, State> {
|
|||||||
<div className="desc">{this.state.noteStatus.desc}</div>
|
<div className="desc">{this.state.noteStatus.desc}</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{this.appState.notes.selectedNotesCount > 0 && (
|
<>
|
||||||
<>
|
<div className="mr-3">
|
||||||
<div className="mr-3">
|
<PinNoteButton
|
||||||
<PinNoteButton appState={this.appState} />
|
|
||||||
</div>
|
|
||||||
<NotesOptionsPanel
|
|
||||||
application={this.application}
|
|
||||||
appState={this.appState}
|
appState={this.appState}
|
||||||
|
onClickPreprocessing={
|
||||||
|
this.ensureNoteIsInsertedBeforeUIAction
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</>
|
</div>
|
||||||
)}
|
<NotesOptionsPanel
|
||||||
|
application={this.application}
|
||||||
|
appState={this.appState}
|
||||||
|
onClickPreprocessing={
|
||||||
|
this.ensureNoteIsInsertedBeforeUIAction
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<NoteTagsContainer appState={this.appState} />
|
<NoteTagsContainer appState={this.appState} />
|
||||||
|
|||||||
@@ -15,10 +15,11 @@ import { WebApplication } from '@/ui_models/application';
|
|||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
|
onClickPreprocessing?: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NotesOptionsPanel = observer(
|
export const NotesOptionsPanel = observer(
|
||||||
({ application, appState }: Props) => {
|
({ application, appState, onClickPreprocessing }: Props) => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [position, setPosition] = useState({
|
const [position, setPosition] = useState({
|
||||||
top: 0,
|
top: 0,
|
||||||
@@ -37,7 +38,7 @@ export const NotesOptionsPanel = observer(
|
|||||||
return (
|
return (
|
||||||
<Disclosure
|
<Disclosure
|
||||||
open={open}
|
open={open}
|
||||||
onChange={() => {
|
onChange={async () => {
|
||||||
const rect = buttonRef.current?.getBoundingClientRect();
|
const rect = buttonRef.current?.getBoundingClientRect();
|
||||||
if (rect) {
|
if (rect) {
|
||||||
const { clientHeight } = document.documentElement;
|
const { clientHeight } = document.documentElement;
|
||||||
@@ -52,7 +53,11 @@ export const NotesOptionsPanel = observer(
|
|||||||
top: rect.bottom,
|
top: rect.bottom,
|
||||||
right: document.body.clientWidth - rect.right,
|
right: document.body.clientWidth - rect.right,
|
||||||
});
|
});
|
||||||
setOpen(!open);
|
const newOpenState = !open;
|
||||||
|
if (newOpenState && onClickPreprocessing) {
|
||||||
|
await onClickPreprocessing();
|
||||||
|
}
|
||||||
|
setOpen(newOpenState);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -7,14 +7,18 @@ import { Icon } from './Icon';
|
|||||||
type Props = {
|
type Props = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
onClickPreprocessing?: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PinNoteButton: FunctionComponent<Props> = observer(
|
export const PinNoteButton: FunctionComponent<Props> = observer(
|
||||||
({ appState, className = '' }) => {
|
({ appState, className = '', onClickPreprocessing }) => {
|
||||||
const notes = Object.values(appState.notes.selectedNotes);
|
const notes = Object.values(appState.notes.selectedNotes);
|
||||||
const pinned = notes.some((note) => note.pinned);
|
const pinned = notes.some((note) => note.pinned);
|
||||||
|
|
||||||
const togglePinned = () => {
|
const togglePinned = async () => {
|
||||||
|
if (onClickPreprocessing) {
|
||||||
|
await onClickPreprocessing();
|
||||||
|
}
|
||||||
if (!pinned) {
|
if (!pinned) {
|
||||||
appState.notes.setPinSelectedNotes(true);
|
appState.notes.setPinSelectedNotes(true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user