feat: create placeholder only in All view

This commit is contained in:
Mo Bitar
2020-10-08 10:03:36 -05:00
parent 9fc7de74d4
commit 02ccc2d8a6

View File

@@ -140,9 +140,7 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
/** @override */ /** @override */
onAppStateEvent(eventName: AppStateEvent, data?: any) { onAppStateEvent(eventName: AppStateEvent, data?: any) {
if (eventName === AppStateEvent.TagChanged) { if (eventName === AppStateEvent.TagChanged) {
this.handleTagChange( this.handleTagChange(this.selectedTag!);
this.application!.getAppState().getSelectedTag()!
);
} else if (eventName === AppStateEvent.ActiveEditorChanged) { } else if (eventName === AppStateEvent.ActiveEditorChanged) {
this.handleEditorChange(); this.handleEditorChange();
} else if (eventName === AppStateEvent.PreferencesChanged) { } else if (eventName === AppStateEvent.PreferencesChanged) {
@@ -173,7 +171,7 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
break; break;
case ApplicationEvent.CompletedFullSync: case ApplicationEvent.CompletedFullSync:
this.getMostValidNotes().then((notes) => { this.getMostValidNotes().then((notes) => {
if (notes.length === 0) { if (notes.length === 0 && this.selectedTag?.isAllTag) {
this.createPlaceholderNote(); this.createPlaceholderNote();
} }
}); });
@@ -208,7 +206,7 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
* as part of user interaction (pressing the + button). * as part of user interaction (pressing the + button).
*/ */
private async createPlaceholderNote() { private async createPlaceholderNote() {
const selectedTag = this.application!.getAppState().getSelectedTag()!; const selectedTag = this.selectedTag!;
if (selectedTag.isSmartTag() && !selectedTag.isAllTag) { if (selectedTag.isSmartTag() && !selectedTag.isAllTag) {
return; return;
} }
@@ -291,9 +289,7 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
if (this.getState().notes!.length > 0) { if (this.getState().notes!.length > 0) {
this.selectFirstNote(); this.selectFirstNote();
} else if (dbLoaded) { } else if (dbLoaded) {
if (!tag.isSmartTag() || tag.isAllTag) { if (
this.createPlaceholderNote();
} else if (
this.activeEditorNote && this.activeEditorNote &&
!this.getState().notes!.includes(this.activeEditorNote!) !this.getState().notes!.includes(this.activeEditorNote!)
) { ) {
@@ -346,8 +342,12 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
); );
} }
private get selectedTag() {
return this.application!.getAppState().getSelectedTag();
}
currentTagCanHavePlaceholderNotes() { currentTagCanHavePlaceholderNotes() {
const selectedTag = this.application!.getAppState().getSelectedTag()!; const selectedTag = this.selectedTag!;
return selectedTag.isAllTag || !selectedTag.isSmartTag() return selectedTag.isAllTag || !selectedTag.isSmartTag()
} }
@@ -357,15 +357,7 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
return; return;
} }
const notes = this.application.getDisplayableItems(ContentType.Note) as SNNote[]; const notes = this.application.getDisplayableItems(ContentType.Note) as SNNote[];
let renderedNotes: SNNote[]; let renderedNotes = notes.slice(0, this.notesToDisplay);
if (
this.appState.getActiveEditor()?.isTemplateNote &&
this.currentTagCanHavePlaceholderNotes()
) {
renderedNotes = [this.appState.getActiveEditor().note, ...notes.slice(0, this.notesToDisplay)];
} else {
renderedNotes = notes.slice(0, this.notesToDisplay);
}
await this.setNotesState({ await this.setNotesState({
notes, notes,
renderedNotes, renderedNotes,
@@ -622,8 +614,6 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
const note = this.getFirstNonProtectedNote(); const note = this.getFirstNonProtectedNote();
if (note) { if (note) {
this.selectNote(note); this.selectNote(note);
} else if (!this.appState.selectedTag || !this.appState.selectedTag.isSmartTag()) {
this.createPlaceholderNote();
} else { } else {
this.appState.closeActiveEditor(); this.appState.closeActiveEditor();
} }