2018-02-23 14:36:16 +01:00
|
|
|
import { Component, OnInit } from '@angular/core'
|
2018-12-19 16:04:34 +01:00
|
|
|
import { Notifier } from '@app/core'
|
2019-07-25 10:44:21 +02:00
|
|
|
import { SortMeta } from 'primeng/api'
|
2018-09-11 16:27:07 +02:00
|
|
|
import { ActorFollow } from '../../../../../../shared/models/actors/follow.model'
|
2017-11-20 11:19:23 +01:00
|
|
|
import { ConfirmService } from '../../../core/confirm/confirm.service'
|
2017-11-15 11:00:25 +01:00
|
|
|
import { RestPagination, RestTable } from '../../../shared'
|
2019-06-06 11:39:22 +02:00
|
|
|
import { FollowService } from '@app/shared/instance/follow.service'
|
2018-06-04 16:21:17 +02:00
|
|
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
2017-11-15 10:10:41 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-followers-list',
|
2018-09-11 16:27:07 +02:00
|
|
|
templateUrl: './following-list.component.html',
|
|
|
|
styleUrls: [ './following-list.component.scss' ]
|
2017-11-15 10:10:41 +01:00
|
|
|
})
|
2018-02-23 14:36:16 +01:00
|
|
|
export class FollowingListComponent extends RestTable implements OnInit {
|
2018-09-11 16:27:07 +02:00
|
|
|
following: ActorFollow[] = []
|
2017-11-15 10:10:41 +01:00
|
|
|
totalRecords = 0
|
|
|
|
rowsPerPage = 10
|
|
|
|
sort: SortMeta = { field: 'createdAt', order: 1 }
|
|
|
|
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
|
|
|
|
|
|
|
|
constructor (
|
2018-12-19 16:04:34 +01:00
|
|
|
private notifier: Notifier,
|
2017-11-20 11:19:23 +01:00
|
|
|
private confirmService: ConfirmService,
|
2018-06-04 16:21:17 +02:00
|
|
|
private followService: FollowService,
|
|
|
|
private i18n: I18n
|
2017-11-15 10:10:41 +01:00
|
|
|
) {
|
|
|
|
super()
|
|
|
|
}
|
|
|
|
|
2018-02-23 14:36:16 +01:00
|
|
|
ngOnInit () {
|
2018-10-08 15:51:38 +02:00
|
|
|
this.initialize()
|
2018-02-23 14:36:16 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 10:49:26 +02:00
|
|
|
getIdentifier () {
|
|
|
|
return 'FollowingListComponent'
|
|
|
|
}
|
|
|
|
|
2018-09-11 16:27:07 +02:00
|
|
|
async removeFollowing (follow: ActorFollow) {
|
2018-06-04 16:21:17 +02:00
|
|
|
const res = await this.confirmService.confirm(
|
2018-06-05 09:13:26 +02:00
|
|
|
this.i18n('Do you really want to unfollow {{host}}?', { host: follow.following.host }),
|
2018-06-04 16:21:17 +02:00
|
|
|
this.i18n('Unfollow')
|
|
|
|
)
|
2018-02-22 15:29:32 +01:00
|
|
|
if (res === false) return
|
2017-11-20 11:19:23 +01:00
|
|
|
|
2018-02-22 15:29:32 +01:00
|
|
|
this.followService.unfollow(follow).subscribe(
|
|
|
|
() => {
|
2018-12-19 16:04:34 +01:00
|
|
|
this.notifier.success(this.i18n('You are not following {{host}} anymore.', { host: follow.following.host }))
|
2018-02-22 15:29:32 +01:00
|
|
|
this.loadData()
|
|
|
|
},
|
2017-11-20 11:19:23 +01:00
|
|
|
|
2018-12-19 16:04:34 +01:00
|
|
|
err => this.notifier.error(err.message)
|
2017-11-20 11:19:23 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-11-15 10:10:41 +01:00
|
|
|
protected loadData () {
|
2019-11-28 11:37:32 +01:00
|
|
|
this.followService.getFollowing({ pagination: this.pagination, sort: this.sort, search: this.search })
|
2017-11-15 10:10:41 +01:00
|
|
|
.subscribe(
|
|
|
|
resultList => {
|
|
|
|
this.following = resultList.data
|
|
|
|
this.totalRecords = resultList.total
|
|
|
|
},
|
|
|
|
|
2018-12-19 16:04:34 +01:00
|
|
|
err => this.notifier.error(err.message)
|
2017-11-15 10:10:41 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|