Add issue comment editing

This commit is contained in:
Georg Bauer
2026-07-31 15:17:09 +02:00
parent 33f9eb809c
commit da0a3aecb4
10 changed files with 451 additions and 12 deletions

View File

@@ -146,15 +146,41 @@ final class IssueViewController: MarkdownPageViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(
let addComment = UIBarButtonItem(
image: context.symbol("plus.bubble"),
style: .plain,
target: self,
action: #selector(addComment)
)
addComment.accessibilityLabel = "Add comment"
let editIssue = UIBarButtonItem(
title: "Edit",
style: .plain,
target: self,
action: #selector(editIssue)
)
navigationItem.rightBarButtonItems = [addComment, editIssue]
loadContent(refreshing: false)
}
@objc private func addComment() { presentCommentEditor() }
private func editComment(_ comment: CommentRow) { presentCommentEditor(comment) }
private func presentCommentEditor(_ comment: CommentRow? = nil) {
let editor = CommentEditorViewController(
context: context,
owner: owner,
repository: repository,
number: number,
comment: comment
) { [weak self] in
guard let self else { return }
self.dismiss(animated: true) { self.loadContent(refreshing: false) }
}
present(UINavigationController(rootViewController: editor), animated: true)
}
@objc private func editIssue() {
let editor = IssueEditorViewController(
context: context,
@@ -204,6 +230,7 @@ final class IssueViewController: MarkdownPageViewController {
meta: page.meta,
body: page.body,
comments: page.comments,
editComment: { [weak self] comment in self?.editComment(comment) },
milestone: page.milestone
))
finishPagination(hasMore: page.hasMore)
@@ -791,6 +818,7 @@ private func detailViews(
meta: String,
body: String,
comments: [CommentRow],
editComment: ((CommentRow) -> Void)? = nil,
milestone: String = ""
) -> [UIView] {
let titleLabel = UILabel()
@@ -815,7 +843,7 @@ private func detailViews(
milestoneLabel.accessibilityLabel = "Milestone \(milestone)"
views.append(milestoneLabel)
}
return views + [separator(), bodyView] + commentViews(comments)
return views + [separator(), bodyView] + commentViews(comments, editComment: editComment)
}
private func issueTitle(_ titleLabel: UILabel, state: String) -> UIView {
@@ -843,18 +871,37 @@ private func issueTitle(_ titleLabel: UILabel, state: String) -> UIView {
return stack
}
private func commentViews(_ comments: [CommentRow]) -> [UIView] {
private func commentViews(
_ comments: [CommentRow],
editComment: ((CommentRow) -> Void)? = nil
) -> [UIView] {
guard !comments.isEmpty else { return [] }
var views: [UIView] = [sectionLabel("Comments")]
for comment in comments {
let author = UILabel()
author.text = comment.author
author.font = .preferredFont(forTextStyle: .headline)
var headerViews: [UIView] = [author, UIView()]
if comment.canEdit, let editComment {
var configuration = UIButton.Configuration.plain()
configuration.title = "Edit"
configuration.image = UIImage(systemName: "pencil")
configuration.imagePadding = 5
configuration.contentInsets = .zero
let button = UIButton(
configuration: configuration,
primaryAction: UIAction { _ in editComment(comment) }
)
button.accessibilityLabel = "Edit comment by \(comment.author)"
headerViews.append(button)
}
let header = UIStackView(arrangedSubviews: headerViews)
header.alignment = .center
let date = UILabel()
date.text = comment.meta
date.font = .preferredFont(forTextStyle: .caption1)
date.textColor = .tertiaryLabel
let stack = UIStackView(arrangedSubviews: [author, markdownView(comment.body), date, separator()])
let stack = UIStackView(arrangedSubviews: [header, markdownView(comment.body), date, separator()])
stack.axis = .vertical
stack.spacing = 6
views.append(stack)