Add pull request milestone features
This commit is contained in:
@@ -426,18 +426,32 @@ final class MilestoneViewController: RefreshingTableViewController {
|
||||
}
|
||||
}
|
||||
|
||||
override func numberOfSections(in tableView: UITableView) -> Int { page == nil ? 0 : 2 }
|
||||
override func numberOfSections(in tableView: UITableView) -> Int { page == nil ? 0 : 3 }
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
section == 0 ? 1 : page?.issues.count ?? 0
|
||||
switch section {
|
||||
case 0: 1
|
||||
case 1: page?.issues.count ?? 0
|
||||
default: page?.pulls.count ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
section == 1 ? "Issues" : nil
|
||||
switch section {
|
||||
case 1: "Issues"
|
||||
case 2: "Pull Requests"
|
||||
default: nil
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
||||
section == 1 && page?.issues.isEmpty == true ? "No issues are assigned to this milestone." : nil
|
||||
if section == 1, page?.issues.isEmpty == true {
|
||||
return "No issues are assigned to this milestone."
|
||||
}
|
||||
if section == 2, page?.pulls.isEmpty == true {
|
||||
return "No pull requests are assigned to this milestone."
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
override func tableView(
|
||||
@@ -453,23 +467,42 @@ final class MilestoneViewController: RefreshingTableViewController {
|
||||
cell.configure(page.milestone, disclosure: false)
|
||||
return cell
|
||||
}
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "issue", for: indexPath) as! IssueCell
|
||||
cell.configure(page.issues[indexPath.row])
|
||||
if indexPath.section == 1 {
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "issue", for: indexPath) as! IssueCell
|
||||
cell.configure(page.issues[indexPath.row])
|
||||
return cell
|
||||
}
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: "pull")
|
||||
?? UITableViewCell(style: .subtitle, reuseIdentifier: "pull")
|
||||
let pull = page.pulls[indexPath.row]
|
||||
configureTextCell(cell, title: pull.title, detail: "\(pull.summary)\n\(pull.meta)")
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
return cell
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
guard indexPath.section == 1, let issue = page?.issues[indexPath.row] else { return }
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
navigationController?.pushViewController(
|
||||
IssueViewController(
|
||||
context: context,
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
number: issue.number
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
if indexPath.section == 1, let issue = page?.issues[indexPath.row] {
|
||||
navigationController?.pushViewController(
|
||||
IssueViewController(
|
||||
context: context,
|
||||
owner: owner,
|
||||
repository: repository,
|
||||
number: issue.number
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
} else if indexPath.section == 2, let pull = page?.pulls[indexPath.row] {
|
||||
navigationController?.pushViewController(
|
||||
PullViewController(
|
||||
context: context,
|
||||
owner: pull.owner,
|
||||
repository: pull.repository,
|
||||
number: pull.number
|
||||
),
|
||||
animated: true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,6 +555,8 @@ final class MilestoneCell: UITableViewCell {
|
||||
final class PullsViewController: RefreshingTableViewController {
|
||||
private let context: AppContext
|
||||
private var rows: [PullRow] = []
|
||||
private var filterOptions: PullFilterOptions?
|
||||
private var filterTask: Task<Void, Never>?
|
||||
|
||||
init(context: AppContext) {
|
||||
self.context = context
|
||||
@@ -532,6 +567,8 @@ final class PullsViewController: RefreshingTableViewController {
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) { fatalError("init(coder:) is not supported") }
|
||||
|
||||
deinit { filterTask?.cancel() }
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(
|
||||
@@ -557,6 +594,11 @@ final class PullsViewController: RefreshingTableViewController {
|
||||
refreshControl?.endRefreshing()
|
||||
return
|
||||
}
|
||||
loadFilterOptions()
|
||||
loadPulls(refreshing: refreshing)
|
||||
}
|
||||
|
||||
private func loadPulls(refreshing: Bool) {
|
||||
beginLoading(refreshing: refreshing)
|
||||
loadingTask?.cancel()
|
||||
loadingTask = Task {
|
||||
@@ -567,7 +609,9 @@ final class PullsViewController: RefreshingTableViewController {
|
||||
tableView.backgroundView = rows.isEmpty
|
||||
? EmptyBackgroundView(
|
||||
title: "No \(status) pull requests",
|
||||
detail: "No pull requests match the selected status."
|
||||
detail: filtersActive
|
||||
? "No pull requests match the selected filters."
|
||||
: "No pull requests match the selected status."
|
||||
)
|
||||
: nil
|
||||
} catch {
|
||||
@@ -577,6 +621,19 @@ final class PullsViewController: RefreshingTableViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private func loadFilterOptions() {
|
||||
filterTask?.cancel()
|
||||
filterTask = Task {
|
||||
do {
|
||||
filterOptions = try await context.core.pullFilters()
|
||||
guard !Task.isCancelled else { return }
|
||||
updateFilterMenu()
|
||||
} catch {
|
||||
if !Task.isCancelled { show(error: error) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
rows.count
|
||||
}
|
||||
@@ -617,22 +674,74 @@ final class PullsViewController: RefreshingTableViewController {
|
||||
|
||||
private func updateFilterMenu() {
|
||||
let current = context.core.settings().pullStatus
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(
|
||||
image: context.symbol("line.3.horizontal.decrease.circle"),
|
||||
menu: UIMenu(children: ["open", "closed"].map { status in
|
||||
let status = UIMenu(
|
||||
title: "Status",
|
||||
image: context.symbol("circle.lefthalf.filled"),
|
||||
options: .singleSelection,
|
||||
children: ["open", "closed"].map { status in
|
||||
UIAction(title: status.capitalized, state: current == status ? .on : .off) {
|
||||
[weak self] _ in
|
||||
guard let self else { return }
|
||||
do {
|
||||
try self.context.core.setPullStatus(status: status)
|
||||
self.updateFilterMenu()
|
||||
self.loadContent(refreshing: false)
|
||||
self.loadPulls(refreshing: false)
|
||||
} catch {
|
||||
self.show(error: error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
let milestone: UIMenuElement = filterOptions.map(milestoneMenu)
|
||||
?? UIAction(title: "Loading milestones…", attributes: .disabled) { _ in }
|
||||
let item = navigationItem.rightBarButtonItem ?? UIBarButtonItem(
|
||||
image: context.symbol("line.3.horizontal.decrease.circle")
|
||||
)
|
||||
item.menu = UIMenu(children: [status, milestone])
|
||||
item.accessibilityLabel = "Filter pull requests"
|
||||
navigationItem.rightBarButtonItem = item
|
||||
updateFilterTint()
|
||||
}
|
||||
|
||||
private func milestoneMenu(_ options: PullFilterOptions) -> UIMenu {
|
||||
let selected = options.selectedMilestone
|
||||
let all = UIAction(title: "All Milestones", state: selected.isEmpty ? .on : .off) {
|
||||
[weak self] _ in self?.selectMilestone("")
|
||||
}
|
||||
let milestones = options.milestones.map { milestone in
|
||||
UIAction(title: milestone, state: selected == milestone ? .on : .off) {
|
||||
[weak self] _ in self?.selectMilestone(milestone)
|
||||
}
|
||||
}
|
||||
return UIMenu(
|
||||
title: "Milestone",
|
||||
image: context.symbol("flag"),
|
||||
options: .singleSelection,
|
||||
children: [all] + milestones
|
||||
)
|
||||
}
|
||||
|
||||
private func selectMilestone(_ milestone: String) {
|
||||
filterTask?.cancel()
|
||||
do {
|
||||
try context.core.setPullFilters(milestone: milestone)
|
||||
filterOptions?.selectedMilestone = milestone
|
||||
updateFilterMenu()
|
||||
loadPulls(refreshing: false)
|
||||
} catch {
|
||||
show(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private var filtersActive: Bool {
|
||||
(try? context.core.pullFiltersActive()) ?? false
|
||||
}
|
||||
|
||||
private func updateFilterTint() {
|
||||
navigationItem.rightBarButtonItem?.tintColor = filtersActive ? .tintColor : .secondaryLabel
|
||||
navigationItem.rightBarButtonItem?.accessibilityValue = filtersActive
|
||||
? "Filters active"
|
||||
: "Default filters"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user