Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

[WIP] Adds edit issue title #2348

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ final class IssueCommentSectionController: ListBindingSectionController<IssueCom

var editAction: UIAlertAction? {
guard object?.viewerCanUpdate == true else { return nil }
return UIAlertAction(title: NSLocalizedString("Edit", comment: ""), style: .default, handler: { [weak self] _ in
return UIAlertAction(title: Constants.Strings.edit, style: .default, handler: { [weak self] _ in
guard let strongSelf = self,
let object = strongSelf.object,
let number = object.number,
Expand Down
2 changes: 1 addition & 1 deletion Classes/Issues/EditComment/EditCommentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ MessageTextViewListener {

func setRightBarItemIdle() {
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: NSLocalizedString("Save", comment: ""),
title: Constants.Strings.save,
style: .done,
target: self,
action: #selector(EditCommentViewController.onSave)
Expand Down
81 changes: 81 additions & 0 deletions Classes/Issues/EditTitle/EditIssueTitleViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// EditIssueTitleViewController.swift
// Freetime
//
// Created by B_Litwin on 10/22/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//

import UIKit
import GitHubAPI
import SnapKit
import Squawk


final class EditIssueTitleViewController: UIViewController {

private let issueTitle: String
private let textView = UITextView()
public private(set) var setTitle: String?

init(issueTitle: String) {
self.issueTitle = issueTitle
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
preferredContentSize = CGSize(
width: Styles.Sizes.contextMenuSize.width,
height: 120
)
title = Constants.Strings.edit

view.addSubview(textView)
textView.snp.makeConstraints { make in
make.edges.equalTo(view)
}
textView.textContainerInset = Styles.Sizes.textViewInset
textView.text = issueTitle

navigationItem.rightBarButtonItem = UIBarButtonItem(
title: Constants.Strings.save,
style: .plain,
target: self,
action: #selector(
EditIssueTitleViewController.onSave
)
)

navigationItem.leftBarButtonItem = UIBarButtonItem(
title: Constants.Strings.cancel,
style: .plain,
target: self,
action: #selector(
EditIssueTitleViewController.onCancel
)
)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
textView.becomeFirstResponder()
}

@objc func onSave() {
textView.resignFirstResponder()
if textView.text != issueTitle {
setTitle = textView.text
}
dismiss(animated: true)
}

@objc func onCancel() {
textView.resignFirstResponder()
dismiss(animated: true)
}
}
54 changes: 53 additions & 1 deletion Classes/Issues/GithubClient+Issues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension GithubClient {
let issueResult = IssueResult(
id: issueType.id,
pullRequest: issueType.pullRequest,
title: titleStringSizing(title: issueType.title, contentSizeCategory: contentSizeCategory, width: width),
title: titleStringSizing(title: issueType.title, contentSizeCategory: contentSizeCategory),
labels: IssueLabelsModel(
status: IssueLabelStatusModel(status: status, pullRequest: issueType.pullRequest),
locked: issueType.locked,
Expand Down Expand Up @@ -525,4 +525,56 @@ extension GithubClient {
}
}
}

func setTitle(
previous: IssueResult,
owner: String,
repo: String,
number: Int,
title: String
) {

let contentSizeCategory = UIContentSizeCategory.preferred

let titleChangeString = IssueRenamedString(
previous: previous.title.string.allText,
current: title,
contentSizeCategory: contentSizeCategory,
width: 0
)

let issueRenamedModel = IssueRenamedModel(
id: UUID().uuidString,
actor: userSession?.username ?? "",
date: Date(),
titleChangeString: titleChangeString
)

let issueResult = previous.updated(
title: titleStringSizing(
title: title,
contentSizeCategory: contentSizeCategory
),
timelinePages: previous.timelinePages(appending: [issueRenamedModel])
)

let cache = self.cache
cache.set(value: issueResult)

let request = V3SetIssueTitleRequest(
owner: owner,
repo: repo,
issueNumber: number,
title: title
)

client.send(request) { result in
switch result {
case .success: break
case .failure(let error):
cache.set(value: previous)
Squawk.show(error: error)
}
}
}
}
39 changes: 36 additions & 3 deletions Classes/Issues/IssueManagingContextController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
case lock
case reopen
case close
case editTitle
}

var actions: [Action] {
Expand All @@ -91,6 +92,8 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
if result.pullRequest {
actions.append(.reviewers)
}
actions += [.editTitle]

if result.labels.locked {
actions.append(.unlock)
} else {
Expand Down Expand Up @@ -138,6 +141,9 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
case .close:
title = Constants.Strings.close
iconName = "x"
case .editTitle:
title = NSLocalizedString("Edit Title", comment: "")
iconName = "pencil"
}

// Lock always has the divider above it assuming you're a collaborator.
Expand Down Expand Up @@ -176,6 +182,11 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
case .milestone: strongSelf.presentContextMenu(with: strongSelf.newMilestonesController())
case .assignees: strongSelf.presentContextMenu(with: strongSelf.newPeopleController(type: .assignee))
case .reviewers: strongSelf.presentContextMenu(with: strongSelf.newPeopleController(type: .reviewer))
case .editTitle:
strongSelf.presentContextMenu(
with: strongSelf.newEditTitleController(),
backgroundColor: .white
)
case .unlock: strongSelf.lock(false)
case .lock: strongSelf.lock(true)
case .reopen: strongSelf.close(false)
Expand Down Expand Up @@ -204,6 +215,12 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
sourceView: sender
)
}

func newEditTitleController() -> UIViewController {
return EditIssueTitleViewController(
issueTitle: result?.title.string.allText ?? ""
)
}

func newLabelsController() -> UIViewController {
return LabelsViewController(
Expand Down Expand Up @@ -251,14 +268,17 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
)
}

func presentContextMenu(with controller: UIViewController) {
func presentContextMenu(
with controller: UIViewController,
backgroundColor: UIColor = Styles.Colors.menuBackgroundColor.color
) {
guard let viewController = self.viewController else { return }
ContextMenu.shared.show(
sourceViewController: viewController,
viewController: controller,
options: ContextMenu.Options(
containerStyle: ContextMenu.ContainerStyle(
backgroundColor: Styles.Colors.menuBackgroundColor.color
backgroundColor: backgroundColor
)
),
delegate: self
Expand Down Expand Up @@ -288,6 +308,18 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
)
Haptic.triggerNotification(.success)
}

func didDismiss(controller: EditIssueTitleViewController) {
guard let title = controller.setTitle,
let previous = result else { return }
client.setTitle(
previous: previous,
owner: model.owner,
repo: model.repo,
number: model.number,
title: title
)
}

func didDismiss(selected labels: [RepositoryLabel]) {
guard let previous = result else { return }
Expand Down Expand Up @@ -339,9 +371,10 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
didDismiss(controller: people)
} else if let labels = viewController as? LabelsViewController {
didDismiss(selected: labels.selected)
} else if let editIssueTitle = viewController as? EditIssueTitleViewController {
didDismiss(controller: editIssueTitle)
}
}

func contextMenuDidDismiss(viewController: UIViewController, animated: Bool) {}

}
3 changes: 1 addition & 2 deletions Classes/Issues/IssueViewModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import StyledTextKit

func titleStringSizing(
title: String,
contentSizeCategory: UIContentSizeCategory,
width: CGFloat
contentSizeCategory: UIContentSizeCategory
) -> StyledTextRenderer {
let builder = StyledTextBuilder(styledText: StyledText(
text: title, style: Styles.Text.headline.with(foreground: Styles.Colors.Gray.dark.color)
Expand Down
1 change: 0 additions & 1 deletion Classes/Systems/GithubClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ struct GithubClient {
self.bookmarksStore = nil
}
}

}
2 changes: 2 additions & 0 deletions Classes/Views/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ enum Constants {
static let reviewers = NSLocalizedString("Reviewers", comment: "")
static let reviewGitHubAccess = NSLocalizedString("Review GitHub Access", comment: "")
static let clear = NSLocalizedString("Clear", comment: "")
static let edit = NSLocalizedString("Edit", comment: "")
static let save = NSLocalizedString("Save", comment: "")
}
}
12 changes: 12 additions & 0 deletions Freetime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@
BDB6AA6A215FBC35009BB73C /* RepositoryBranchesCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB6AA63215FBC35009BB73C /* RepositoryBranchesCell.swift */; };
BDB6AA6B215FBC35009BB73C /* GitHubClient+RepositoryBranches.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB6AA64215FBC35009BB73C /* GitHubClient+RepositoryBranches.swift */; };
BDB6AA762165B8EA009BB73C /* SwitchBranches.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDB6AA752165B8EA009BB73C /* SwitchBranches.swift */; };
BDDC37EE217E1829006F69CA /* EditIssueTitleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDDC37ED217E1829006F69CA /* EditIssueTitleViewController.swift */; };
D8BAD0601FDA0A1A00C41071 /* LabelListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BAD05F1FDA0A1A00C41071 /* LabelListCell.swift */; };
D8BAD0641FDF221900C41071 /* LabelListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BAD0631FDF221900C41071 /* LabelListView.swift */; };
D8BAD0661FDF224600C41071 /* WrappingStaticSpacingFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8BAD0651FDF224600C41071 /* WrappingStaticSpacingFlowLayout.swift */; };
Expand Down Expand Up @@ -1025,6 +1026,7 @@
BDB6AA63215FBC35009BB73C /* RepositoryBranchesCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryBranchesCell.swift; sourceTree = "<group>"; };
BDB6AA64215FBC35009BB73C /* GitHubClient+RepositoryBranches.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "GitHubClient+RepositoryBranches.swift"; sourceTree = "<group>"; };
BDB6AA752165B8EA009BB73C /* SwitchBranches.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchBranches.swift; sourceTree = "<group>"; };
BDDC37ED217E1829006F69CA /* EditIssueTitleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditIssueTitleViewController.swift; sourceTree = "<group>"; };
D396E0DA66FED629384A84BC /* Pods_FreetimeWatch.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FreetimeWatch.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D8BAD05F1FDA0A1A00C41071 /* LabelListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelListCell.swift; sourceTree = "<group>"; };
D8BAD0631FDF221900C41071 /* LabelListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LabelListView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1238,6 +1240,7 @@
292FCAC81EDFCC510026635E /* Comments */,
293A45A01F29953800DD1006 /* Commit */,
292CD3B91F0AF26900D3D57B /* DiffHunk */,
BDDC37EC217E180E006F69CA /* EditTitle */,
29AF1E801F8AAB1D0008A0EF /* EditComment */,
291929431F3EAAAF0012067B /* Files */,
29EE44451F19D5C100B05ED3 /* GithubClient+Issues.swift */,
Expand Down Expand Up @@ -2188,6 +2191,14 @@
path = RepositoryBranches;
sourceTree = "<group>";
};
BDDC37EC217E180E006F69CA /* EditTitle */ = {
isa = PBXGroup;
children = (
BDDC37ED217E1829006F69CA /* EditIssueTitleViewController.swift */,
);
path = EditTitle;
sourceTree = "<group>";
};
CF4CC0BFE456879DD6DBC714 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3080,6 +3091,7 @@
D8BAD0641FDF221900C41071 /* LabelListView.swift in Sources */,
2924C18820D5B2F200FCFCFF /* PeopleSectionController.swift in Sources */,
292ACE181F5C945B00C9A02C /* RepositoryIssueSummaryModel.swift in Sources */,
BDDC37EE217E1829006F69CA /* EditIssueTitleViewController.swift in Sources */,
DCA5ED1B1FAEF78B0072F074 /* BookmarkSectionController.swift in Sources */,
29A1053F216D9062004734A0 /* UNNotificationContent+Routable.swift in Sources */,
29693EE520FAA05F00336200 /* IssueAutocomplete.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "GITHUB_CLIENT_ID"
value = "6b1cd65359f9aab074aa"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "GITHUB_CLIENT_SECRET"
value = "b7c871145720014dc39e2a08ed68e8063fdcfb15"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "NETWORK_RECORD_PATH"
value = "$(PROJECT_DIR)"
Expand Down
25 changes: 25 additions & 0 deletions Local Pods/GitHubAPI/GitHubAPI/V3AssigneesRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@

import Foundation


public struct V3SetIssueTitleRequest: V3Request {
public typealias ResponseType = V3StatusCodeResponse<V3StatusCode200>

public var pathComponents: [String] {
return ["repos", owner, repo, "issues", "\(issueNumber)"]
}

public var method: HTTPMethod { return .patch }
public var parameters: [String : Any]? { return ["title": title] }

public let owner: String
public let repo: String
public let issueNumber: Int
public let title: String

public init(owner: String, repo: String, issueNumber: Int, title: String) {
self.owner = owner
self.repo = repo
self.issueNumber = issueNumber
self.title = title
}
}


public struct V3AssigneesRequest: V3Request {
public typealias ResponseType = V3DataResponse<[V3User]>
public var pathComponents: [String] {
Expand Down
8 changes: 8 additions & 0 deletions Local Pods/GitHubAPI/V3EditIssuetitleRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// V3EditIssuetitleRequest.swift
// Pods-Freetime
//
// Created by B_Litwin on 10/27/18.
//

import UIKit
Loading