diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6aeab2a..8645a8f 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 { ProfileMenu } from '../pages/profile/profile-menu'; import { UserListPage } from '../pages/user-list/user-list'; import { PostComponent } from '../components/post/post'; @@ -36,6 +37,7 @@ import { ParserPipe } from '../pipes/parser/parser'; TimeagoPipe, NewPostModal, PostMenu, + ProfileMenu, ParserPipe, PostComponent ], @@ -55,7 +57,8 @@ import { ParserPipe } from '../pipes/parser/parser'; ProfilePage, UserListPage, NewPostModal, - PostMenu + PostMenu, + ProfileMenu ], providers: [ SplashScreen, diff --git a/src/components/post/post.html b/src/components/post/post.html index fc5c860..01fee5f 100644 --- a/src/components/post/post.html +++ b/src/components/post/post.html @@ -1,6 +1,6 @@ - - + +

{{ post.user.name }}

diff --git a/src/pages/profile/profile-menu.ts b/src/pages/profile/profile-menu.ts new file mode 100644 index 0000000..a8cd5b7 --- /dev/null +++ b/src/pages/profile/profile-menu.ts @@ -0,0 +1,70 @@ +import { Component } from '@angular/core'; +import { ViewController, NavParams, ToastController } from 'ionic-angular'; +import { Events } from 'ionic-angular'; + +import * as pnut from 'pnut-butter'; + +@Component({ + template: ` + + + + + +` +}) +export class ProfileMenu { + + private userid: string; + private username: string; + + constructor(public navParams: NavParams, public viewCtrl: ViewController, + public toastCtrl: ToastController, public events: Events) { + this.userid = this.navParams.data.userid; + this.username = this.navParams.data.username; + } + + browse() { + window.open('https://pnut.io/@' + this.username, '_system'); + this.close(); + } + + mute() { + if (this.user.you_muted) { + pnut.unmute(this.userid).then(res => { + this.presentToast('User unmuted'); + }); + } else { + pnut.mute(this.userid).then(res => { + this.presentToast('User muted'); + }); + } + this.close(); + } + + block() { + if (this.user.you_blocked) { + pnut.unblock(this.userid).then(res => { + this.presentToast('User unblocked'); + }); + } else { + pnut.block(this.userid).then(res => { + this.presentToast('User blocked'); + }); + } + this.close(); + } + + presentToast(text) { + let toast = this.toastCtrl.create({ + position: 'top', + message: text, + duration: 2000 + }); + toast.present(); + } + + close() { + this.viewCtrl.dismiss(); + } +} diff --git a/src/pages/profile/profile.html b/src/pages/profile/profile.html index 0bc9262..b76470a 100644 --- a/src/pages/profile/profile.html +++ b/src/pages/profile/profile.html @@ -8,6 +8,11 @@ {{ user.username }} + + + @@ -24,7 +29,7 @@

{{ user.name }}

@{{ user.username }}

- + {{ user.follows_you ? "Follows you" : ""}}
diff --git a/src/pages/profile/profile.ts b/src/pages/profile/profile.ts index 871461a..e0d4b61 100644 --- a/src/pages/profile/profile.ts +++ b/src/pages/profile/profile.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; -import { NavController, NavParams } from 'ionic-angular'; +import { NavController, NavParams, PopoverController, ToastController } from 'ionic-angular'; import { UserListPage } from '../user-list/user-list'; +import { ProfileMenu } from './profile-menu' import * as pnut from 'pnut-butter'; @@ -25,15 +26,14 @@ export class ProfilePage { private myUsername: string; public activeTab: string = 'posts'; - constructor(public navCtrl: NavController, public navParams: NavParams) { + constructor(public navCtrl: NavController, public navParams: NavParams, + public popoverCtrl: PopoverController, public toastCtrl: ToastController) { this.user = this.navParams.data.user; this.myUsername = this.navParams.data.me; } ionViewDidLoad() { console.log('ionViewDidLoad ProfilePage'); - // console.log(JSON.stringify(this.user)); - // console.log('-----'); let params = { include_deleted: 0, include_raw: 1, @@ -114,4 +114,34 @@ export class ProfilePage { list: list}); } + followUser() { + if (this.user.you_follow) { + pnut.unfollow(this.user.id).then(res => { + this.user = res.data; + this.presentToast('User unfollowed'); + }); + } else { + pnut.follow(this.user.id).then(res => { + this.user = res.data; + this.presentToast('User followed'); + }); + } + } + + presentProfileMenu(myEvent) { + let popover = this.popoverCtrl.create(ProfileMenu, { + userid: this.user.id, + username: this.user.username}); + popover.present({ev: myEvent}); + } + + presentToast(text) { + let toast = this.toastCtrl.create({ + position: 'top', + message: text, + duration: 2000 + }); + toast.present(); + } + } diff --git a/src/pages/user-list/user-list.html b/src/pages/user-list/user-list.html index b967f84..e6d7ef6 100644 --- a/src/pages/user-list/user-list.html +++ b/src/pages/user-list/user-list.html @@ -21,10 +21,10 @@

{{ user.name }}

@{{ user.username }}

- +