Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix features loading with app state #775

Merged
merged 3 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/assets/javascripts/ui_models/app_state/features_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ export class FeaturesState {
enableNativeFoldersFeature: computed,
});

this.unsub = this.application.addEventObserver(async () => {
runInAction(() => {
this._hasFolders = this.hasNativeFolders();
});
}, ApplicationEvent.FeaturesUpdated);
this.unsub = this.application.addEventObserver(async (eventName) => {
switch (eventName) {
case ApplicationEvent.FeaturesUpdated:
case ApplicationEvent.Launched:
runInAction(() => {
this._hasFolders = this.hasNativeFolders();
});
break;
default:
break;
}
});
}

public deinit() {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/views/application/application-view.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
)
#app.app(
ng-class='self.state.appClass',
ng-if='!self.state.needsUnlock && self.state.ready'
ng-if='!self.state.needsUnlock && self.state.launched'
)
tags-view(application='self.application')
notes-view(application='self.application')
editor-group-view.flex-grow(application='self.application')

footer-view(
ng-if='!self.state.needsUnlock && self.state.ready'
ng-if='!self.state.needsUnlock && self.state.launched'
application='self.application'
)

Expand Down
63 changes: 35 additions & 28 deletions app/assets/javascripts/views/application/application_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import { WebDirective } from '@/types';
import { getPlatformString } from '@/utils';
import template from './application-view.pug';
import { AppStateEvent, PanelResizedData } from '@/ui_models/app_state';
import { ApplicationEvent, Challenge, removeFromArray } from '@standardnotes/snjs';
import {
PANEL_NAME_NOTES,
PANEL_NAME_TAGS
} from '@/views/constants';
import {
STRING_DEFAULT_FILE_ERROR
} from '@/strings';
ApplicationEvent,
Challenge,
removeFromArray,
} from '@standardnotes/snjs';
import { PANEL_NAME_NOTES, PANEL_NAME_TAGS } from '@/views/constants';
import { STRING_DEFAULT_FILE_ERROR } from '@/strings';
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
import { alertDialog } from '@/services/alertService';

class ApplicationViewCtrl extends PureViewCtrl<unknown, {
ready?: boolean,
needsUnlock?: boolean,
appClass: string,
}> {
class ApplicationViewCtrl extends PureViewCtrl<
unknown,
{
started?: boolean;
launched?: boolean;
needsUnlock?: boolean;
appClass: string;
}
> {
public platformString: string;
private notesCollapsed = false;
private tagsCollapsed = false;
Expand Down Expand Up @@ -76,7 +79,7 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
this.$timeout(() => {
this.challenges.push(challenge);
});
}
},
});
await this.application.launch();
}
Expand All @@ -90,14 +93,17 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
async onAppStart() {
super.onAppStart();
this.setState({
ready: true,
needsUnlock: this.application.hasPasscode()
started: true,
needsUnlock: this.application.hasPasscode(),
});
}

async onAppLaunch() {
super.onAppLaunch();
this.setState({ needsUnlock: false });
this.setState({
launched: true,
needsUnlock: false,
});
this.handleDemoSignInFromParams();
}

Expand All @@ -111,12 +117,12 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
switch (eventName) {
case ApplicationEvent.LocalDatabaseReadError:
alertDialog({
text: 'Unable to load local database. Please restart the app and try again.'
text: 'Unable to load local database. Please restart the app and try again.',
});
break;
case ApplicationEvent.LocalDatabaseWriteError:
alertDialog({
text: 'Unable to write to local database. Please restart the app and try again.'
text: 'Unable to write to local database. Please restart the app and try again.',
});
break;
}
Expand All @@ -132,9 +138,13 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
if (panel === PANEL_NAME_TAGS) {
this.tagsCollapsed = collapsed;
}
let appClass = "";
if (this.notesCollapsed) { appClass += "collapsed-notes"; }
if (this.tagsCollapsed) { appClass += " collapsed-tags"; }
let appClass = '';
if (this.notesCollapsed) {
appClass += 'collapsed-notes';
}
if (this.tagsCollapsed) {
appClass += ' collapsed-tags';
}
this.setState({ appClass });
} else if (eventName === AppStateEvent.WindowDidFocus) {
if (!(await this.application.isLocked())) {
Expand Down Expand Up @@ -163,23 +173,20 @@ class ApplicationViewCtrl extends PureViewCtrl<unknown, {
if (event.dataTransfer?.files.length) {
event.preventDefault();
void alertDialog({
text: STRING_DEFAULT_FILE_ERROR
text: STRING_DEFAULT_FILE_ERROR,
});
}
}

async handleDemoSignInFromParams() {
if (
this.$location.search().demo === 'true' &&
!this.application.hasAccount()
!this.application.hasAccount()
) {
await this.application.setCustomHost(
'https://syncing-server-demo.standardnotes.com'
);
this.application.signIn(
'[email protected]',
'password',
);
this.application.signIn('[email protected]', 'password');
}
}
}
Expand All @@ -193,7 +200,7 @@ export class ApplicationView extends WebDirective {
this.controllerAs = 'self';
this.bindToController = true;
this.scope = {
application: '='
application: '=',
};
}
}