This commit is contained in:
Mo Bitar
2020-04-13 18:39:25 -05:00
parent 82f71aa923
commit ef66170ba4
10 changed files with 134 additions and 118 deletions

View File

@@ -13,7 +13,8 @@ import {
Uuids,
ComponentArea,
ComponentAction,
WebPrefKey
WebPrefKey,
ComponentMutator
} from 'snjs';
import find from 'lodash/find';
import { isDesktopApplication } from '@/utils';
@@ -31,7 +32,6 @@ import {
StringEmptyTrash
} from '@/strings';
import { RawPayload } from '@/../../../../snjs/dist/@types/protocol/payloads/generator';
import { ComponentMutator } from '@/../../../../snjs/dist/@types/models';
const NOTE_PREVIEW_CHAR_LIMIT = 80;
const MINIMUM_STATUS_DURATION = 400;
@@ -74,7 +74,7 @@ type EditorState = {
tagsComponent?: SNComponent
componentStack?: SNComponent[]
/** Fields that can be directly mutated by the template */
mutable: { }
mutable: {}
}
type EditorValues = {
@@ -244,22 +244,26 @@ class EditorCtrl extends PureCtrl {
if (!currentNote) {
return;
}
if (currentNote.deleted) {
await this.setState({
note: null,
noteReady: false
});
return;
}
if (!isPayloadSourceRetrieved(source!)) {
return;
}
const matchingNote = items.find((item) => {
return item.uuid === currentNote.uuid;
}) as SNNote;
if (!matchingNote) {
return;
}
if (matchingNote?.deleted) {
await this.setState({
note: undefined,
noteReady: false
});
return;
} else {
await this.setState({
note: matchingNote
});
}
if (!isPayloadSourceRetrieved(source!)) {
return;
}
this.editorValues.title = matchingNote.title;
this.editorValues.text = matchingNote.text;
this.reloadTagsString();
@@ -314,13 +318,15 @@ class EditorCtrl extends PureCtrl {
}
async handleNoteSelectionChange(note: SNNote, previousNote?: SNNote) {
this.setState({
note: this.application.getAppState().getSelectedNote(),
await this.setState({
note: note,
showExtensions: false,
showOptionsMenu: false,
altKeyDown: false,
noteStatus: null
});
this.editorValues.title = note.title;
this.editorValues.text = note.text;
if (!note) {
this.setState({
noteReady: false
@@ -480,7 +486,7 @@ class EditorCtrl extends PureCtrl {
noteMutator.title = this.editorValues.title!;
noteMutator.text = this.editorValues.text!;
if (!dontUpdatePreviews) {
const text = note.text || '';
const text = this.editorValues.text || '';
const truncate = text.length > NOTE_PREVIEW_CHAR_LIMIT;
const substring = text.substring(0, NOTE_PREVIEW_CHAR_LIMIT);
const previewPlain = substring + (truncate ? STRING_ELLIPSES : '');

View File

@@ -18,7 +18,6 @@ type NotesState = {
tag?: SNTag
notes?: SNNote[]
renderedNotes?: SNNote[]
selectedNote?: SNNote
sortBy?: string
sortReverse?: boolean
showArchived?: boolean
@@ -136,12 +135,16 @@ class NotesCtrl extends PureCtrl {
}
}
get selectedNote() {
return this.appState.getSelectedNote();
}
/** @override */
async onAppEvent(eventName: ApplicationEvent) {
if (eventName === ApplicationEvent.SignedIn) {
/** Delete dummy note if applicable */
if (this.getState().selectedNote && this.getState().selectedNote!.dummy) {
this.application!.deleteItemLocally(this.getState().selectedNote!);
if (this.selectedNote && this.selectedNote!.dummy) {
this.application!.deleteItemLocally(this.selectedNote!);
await this.selectNote(undefined);
await this.reloadNotes();
}
@@ -193,7 +196,7 @@ class NotesCtrl extends PureCtrl {
[ContentType.Note, ContentType.Tag],
async (items) => {
await this.reloadNotes();
const selectedNote = this.getState().selectedNote;
const selectedNote = this.selectedNote;
if (selectedNote) {
const discarded = selectedNote.deleted || selectedNote.trashed;
if (discarded) {
@@ -229,7 +232,7 @@ class NotesCtrl extends PureCtrl {
if (this.isFiltering()) {
title = this.getState().noteFilter.text;
isDummyNote = false;
} else if (this.getState().selectedNote && this.getState().selectedNote!.dummy) {
} else if (this.selectedNote && this.selectedNote!.dummy) {
return;
} else {
title = `Note ${this.getState().notes!.length + 1}`;
@@ -255,8 +258,8 @@ class NotesCtrl extends PureCtrl {
}
async handleTagChange(tag: SNTag, previousTag?: SNTag) {
if (this.getState().selectedNote && this.getState().selectedNote!.dummy) {
await this.application!.deleteItemLocally(this.getState().selectedNote!);
if (this.selectedNote && this.selectedNote!.dummy) {
await this.application!.deleteItemLocally(this.selectedNote!);
await this.selectNote(undefined);
}
await this.setState({ tag: tag });
@@ -277,8 +280,8 @@ class NotesCtrl extends PureCtrl {
if (!tag.isSmartTag() || tag.isAllTag) {
this.createPlaceholderNote();
} else if (
this.getState().selectedNote &&
!this.getState().notes!.includes(this.getState().selectedNote!)
this.selectedNote &&
!this.getState().notes!.includes(this.selectedNote!)
) {
this.selectNote(undefined);
}
@@ -344,7 +347,7 @@ class NotesCtrl extends PureCtrl {
}
async handleNoteSelection(note: SNNote) {
const previousNote = this.getState().selectedNote;
const previousNote = this.selectedNote;
if (previousNote === note) {
return;
}
@@ -352,9 +355,6 @@ class NotesCtrl extends PureCtrl {
await this.application!.deleteItemLocally(previousNote);
this.removeNoteFromList(previousNote);
}
await this.setState({
selectedNote: note
});
if (!note) {
return;
}
@@ -584,7 +584,7 @@ class NotesCtrl extends PureCtrl {
selectNextNote() {
const displayableNotes = this.displayableNotes();
const currentIndex = displayableNotes.findIndex((candidate) => {
return candidate.uuid === this.getState().selectedNote!.uuid
return candidate.uuid === this.selectedNote!.uuid
});
if (currentIndex + 1 < displayableNotes.length) {
this.selectNote(displayableNotes[currentIndex + 1]);
@@ -604,7 +604,7 @@ class NotesCtrl extends PureCtrl {
selectPreviousNote() {
const displayableNotes = this.displayableNotes();
const currentIndex = displayableNotes.indexOf(this.getState().selectedNote!);
const currentIndex = displayableNotes.indexOf(this.selectedNote!);
if (currentIndex - 1 >= 0) {
this.selectNote(displayableNotes[currentIndex - 1]);
return true;