diff --git a/src/components/page-session/page-session.tsx b/src/components/page-session/page-session.tsx index 1bdb875..73e3b06 100644 --- a/src/components/page-session/page-session.tsx +++ b/src/components/page-session/page-session.tsx @@ -9,6 +9,7 @@ import { UserData } from '../../providers/user-data'; export class PageSession { private session: any; + @State() isWatched: boolean; @State() isFavorite: boolean; @Prop() sessionId: string; @Prop() goback = '/'; @@ -16,10 +17,7 @@ export class PageSession { async componentWillLoad() { this.session = await ConferenceData.getSession(this.sessionId); this.isFavorite = UserData.hasFavorite(this.session.name); - } - - sessionClick(item: string) { - console.log('Clicked', item); + this.isWatched = UserData.hasWatch(this.session.name); } toggleFavorite() { @@ -32,6 +30,20 @@ export class PageSession { } } + toggleWatch() { + if (UserData.hasWatch(this.session.name)) { + UserData.removeWatch(this.session.name); + this.isWatched = false; + } else { + UserData.addWatch(this.session.name); + this.isWatched = true; + } + } + + sessionClick(item: string) { + console.log('Clicked', item); + } + render() { return [ @@ -71,15 +83,20 @@ export class PageSession { - this.sessionClick('watch')}> - Watch - + { + this.isWatched ? + this.toggleWatch()}> + Mark as Unwatched + + : + this.toggleWatch()}> + Watch + + } + this.sessionClick('add to calendar')}> Add to Calendar - this.sessionClick('mark as unwatched')}> - Mark as Unwatched - this.sessionClick('download video')}> Download Video diff --git a/src/providers/user-data.ts b/src/providers/user-data.ts index ed3e660..f847428 100644 --- a/src/providers/user-data.ts +++ b/src/providers/user-data.ts @@ -5,6 +5,7 @@ const HAS_SEEN_TUTORIAL = 'hasSeenTutorial'; export class UserDataController { private favorites: string[] = []; + private watches: string[] = []; hasFavorite(sessionName: string): boolean { return (this.favorites.indexOf(sessionName) > -1); @@ -21,6 +22,21 @@ export class UserDataController { } } + hasWatch(sessionName: string): boolean { + return (this.watches.indexOf(sessionName) > -1); + } + + addWatch(sessionName: string): void { + this.watches.push(sessionName); + } + + removeWatch(sessionName: string): void { + const index = this.watches.indexOf(sessionName); + if (index > -1) { + this.watches.splice(index, 1); + } + } + login(username: string): Promise { return set(HAS_LOGGED_IN, true).then(() => { this.setUsername(username);