mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(): add missing pages, make user-data return promises
This commit is contained in:
@@ -8,17 +8,41 @@
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
|
||||
<ion-list>
|
||||
<ion-list-header>
|
||||
Navigate
|
||||
</ion-list-header>
|
||||
<ion-item (click)="openPage(p)" *ngFor="let p of appPages">
|
||||
<ion-item menuToggle (click)="openPage(p)" *ngFor="let p of appPages">
|
||||
<ion-icon slot="start" [name]="p.icon" [color]="isActive(p)"></ion-icon>
|
||||
<ion-label>
|
||||
{{p.title}}
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
|
||||
<ion-list>
|
||||
<ion-list-header>
|
||||
Account
|
||||
</ion-list-header>
|
||||
<ion-item menuToggle *ngFor="let p of loggedOutPages" (click)="openPage(p)">
|
||||
<ion-icon slot="start" [name]="p.icon" [color]="isActive(p)"></ion-icon>
|
||||
<ion-label>
|
||||
{{p.title}}
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
|
||||
<ion-list>
|
||||
<ion-list-header>
|
||||
Tutorial
|
||||
</ion-list-header>
|
||||
<ion-item menuToggle (click)="openTutorial()">
|
||||
<ion-icon slot="start" name="hammer"></ion-icon>
|
||||
<ion-label>Show Tutorial</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
|
||||
</ion-content>
|
||||
</ion-menu>
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ export class AppComponent implements OnInit {
|
||||
// Check if the user has already seen the tutorial
|
||||
this.storage.get('hasSeenTutorial')
|
||||
.then((hasSeenTutorial) => {
|
||||
console.log('hasSeenTutorial: ', hasSeenTutorial);
|
||||
if (hasSeenTutorial) {
|
||||
this.rootPage = TabsPage;
|
||||
} else {
|
||||
@@ -96,7 +95,7 @@ export class AppComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
openPage(page: PageInterface) {
|
||||
openPage(page: PageInterface): Promise<any> {
|
||||
let params = {};
|
||||
|
||||
// the nav component was found using @ViewChild(Nav)
|
||||
@@ -106,25 +105,30 @@ export class AppComponent implements OnInit {
|
||||
params = { tabIndex: page.index };
|
||||
}
|
||||
|
||||
// If we are already on tabs just change the selected tab
|
||||
// don't setRoot again, this maintains the history stack of the
|
||||
// tabs even if changing them from the menu
|
||||
/*if (getNav(this.navRef).getChildNavs().length && page.index !== undefined) {
|
||||
getNav(this.navRef).getChildNavs()[0].select(page.index);
|
||||
} else {
|
||||
// Set the root of the nav with params if it's a tab index
|
||||
getNav(this.navRef).setRoot(page.name, params).catch((err: any) => {
|
||||
console.log(`Didn't set nav root: ${err}`);
|
||||
});
|
||||
// check if it's in the appPAges
|
||||
for (const appPage of this.appPages) {
|
||||
if (page === appPage) {
|
||||
// sweet, select the tab
|
||||
const tabs = document.querySelector('ion-tabs');
|
||||
return (tabs as any).componentOnReady().then(() => {
|
||||
return tabs.select(page.index);
|
||||
}).then(() => {
|
||||
if (page.logsOut === true) {
|
||||
// Give the menu time to close before changing to logged out
|
||||
return this.userData.logout();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
*/
|
||||
console.log('TODO DANNNNNNN');
|
||||
|
||||
|
||||
if (page.logsOut === true) {
|
||||
// Give the menu time to close before changing to logged out
|
||||
this.userData.logout();
|
||||
}
|
||||
return getNav(this.navRef).then(() => {
|
||||
return nav.setRoot(page.component, params);
|
||||
}).then(() => {
|
||||
if (page.logsOut === true) {
|
||||
// Give the menu time to close before changing to logged out
|
||||
return this.userData.logout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openTutorial() {
|
||||
|
||||
@@ -30,26 +30,30 @@ export class UserData {
|
||||
}
|
||||
}
|
||||
|
||||
login(username: string): void {
|
||||
this.storage.set(this.HAS_LOGGED_IN, true);
|
||||
this.setUsername(username);
|
||||
this.events.publish('user:login');
|
||||
login(username: string): Promise<any> {
|
||||
return this.storage.set(this.HAS_LOGGED_IN, true).then(() => {
|
||||
this.setUsername(username);
|
||||
return this.events.publish('user:login');
|
||||
});
|
||||
}
|
||||
|
||||
signup(username: string): void {
|
||||
this.storage.set(this.HAS_LOGGED_IN, true);
|
||||
this.setUsername(username);
|
||||
this.events.publish('user:signup');
|
||||
signup(username: string): Promise<any> {
|
||||
return this.storage.set(this.HAS_LOGGED_IN, true).then(() => {
|
||||
this.setUsername(username);
|
||||
return this.events.publish('user:signup');
|
||||
});
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.storage.remove(this.HAS_LOGGED_IN);
|
||||
this.storage.remove('username');
|
||||
this.events.publish('user:logout');
|
||||
logout(): Promise<any> {
|
||||
return this.storage.remove(this.HAS_LOGGED_IN).then(() => {
|
||||
return this.storage.remove('username');
|
||||
}).then(() => {
|
||||
this.events.publish('user:logout');
|
||||
});
|
||||
}
|
||||
|
||||
setUsername(username: string): void {
|
||||
this.storage.set('username', username);
|
||||
setUsername(username: string): Promise<any> {
|
||||
return this.storage.set('username', username);
|
||||
}
|
||||
|
||||
getUsername(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user