diff --git a/platforms/android/app/src/main/AndroidManifest.xml b/platforms/android/app/src/main/AndroidManifest.xml index 25bb6c0..8db69e3 100644 --- a/platforms/android/app/src/main/AndroidManifest.xml +++ b/platforms/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/platforms/android/app/src/main/res/xml/config.xml b/platforms/android/app/src/main/res/xml/config.xml index 5837c2d..d64f5c2 100644 --- a/platforms/android/app/src/main/res/xml/config.xml +++ b/platforms/android/app/src/main/res/xml/config.xml @@ -1,5 +1,5 @@ - + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 9fdb65d..4727fdc 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -11,6 +11,7 @@ import { ThreadPage } from '../pages/thread/thread'; import { SettingsPage } from '../pages/settings/settings'; import { AboutPage } from '../pages/about/about'; import { ProfilePage } from '../pages/profile/profile'; +import { PostComponent } from '../components/post/post'; import { SplashScreen } from '@ionic-native/splash-screen'; import { IonicStorageModule } from '@ionic/storage'; @@ -33,7 +34,8 @@ import { ParserPipe } from '../pipes/parser/parser'; TimeagoPipe, NewPostModal, PostMenu, - ParserPipe + ParserPipe, + PostComponent ], imports: [ BrowserModule, diff --git a/src/components/post/post.html b/src/components/post/post.html index 52f01e1..fc5c860 100644 --- a/src/components/post/post.html +++ b/src/components/post/post.html @@ -53,12 +53,12 @@ - - diff --git a/src/components/post/post.ts b/src/components/post/post.ts index 0314501..1206cf5 100644 --- a/src/components/post/post.ts +++ b/src/components/post/post.ts @@ -1,4 +1,12 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; +import { NavController, NavParams, ModalController, ToastController, PopoverController } from 'ionic-angular'; +import { ProfilePage } from '../../pages/profile/profile'; +import { ThreadPage } from '../../pages/thread/thread'; +import { LoginPage } from '../../pages/login/login'; +import { NewPostModal } from '../../pages/stream/new-post'; +import { PostMenu } from '../../pages/stream/post-menu'; + +import * as pnut from 'pnut-butter'; /** * Generated class for the PostComponent component. @@ -12,11 +20,101 @@ import { Component } from '@angular/core'; }) export class PostComponent { - text: string; + @Input() public post: Object; + @Input() public hideImg: boolean; + @Input() public ccOnReply: boolean; + @Input() public myUsername: string; - constructor() { - console.log('Hello PostComponent Component'); - this.text = 'Hello World'; + constructor(public navCtrl: NavController, public navParams: NavParams, + public modalCtrl: ModalController, public toastCtrl: ToastController, + public popoverCtrl: PopoverController) {} + + fetchThread(threadid) { + pnut.thread(threadid, {include_deleted: 0, include_raw: 1, count: 140}).then(res => { + if (res.meta.code === 401) { + // this.storage.clear(); + this.navCtrl.setRoot(LoginPage); + } else { + this.navCtrl.push(ThreadPage, {posts: res.data, me: this.myUsername}); + } + }); + } + + showImage(url) { + window.open(url, '_system'); + } + + showProfile(user) { + this.navCtrl.push(ProfilePage, {user: user}); + } + + showReplyPost(postData, repType) { + let newPostModal = this.modalCtrl.create(NewPostModal, { + type: repType, + post: postData, + me: this.myUsername, + cc: this.ccOnReply}); + newPostModal.present(); + } + + repost(postid, reposted) { + if (reposted) { + pnut.deleteRepost(postid).then(res => { + this.updatePost(res.data.id); + this.presentToast("Repost updated."); + }).catch(err => { + console.log(err); + }); + } else { + pnut.repost(postid).then(res => { + this.updatePost(res.data.id); + this.presentToast("Repost updated."); + }).catch(err => { + console.log(err); + }); + } + } + + bookmark(postid, bookmarked) { + if (bookmarked) { + pnut.deleteBookmark(postid).then(res => { + this.updatePost(res.data.id); + this.presentToast("Bookmark updated."); + }).catch(err => { + console.log(err); + }); + } else { + pnut.bookmark(postid).then(res => { + this.updatePost(res.data.id); + this.presentToast("Bookmark updated."); + }).catch(err => { + console.log(err); + }); + } + } + + updatePost(postid) { + pnut.post(postid, {include_raw: 1}).then(res => { + this.post = res.data; + }).catch(err => { + console.log(err); + }); + } + + presentToast(text) { + let toast = this.toastCtrl.create({ + position: 'top', + message: text, + duration: 2000 + }); + toast.present(); + } + + presentPostMenu(myEvent, postData) { + let popover = this.popoverCtrl.create(PostMenu, { + post: postData, + me: this.myUsername}); + popover.present({ev: myEvent}); } } diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html index 3626809..22d5c2a 100644 --- a/src/pages/stream/stream.html +++ b/src/pages/stream/stream.html @@ -24,7 +24,8 @@ - + + diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index 960a620..f585047 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -1,11 +1,8 @@ import { Component, ViewChild, ChangeDetectorRef } from '@angular/core'; -import { NavController, NavParams, ModalController, Content, ToastController, PopoverController } from 'ionic-angular'; -import { ThreadPage } from '../thread/thread'; +import { NavController, NavParams, ModalController, Content } from 'ionic-angular'; import { Storage } from '@ionic/storage'; import { Events } from 'ionic-angular'; import { LoginPage } from '../login/login'; -import { ProfilePage } from '../profile/profile'; -import { PostMenu } from '../stream/post-menu'; import { NewPostModal } from '../stream/new-post'; import * as pnut from 'pnut-butter'; @@ -36,10 +33,9 @@ export class StreamPage { ccOnReply: boolean = false; hideImg: boolean = false; - constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, - private changeDetectorRef: ChangeDetectorRef, public toastCtrl: ToastController, private storage: Storage, - public popoverCtrl: PopoverController, public events: Events) { - // console.log(JSON.stringify(navParams)); + constructor(public navCtrl: NavController, public navParams: NavParams, + public modalCtrl: ModalController, private storage: Storage, + private changeDetectorRef: ChangeDetectorRef, public events: Events) { this.storage.get('cc').then((val) => { this.ccOnReply = val; @@ -212,17 +208,6 @@ export class StreamPage { return pdata; } - fetchThread(threadid) { - pnut.thread(threadid, {include_deleted: 0, include_raw: 1, count: 140}).then(res => { - if (res.meta.code === 401) { - this.storage.clear(); - this.navCtrl.setRoot(LoginPage); - } else { - this.navCtrl.push(ThreadPage, {posts: res.data, me: this.myUsername}); - } - }); - } - fetchMyPosts() { console.log('-- fetching mentions --'); this.fetcher('me', {include_raw: 1, count: 40}).then(res => { @@ -239,97 +224,11 @@ export class StreamPage { }); } - bookmark(postid, bookmarked) { - if (bookmarked) { - pnut.deleteBookmark(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Bookmark updated."); - }).catch(err => { - console.log(err); - }); - } else { - pnut.bookmark(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Bookmark updated."); - }).catch(err => { - console.log(err); - }); - } - } - - repost(postid, reposted) { - if (reposted) { - pnut.deleteRepost(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Repost updated."); - }).catch(err => { - console.log(err); - }); - } else { - pnut.repost(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Repost updated."); - }).catch(err => { - console.log(err); - }); - } - } - - updatePost(postid) { - pnut.post(postid, {include_raw: 1}).then(res => { - for (var i = 0; i < this.posts.length; i++) { - if (this.posts[i]['id'] === postid) { - this.posts[i] = res.data; - break; - } - } - }).catch(err => { - console.log(err); - }); - } - showNewPost() { let newPostModal = this.modalCtrl.create(NewPostModal, {me: this.myUsername}); newPostModal.present(); } - showReplyPost(postData) { - let newPostModal = this.modalCtrl.create(NewPostModal, {type: 'reply', post: postData, me: this.myUsername, cc: this.ccOnReply}); - newPostModal.present(); - } - - showQuotedPost(postData) { - console.log(postData); - let newPostModal = this.modalCtrl.create(NewPostModal, {type: 'quote', post: postData, me: this.myUsername, cc: this.ccOnReply}); - newPostModal.present(); - } - - showImage(url) { - window.open(url, '_system'); - } - - showProfile(user) { - this.navCtrl.push(ProfilePage, {user: user}); - } - - presentToast(text) { - let toast = this.toastCtrl.create({ - position: 'top', - message: text, - duration: 2000 - }); - toast.present(); - } - - presentPostMenu(myEvent, postData) { - let popover = this.popoverCtrl.create(PostMenu, {post: postData, me: this.myUsername}); - popover.present({ev: myEvent}); - } - scrollToTop() { this.content.scrollToTop(); } diff --git a/src/pages/thread/thread.html b/src/pages/thread/thread.html index a16ebe7..6a38ffd 100644 --- a/src/pages/thread/thread.html +++ b/src/pages/thread/thread.html @@ -15,66 +15,11 @@ - - - - - -

{{ post.user.name }}

-

@{{ post.user.username }}

- -
- {{ post.created_at | timeago }}
- {{ post.source.name }} -
-
-
- -
- -
-
-
-
-
-
- -
-
-
- - - - - - - - - - - - - - - - - +
diff --git a/src/pages/thread/thread.ts b/src/pages/thread/thread.ts index 7b24c2b..57bfe1f 100644 --- a/src/pages/thread/thread.ts +++ b/src/pages/thread/thread.ts @@ -1,7 +1,6 @@ import { Component } from '@angular/core'; -import { NavController, NavParams, ModalController, ToastController, PopoverController } from 'ionic-angular'; -import { NewPostModal } from '../stream/new-post'; -import { PostMenu } from '../stream/post-menu'; +import { NavController, NavParams } from 'ionic-angular'; +import { Storage } from '@ionic/storage'; import * as pnut from 'pnut-butter'; @@ -20,89 +19,22 @@ export class ThreadPage { title: string; posts: Array = []; myUsername: string; + hideImg: boolean = false; + ccOnReply: boolean = false; - constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, - public popoverCtrl: PopoverController, public toastCtrl: ToastController) { + constructor(public navCtrl: NavController, public navParams: NavParams, + private storage: Storage) { this.posts = this.navParams.data.posts; this.myUsername = this.navParams.data.me; - } - showReplyPost(postData) { - let newPostModal = this.modalCtrl.create(NewPostModal, {type: 'reply', post: postData}); - newPostModal.present(); - } - - showQuotedPost(postData) { - console.log(postData); - let newPostModal = this.modalCtrl.create(NewPostModal, {type: 'quote', post: postData}); - newPostModal.present(); - } - - bookmark(postid, bookmarked) { - if (bookmarked) { - pnut.deleteBookmark(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Bookmark updated."); - }).catch(err => { - console.log(err); - }); - } else { - pnut.bookmark(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Bookmark updated."); - }).catch(err => { - console.log(err); - }); - } - } - - repost(postid, reposted) { - if (reposted) { - pnut.deleteRepost(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Repost updated."); - }).catch(err => { - console.log(err); - }); - } else { - pnut.repost(postid).then(res => { - console.log(res); - this.updatePost(res.data.id); - this.presentToast("Repost updated."); - }).catch(err => { - console.log(err); - }); - } - } - - updatePost(postid) { - pnut.post(postid, {include_raw: 1}).then(res => { - for (var i = 0; i < this.posts.length; i++) { - if (this.posts[i]['id'] === postid) { - this.posts[i] = res.data; - break; - } - } - }).catch(err => { - console.log(err); + this.storage.get('hideimg').then((val) => { + this.hideImg = val; }); - } - presentPostMenu(myEvent, postData) { - let popover = this.popoverCtrl.create(PostMenu, {post: postData, me: this.myUsername}); - popover.present({ev: myEvent}); - } - - presentToast(text) { - let toast = this.toastCtrl.create({ - position: 'top', - message: text, - duration: 2000 + this.storage.get('cc').then((val) => { + this.ccOnReply = val; }); - toast.present(); + } }