-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPostPageVC+Actions.swift
90 lines (80 loc) · 3.03 KB
/
PostPageVC+Actions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// PostPageVC+Actions.swift
// Commun
//
// Created by Chung Tran on 4/17/20.
// Copyright © 2020 Commun Limited. All rights reserved.
//
import Foundation
extension PostPageVC: PostHeaderViewDelegate, PostStatsViewDelegate {
// MARK: - Actions
@objc func openMorePostActions() {
guard let post = post else {return}
showPostMenu(post: post)
}
@objc func sortButtonDidTouch() {
showCMActionSheet(
title: "sort by".localized().uppercaseFirst,
actions: [
.default(
title: "interesting first".localized().uppercaseFirst,
showIcon: false,
handle: {
let vm = self.viewModel as! CommentsViewModel
vm.changeFilter(sortBy: .popularity)
}),
.default(
title: "newest first".localized().uppercaseFirst,
showIcon: false,
handle: {
let vm = self.viewModel as! CommentsViewModel
vm.changeFilter(sortBy: .timeDesc)
}),
.default(
title: "oldest first".localized().uppercaseFirst,
showIcon: false,
handle: {
let vm = self.viewModel as! CommentsViewModel
vm.changeFilter(sortBy: .time)
})
])
}
@objc func headerViewUpVoteButtonDidTouch(_ headerView: PostHeaderView) {
guard let post = post else {return}
post.upVote()
.subscribe(onError: { (error) in
self.showError(error)
})
.disposed(by: self.disposeBag)
}
@objc func headerViewDownVoteButtonDidTouch(_ headerView: PostHeaderView) {
guard let post = post else {return}
post.downVote()
.subscribe(onError: { (error) in
self.showError(error)
})
.disposed(by: self.disposeBag)
}
func headerViewShareButtonDidTouch(_ headerView: PostHeaderView) {
guard let post = post else {return}
ShareHelper.share(post: post)
}
func headerViewCommentButtonDidTouch(_ headerView: PostHeaderView) {
tableView.safeScrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
}
func headerViewDonationButtonDidTouch(_ headerView: PostHeaderView, amount: Double?) {
guard let symbol = post?.community?.communityId,
let post = post,
let user = post.author
else {return}
let donateVC = CMDonateVC(selectedBalanceSymbol: symbol, receiver: user, message: post, amount: amount)
show(donateVC, sender: nil)
}
func headerViewDonationViewCloseButtonDidTouch(_ donationView: CMMessageView) {
var post = self.post
if donationView is DonationView {
post?.showDonationButtons = false
post?.notifyChanged()
}
}
}