Skip to content

Commit

Permalink
fix: don't show empty notes view when the database is loading
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Aug 24, 2020
1 parent d96b058 commit 80ce580
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
4 changes: 3 additions & 1 deletion app/assets/javascripts/views/notes/notes-view.pug
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
faded="self.state.hideDate"
label="'Date'"
)
p.empty-notes-list.faded(ng-if="!self.state.renderedNotes.length") No notes.
p.empty-notes-list.faded(
ng-if="self.state.localDataLoaded && !self.state.renderedNotes.length"
) No notes.
.scrollable(ng-if="self.state.renderedNotes.length")
#notes-scrollable.infinite-scroll(
can-load='true',
Expand Down
44 changes: 31 additions & 13 deletions app/assets/javascripts/views/notes/notes_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { UuidString } from '@node_modules/snjs/dist/@types/types';
type NotesState = {
panelTitle: string
notes?: SNNote[]
renderedNotes?: SNNote[]
renderedNotes: SNNote[]
sortBy?: string
sortReverse?: boolean
showArchived?: boolean
Expand All @@ -37,6 +37,14 @@ type NotesState = {
hideDate?: boolean
noteFilter: { text: string }
mutable: { showMenu: boolean }
localDataLoaded: boolean
[WebPrefKey.TagsPanelWidth]?: number
[WebPrefKey.NotesPanelWidth]?: number
[WebPrefKey.EditorWidth]?: number
[WebPrefKey.EditorLeft]?: number
[WebPrefKey.EditorMonospaceEnabled]?: boolean
[WebPrefKey.EditorSpellcheck]?: boolean
[WebPrefKey.EditorResizersEnabled]?: boolean
}

type NoteFlag = {
Expand All @@ -53,7 +61,7 @@ const DEFAULT_LIST_NUM_NOTES = 20;
const ELEMENT_ID_SEARCH_BAR = 'search-bar';
const ELEMENT_ID_SCROLL_CONTAINER = 'notes-scrollable';

class NotesViewCtrl extends PureViewCtrl {
class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {

private panelPuppet?: PanelPuppet
private reloadNotesPromise?: any
Expand Down Expand Up @@ -116,13 +124,15 @@ class NotesViewCtrl extends PureViewCtrl {
return this.setState(state);
}

getInitialState() {
getInitialState(): NotesState {
return {
notes: [],
renderedNotes: [],
mutable: { showMenu: false },
noteFilter: { text: '' },
} as Partial<NotesState>;
panelTitle: '',
localDataLoaded: false,
};
}

async onAppLaunch() {
Expand Down Expand Up @@ -157,15 +167,23 @@ class NotesViewCtrl extends PureViewCtrl {

/** @override */
async onAppEvent(eventName: ApplicationEvent) {
if (eventName === ApplicationEvent.SignedIn) {
this.appState.closeAllEditors();
this.selectFirstNote();
} else if (eventName === ApplicationEvent.CompletedFullSync) {
this.getMostValidNotes().then((notes) => {
if (notes.length === 0) {
this.createPlaceholderNote();
}
});
switch (eventName) {
case ApplicationEvent.SignedIn:
this.appState.closeAllEditors();
this.selectFirstNote();
break;
case ApplicationEvent.CompletedFullSync:
this.getMostValidNotes().then((notes) => {
if (notes.length === 0) {
this.createPlaceholderNote();
}
});
break;
case ApplicationEvent.LocalDataLoaded:
this.setState({
localDataLoaded: true,
});
break;
}
}

Expand Down

0 comments on commit 80ce580

Please sign in to comment.