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

View File

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

View File

@@ -3,9 +3,9 @@ export function selectOnClick($window: ng.IWindowService) {
return { return {
restrict: 'A', restrict: 'A',
link: function(scope: ng.IScope, element: JQLite) { link: function(scope: ng.IScope, element: JQLite) {
element.on('focus', function() { element.on('focus', () => {
if (!$window.getSelection()!.toString()) { if (!$window.getSelection()!.toString()) {
const input = element as any; const input = element[0] as HTMLInputElement;
/** Required for mobile Safari */ /** Required for mobile Safari */
input.setSelectionRange(0, input.value.length); input.setSelectionRange(0, input.value.length);
} }

View File

@@ -190,7 +190,7 @@ export class AppState {
/** Returns the tags that are referncing this note */ /** Returns the tags that are referncing this note */
getNoteTags(note: SNNote) { getNoteTags(note: SNNote) {
return this.application.referencingForItem(note).filter((ref) => { return this.application.referencingForItem(note).filter((ref) => {
return ref.content_type === note.content_type; return ref.content_type === ContentType.Tag;
}) as SNTag[] }) as SNTag[]
} }

View File

@@ -19,10 +19,10 @@
label='editor.name', label='editor.name',
) )
.sk-menu-panel-column( .sk-menu-panel-column(
ng-if='editor.content.conflict_of' ng-if='editor.conflictOf'
) )
.info( .info(
ng-if='editor.content.conflict_of' ng-if='editor.conflictOf'
) Conflicted copy ) Conflicted copy
a.no-decoration( a.no-decoration(
href='https://standardnotes.org/extensions', href='https://standardnotes.org/extensions',

View File

@@ -81,7 +81,7 @@
action='self.selectedMenuItem(true); self.toggleProtectNote()', action='self.selectedMenuItem(true); self.toggleProtectNote()',
desc=`'Protecting a note will require credentials to view desc=`'Protecting a note will require credentials to view
it (Manage Privileges via Account menu)'`, it (Manage Privileges via Account menu)'`,
label="self.state.note.content.protected ? 'Unprotect' : 'Protect'" label="self.state.note.protected ? 'Unprotect' : 'Protect'"
) )
menu-row( menu-row(
action='self.selectedMenuItem(true); self.toggleNotePreview()', action='self.selectedMenuItem(true); self.toggleNotePreview()',
@@ -94,22 +94,22 @@
action='self.selectedMenuItem(); self.deleteNote()', action='self.selectedMenuItem(); self.deleteNote()',
desc="'Send this note to the trash'", desc="'Send this note to the trash'",
label="'Move to Trash'", label="'Move to Trash'",
ng-show='!self.state.altKeyDown && !self.state.note.content.trashed && !self.state.note.errorDecrypting', ng-show='!self.state.altKeyDown && !self.state.note.trashed && !self.state.note.errorDecrypting',
stylekit-class="'warning'" stylekit-class="'warning'"
) )
menu-row( menu-row(
action='self.selectedMenuItem(); self.deleteNotePermanantely()', action='self.selectedMenuItem(); self.deleteNotePermanantely()',
desc="'Delete this note permanently from all your devices'", desc="'Delete this note permanently from all your devices'",
label="'Delete Permanently'", label="'Delete Permanently'",
ng-show='!self.state.note.content.trashed && self.state.note.errorDecrypting', ng-show='!self.state.note.trashed && self.state.note.errorDecrypting',
stylekit-class="'danger'" stylekit-class="'danger'"
) )
div(ng-if='self.state.note.content.trashed || self.state.altKeyDown') div(ng-if='self.state.note.trashed || self.state.altKeyDown')
menu-row( menu-row(
action='self.selectedMenuItem(true); self.restoreTrashedNote()', action='self.selectedMenuItem(true); self.restoreTrashedNote()',
desc="'Undelete this note and restore it back into your notes'", desc="'Undelete this note and restore it back into your notes'",
label="'Restore'", label="'Restore'",
ng-show='self.state.note.content.trashed', ng-show='self.state.note.trashed',
stylekit-class="'info'" stylekit-class="'info'"
) )
menu-row( menu-row(
@@ -122,7 +122,7 @@
action='self.selectedMenuItem(true); self.emptyTrash()', action='self.selectedMenuItem(true); self.emptyTrash()',
desc="'Permanently delete all notes in the trash'", desc="'Permanently delete all notes in the trash'",
label="'Empty Trash'", label="'Empty Trash'",
ng-show='self.state.note.content.trashed || !self.state.altKeyDown', ng-show='self.state.note.trashed || !self.state.altKeyDown',
stylekit-class="'danger'", stylekit-class="'danger'",
subtitle="self.getTrashCount() + ' notes in trash'" subtitle="self.getTrashCount() + ' notes in trash'"
) )

View File

@@ -109,7 +109,7 @@
) )
.note( .note(
ng-repeat='note in self.state.renderedNotes track by note.uuid' ng-repeat='note in self.state.renderedNotes track by note.uuid'
ng-class="{'selected' : self.state.selectedNote == note}" ng-class="{'selected' : self.selectedNote == note}"
ng-click='self.selectNote(note, true)' ng-click='self.selectNote(note, true)'
) )
.note-flags(ng-show='self.noteFlags[note.uuid].length > 0') .note-flags(ng-show='self.noteFlags[note.uuid].length > 0')
@@ -124,14 +124,14 @@
!note.protected` !note.protected`
) )
.html-preview( .html-preview(
ng-bind-html='note.content.preview_html', ng-bind-html='note.preview_html',
ng-show='note.content.preview_html' ng-show='note.preview_html'
) )
.plain-preview( .plain-preview(
ng-show='!note.content.preview_html && note.content.preview_plain' ng-show='!note.preview_html && note.preview_plain'
) {{note.content.preview_plain}} ) {{note.preview_plain}}
.default-preview( .default-preview(
ng-show='!note.content.preview_html && !note.content.preview_plain' ng-show='!note.preview_html && !note.preview_plain'
) {{note.text}} ) {{note.text}}
.date.faded(ng-show='!self.state.hideDate') .date.faded(ng-show='!self.state.hideDate')
span(ng-show="self.state.sortBy == 'client_updated_at'") span(ng-show="self.state.sortBy == 'client_updated_at'")

View File

@@ -18,7 +18,7 @@
.scrollable .scrollable
.infinite-scroll .infinite-scroll
.tag( .tag(
ng-class="{'selected' : self.state.selectedTag == tag, 'faded' : !tag.content.isAllTag}", ng-class="{'selected' : self.state.selectedTag == tag, 'faded' : !tag.isAllTag}",
ng-click='self.selectTag(tag)', ng-click='self.selectTag(tag)',
ng-repeat='tag in self.state.smartTags track by tag.uuid' ng-repeat='tag in self.state.smartTags track by tag.uuid'
) )
@@ -26,9 +26,9 @@
input.title( input.title(
ng-disabled='true', ng-disabled='true',
ng-change='self.onTagTitleChange(tag)' ng-change='self.onTagTitleChange(tag)'
ng-model='self.titles[tag.uuid]' ng-model='tag.title'
) )
.count(ng-show='tag.content.isAllTag') {{self.state.noteCounts[tag.uuid]}} .count(ng-show='tag.isAllTag') {{self.state.noteCounts[tag.uuid]}}
.tags-title-section.section-title-bar .tags-title-section.section-title-bar
.section-title-bar-header .section-title-bar-header
.sk-h3.title .sk-h3.title
@@ -53,7 +53,7 @@
spellcheck='false' spellcheck='false'
) )
.count {{self.state.noteCounts[tag.uuid]}} .count {{self.state.noteCounts[tag.uuid]}}
.danger.small-text.bold(ng-show='tag.content.conflict_of') Conflicted Copy .danger.small-text.bold(ng-show='tag.conflictOf') Conflicted Copy
.danger.small-text.bold(ng-show='tag.errorDecrypting && !tag.waitingForKey') Missing Keys .danger.small-text.bold(ng-show='tag.errorDecrypting && !tag.waitingForKey') Missing Keys
.info.small-text.bold(ng-show='tag.errorDecrypting && tag.waitingForKey') Waiting For Keys .info.small-text.bold(ng-show='tag.errorDecrypting && tag.waitingForKey') Waiting For Keys
.menu(ng-show='self.state.selectedTag == tag') .menu(ng-show='self.state.selectedTag == tag')

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long