From ee1b2163898e69062a98bff4b5a367c728d53b2d Mon Sep 17 00:00:00 2001 From: kj1352 Date: Sat, 17 Apr 2021 22:24:03 +0530 Subject: [PATCH] Bookmarks page + API connections --- src/app/app-routing.module.ts | 4 + src/app/bookmarks/bookmarks-routing.module.ts | 17 ++++ src/app/bookmarks/bookmarks.module.ts | 20 +++++ src/app/bookmarks/bookmarks.page.html | 21 +++++ src/app/bookmarks/bookmarks.page.scss | 15 ++++ src/app/bookmarks/bookmarks.page.spec.ts | 24 +++++ src/app/bookmarks/bookmarks.page.ts | 90 +++++++++++++++++++ src/app/fan-zone/fan-zone.page.html | 8 ++ src/app/services/user.service.ts | 22 +++-- 9 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 src/app/bookmarks/bookmarks-routing.module.ts create mode 100644 src/app/bookmarks/bookmarks.module.ts create mode 100644 src/app/bookmarks/bookmarks.page.html create mode 100644 src/app/bookmarks/bookmarks.page.scss create mode 100644 src/app/bookmarks/bookmarks.page.spec.ts create mode 100644 src/app/bookmarks/bookmarks.page.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 363d6d3..1528932 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -65,6 +65,10 @@ const routes: Routes = [ path: 'league-table', loadChildren: () => import('./league-table/league-table.module').then( m => m.LeagueTablePageModule) }, + { + path: 'bookmarks', + loadChildren: () => import('./bookmarks/bookmarks.module').then( m => m.BookmarksPageModule) + }, ]; @NgModule({ diff --git a/src/app/bookmarks/bookmarks-routing.module.ts b/src/app/bookmarks/bookmarks-routing.module.ts new file mode 100644 index 0000000..df58abc --- /dev/null +++ b/src/app/bookmarks/bookmarks-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { BookmarksPage } from './bookmarks.page'; + +const routes: Routes = [ + { + path: '', + component: BookmarksPage + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class BookmarksPageRoutingModule {} diff --git a/src/app/bookmarks/bookmarks.module.ts b/src/app/bookmarks/bookmarks.module.ts new file mode 100644 index 0000000..0e567dc --- /dev/null +++ b/src/app/bookmarks/bookmarks.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; + +import { IonicModule } from '@ionic/angular'; + +import { BookmarksPageRoutingModule } from './bookmarks-routing.module'; + +import { BookmarksPage } from './bookmarks.page'; + +@NgModule({ + imports: [ + CommonModule, + FormsModule, + IonicModule, + BookmarksPageRoutingModule + ], + declarations: [BookmarksPage] +}) +export class BookmarksPageModule {} diff --git a/src/app/bookmarks/bookmarks.page.html b/src/app/bookmarks/bookmarks.page.html new file mode 100644 index 0000000..46bcb04 --- /dev/null +++ b/src/app/bookmarks/bookmarks.page.html @@ -0,0 +1,21 @@ + +
+ +
Bookmarks({{ this.bookmarked_articles.length }})
All your bookmarked posts in one place
+
+ + + + + + + +

{{ news.title }}

+
+
+
+ +
diff --git a/src/app/bookmarks/bookmarks.page.scss b/src/app/bookmarks/bookmarks.page.scss new file mode 100644 index 0000000..d282de7 --- /dev/null +++ b/src/app/bookmarks/bookmarks.page.scss @@ -0,0 +1,15 @@ +@import '../colors'; + +ion-list { + ion-item { + --padding-top: 10px; + --padding-bottom: 10px; + } + + h3 { + font-size: 1rem; + white-space: normal; + line-height: 1.5; + color: darken($blue-grey, 10%); + } +} \ No newline at end of file diff --git a/src/app/bookmarks/bookmarks.page.spec.ts b/src/app/bookmarks/bookmarks.page.spec.ts new file mode 100644 index 0000000..d3dc550 --- /dev/null +++ b/src/app/bookmarks/bookmarks.page.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IonicModule } from '@ionic/angular'; + +import { BookmarksPage } from './bookmarks.page'; + +describe('BookmarksPage', () => { + let component: BookmarksPage; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BookmarksPage ], + imports: [IonicModule.forRoot()] + }).compileComponents(); + + fixture = TestBed.createComponent(BookmarksPage); + component = fixture.componentInstance; + fixture.detectChanges(); + })); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/bookmarks/bookmarks.page.ts b/src/app/bookmarks/bookmarks.page.ts new file mode 100644 index 0000000..4ab4800 --- /dev/null +++ b/src/app/bookmarks/bookmarks.page.ts @@ -0,0 +1,90 @@ +import { Component, OnInit } from '@angular/core'; +import { Location } from '@angular/common'; +import { UserService } from '../services/user.service'; +import { NewsService, IMAGE_BASE_URL } from '../services/news.service'; +import { Platform } from '@ionic/angular'; +import { Router } from '@angular/router'; + +@Component({ + selector: 'app-bookmarks', + templateUrl: './bookmarks.page.html', + styleUrls: ['./bookmarks.page.scss'], +}) +export class BookmarksPage implements OnInit { + bookmarked_articles: Array<{ + title: string, + alias: string, + image: string, + type: string, + }> = []; + + image_url = IMAGE_BASE_URL; + + constructor( + private location: Location, + private userService: UserService, + private newsService: NewsService, + private router: Router, + private platform: Platform, + ) { } + + back() { + this.location.back(); + } + + getType(type: string) { + let returnType: string = ''; + + console.log(type); + + switch(type) { + case 'Photos': returnType = 'gallery'; break; + case 'Videos': returnType = 'videos'; break; + case 'News': returnType = 'news'; break; + } + + return returnType; + } + + showNewsDetails(alias_title: string, type: string) { + this.router.navigate(['/home-details', { alias_title: alias_title, type: type }]); + } + + ngOnInit() { + this.userService.getUserProfile().then((data: any) => { + let bookmarked_articles: Array = data.bookmarked_articles; + this.bookmarked_articles = []; + + for (let i = 0; i < bookmarked_articles.length; i += 1) { + + this.newsService.getArticleDetails(bookmarked_articles[i]).then((info: any) => { + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.bookmarked_articles.push({ + title: JSON.parse(info.data)['content'].data.short_title ? JSON.parse(info.data)['content'].data.short_title : JSON.parse(info.data)['content'].data.asset_title, + alias: bookmarked_articles[i], + image: this.image_url + JSON.parse(info.data)['content'].data.image_path + JSON.parse(info.data)['content'].data.image_file_name, + type: this.getType(JSON.parse(info.data)['EntityData'].entities[0].ent_display_name) + }); + + } else { + this.bookmarked_articles.push({ + title: info.content.data.short_title ? info.content.data.short_title : info.content.data.asset_title, + alias: bookmarked_articles[i], + image: this.image_url + info.content.data.image_path + info.content.data.image_file_name, + type: this.getType(info.EntityData.entities[0].ent_display_name) + }); + } + + + }, (e) => { + // alert(JSON.stringify(e)); + }); + } + + }, () => { + this.bookmarked_articles = []; + }); + } + +} diff --git a/src/app/fan-zone/fan-zone.page.html b/src/app/fan-zone/fan-zone.page.html index e2c07e2..eb4ed08 100644 --- a/src/app/fan-zone/fan-zone.page.html +++ b/src/app/fan-zone/fan-zone.page.html @@ -41,6 +41,14 @@ +
  • +
    + + + +
    +
  • +