Merge remote-tracking branch 'upstream/develop' into account-menu-split-fix

This commit is contained in:
VardanHakobyan
2021-06-24 12:58:58 +03:00
7 changed files with 52 additions and 14 deletions

View File

@@ -27,7 +27,10 @@ const SearchOptions = observer(({ appState }: Props) => {
} = searchOptions;
const [open, setOpen] = useState(false);
const [optionsPanelTop, setOptionsPanelTop] = useState(0);
const [position, setPosition] = useState({
top: 0,
right: 0,
});
const buttonRef = useRef<HTMLButtonElement>();
const panelRef = useRef<HTMLDivElement>();
const [closeOnBlur, setLockCloseOnBlur] = useCloseOnBlur(panelRef, setOpen);
@@ -45,9 +48,12 @@ const SearchOptions = observer(({ appState }: Props) => {
<Disclosure
open={open}
onChange={() => {
const { height } = buttonRef.current.getBoundingClientRect();
setOptionsPanelTop(height);
setOpen((prevOpen) => !prevOpen);
const rect = buttonRef.current.getBoundingClientRect();
setPosition({
top: rect.bottom,
right: document.body.clientWidth - rect.right,
});
setOpen(!open);
}}
>
<DisclosureButton
@@ -61,9 +67,9 @@ const SearchOptions = observer(({ appState }: Props) => {
<DisclosurePanel
ref={panelRef}
style={{
top: optionsPanelTop,
...position,
}}
className="sn-dropdown sn-dropdown--anchor-right sn-dropdown--animated min-w-80 absolute grid gap-2 py-2"
className="sn-dropdown sn-dropdown--animated min-w-80 fixed grid gap-2 py-2"
onBlur={closeOnBlur}
>
<Switch

View File

@@ -61,10 +61,11 @@ class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> {
}
}
async openSessionRevision(revision: HistoryEntry) {
async openSessionRevision(revision: HistoryEntry & { previewTitle: () => string }) {
this.application.presentRevisionPreviewModal(
revision.payload.uuid,
revision.payload.content
revision.payload.content,
revision.previewTitle()
);
}
@@ -84,7 +85,8 @@ class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> {
}
this.application.presentRevisionPreviewModal(
remoteRevision.payload.uuid,
remoteRevision.payload.content
remoteRevision.payload.content,
this.previewRemoteHistoryTitle(revision)
);
}
@@ -154,7 +156,7 @@ class HistoryMenuCtrl extends PureViewCtrl<unknown, HistoryState> {
this.reloadState();
}
previewRemoteHistoryTitle(revision: SingleRevision) {
previewRemoteHistoryTitle(revision: RevisionListEntry) {
return new Date(revision.created_at).toLocaleString();
}
}

View File

@@ -24,6 +24,7 @@ class RevisionPreviewModalCtrl extends PureViewCtrl implements RevisionPreviewSc
$timeout: ng.ITimeoutService
uuid!: string
content!: PayloadContent
title?: string
application!: WebApplication
unregisterComponent?: any
note!: SNNote
@@ -139,6 +140,7 @@ export class RevisionPreviewModal extends WebDirective {
this.scope = {
uuid: '=',
content: '=',
title: '=',
application: '='
};
}

View File

@@ -189,13 +189,14 @@ export class WebApplication extends SNApplication {
this.applicationElement.append(el);
}
presentRevisionPreviewModal(uuid: string, content: any) {
presentRevisionPreviewModal(uuid: string, content: any, title?: string) {
const scope: any = this.scope!.$new(true);
scope.uuid = uuid;
scope.content = content;
scope.title = title;
scope.application = this;
const el = this.$compile!(
`<revision-preview-modal application='application' uuid='uuid' content='content'
`<revision-preview-modal application='application' uuid='uuid' content='content' title='title'
class='sk-modal'></revision-preview-modal>`
)(scope);
this.applicationElement.append(el);

View File

@@ -105,6 +105,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
public editorValues: EditorValues = { title: '', text: '' };
onEditorLoad?: () => void;
private scrollPosition = 0;
private removeAltKeyObserver?: any;
private removeTrashKeyObserver?: any;
private removeTabObserver?: any;
@@ -131,6 +132,8 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
this.editorMenuOnSelect = this.editorMenuOnSelect.bind(this);
this.onPanelResizeFinish = this.onPanelResizeFinish.bind(this);
this.setScrollPosition = this.setScrollPosition.bind(this);
this.resetScrollPosition = this.resetScrollPosition.bind(this);
this.onEditorLoad = () => {
this.application!.getDesktopService().redoSearch();
};
@@ -868,6 +871,20 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
});
}
setScrollPosition() {
const editor = document.getElementById(
ElementIds.NoteTextEditor
) as HTMLInputElement;
this.scrollPosition = editor.scrollTop;
}
resetScrollPosition() {
const editor = document.getElementById(
ElementIds.NoteTextEditor
) as HTMLInputElement;
editor.scrollTop = this.scrollPosition;
}
onSystemEditorLoad() {
if (this.removeTabObserver) {
return;
@@ -915,6 +932,9 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
},
});
editor.addEventListener('scroll', this.setScrollPosition);
editor.addEventListener('input', this.resetScrollPosition);
/**
* Handles when the editor is destroyed,
* (and not when our controller is destroyed.)
@@ -922,6 +942,9 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
angular.element(editor).one('$destroy', () => {
this.removeTabObserver?.();
this.removeTabObserver = undefined;
editor.removeEventListener('scroll', this.setScrollPosition);
editor.removeEventListener('scroll', this.resetScrollPosition);
this.scrollPosition = 0;
});
}
}

View File

@@ -216,7 +216,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
break;
case ApplicationEvent.CompletedFullSync:
this.getMostValidNotes().then((notes) => {
if (notes.length === 0 && this.selectedTag?.isAllTag) {
if (notes.length === 0 && this.selectedTag?.isAllTag && this.state.noteFilter.text === '') {
this.createPlaceholderNote();
}
});