Skip to content

Commit

Permalink
Add Share action to site link context menu on dashboard (#23935)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Jan 2, 2025
2 parents e00fc8b + 6b1e72a commit be2aa0d
Show file tree
Hide file tree
Showing 42 changed files with 112 additions and 174 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [*] Fix an issue with compliance popover not dismissing for self-hosted site [#23932]
* [*] Fix dynamic type support in the compliance popover [#23932]
* [*] Improve transisions and interactive dismiss gestures for sheets [#23933]
* [*] Add "Share" action to site link context menu on dashboard [#23935]

25.6
-----
Expand Down
15 changes: 5 additions & 10 deletions WordPress/Classes/Services/PostCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PostCoordinator: NSObject {
case maximumRetryTimeIntervalReached

var errorDescription: String? {
Strings.genericErrorTitle
SharedStrings.Error.generic
}

var errorUserInfo: [String: Any] {
Expand Down Expand Up @@ -177,20 +177,20 @@ class PostCoordinator: NSObject {
wpAssertionFailure("Failed to show an error alert")
return
}
let alert = UIAlertController(title: Strings.genericErrorTitle, message: error.localizedDescription, preferredStyle: .alert)
let alert = UIAlertController(title: SharedStrings.Error.generic, message: error.localizedDescription, preferredStyle: .alert)
if let error = error as? PostRepository.PostSaveError {
switch error {
case .conflict(let latest):
alert.addDefaultActionWithTitle(Strings.buttonOK) { [weak self] _ in
alert.addDefaultActionWithTitle(SharedStrings.Button.ok) { [weak self] _ in
self?.showResolveConflictView(post: post, remoteRevision: latest, source: .editor)
}
case .deleted:
alert.addDefaultActionWithTitle(Strings.buttonOK) { [weak self] _ in
alert.addDefaultActionWithTitle(SharedStrings.Button.ok) { [weak self] _ in
self?.handlePermanentlyDeleted(post)
}
}
} else {
alert.addDefaultActionWithTitle(Strings.buttonOK, handler: nil)
alert.addDefaultActionWithTitle(SharedStrings.Button.ok, handler: nil)
}
topViewController.present(alert, animated: true)
}
Expand Down Expand Up @@ -945,8 +945,3 @@ private extension NSManagedObjectID {
.trimmingCharacters(in: CharacterSet(charactersIn: "/>"))
}
}

private enum Strings {
static let genericErrorTitle = NSLocalizedString("postNotice.errorTitle", value: "An error occured", comment: "A generic error message title")
static let buttonOK = NSLocalizedString("postNotice.ok", value: "OK", comment: "Button OK")
}
9 changes: 1 addition & 8 deletions WordPress/Classes/Users/Views/UserDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ struct UserDetailsView: View {
value: "There was an error deleting the user.",
comment: "The message in the alert that appears when deleting a user"
)

static let deleteUserErrorAlertOkButton = NSLocalizedString(
"userDetails.alert.deleteUserErrorAlertOkButton",
value: "OK",
comment: "The title of the OK button in the alert that appears when deleting a user"
)

}
}

Expand Down Expand Up @@ -293,7 +286,7 @@ private extension View {
isPresented: view.$presentDeleteUserError,
presenting: view.deleteUserViewModel.error,
actions: { _ in
Button(Strings.deleteUserErrorAlertOkButton) {
Button(SharedStrings.Button.ok) {
view.presentDeleteUserError = false
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private struct SubmitFeedbackView: View {
.listStyle(.plain)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button(Strings.cancel) {
Button(SharedStrings.Button.cancel) {
if isInputEmpty {
dismiss()
} else {
Expand Down Expand Up @@ -87,7 +87,7 @@ private struct SubmitFeedbackView: View {
}
}
.alert(Strings.attachmentsStillUploadingAlertTitle, isPresented: $isShowingAttachmentsUploadingAlert) {
Button(Strings.ok) {}
Button(SharedStrings.Button.ok) {}
}
.onChange(of: isInputEmpty) {
presentingViewController?.isModalInPresentation = !$0
Expand Down Expand Up @@ -179,8 +179,6 @@ private struct SubmitFeedbackView: View {
}

private enum Strings {
static let ok = NSLocalizedString("submit.feedback.buttonOK", value: "OK", comment: "The button title for the Cancel button in the In-App Feedback screen")
static let cancel = NSLocalizedString("submit.feedback.buttonCancel", value: "Cancel", comment: "The button title for the Cancel button in the In-App Feedback screen")
static let submit = NSLocalizedString("submit.feedback.submit.button", value: "Submit", comment: "The button title for the Submit button in the In-App Feedback screen")
static let title = NSLocalizedString("submit.feedback.title", value: "Feedback", comment: "The title for the the In-App Feedback screen")
static let details = NSLocalizedString("submit.feedback.detailsPlaceholder", value: "Details", comment: "The section title and or placeholder")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ private extension PushAuthenticationManager {
/// Displays an AlertView indicating that a Login Request has expired.
///
func showLoginExpiredAlert() {
let title = NSLocalizedString("Login Request Expired", comment: "Login Request Expired")
let message = NSLocalizedString("The login request has expired. Log in to WordPress.com to try again.",
comment: "WordPress.com Push Authentication Expired message")
let acceptButtonTitle = NSLocalizedString("OK", comment: "OK")
let title = NSLocalizedString("Login Request Expired", comment: "Login Request Expired")
let message = NSLocalizedString("The login request has expired. Log in to WordPress.com to try again.", comment: "WordPress.com Push Authentication Expired message")
let acceptButtonTitle = SharedStrings.Button.ok

alertControllerProxy.show(withTitle: title,
message: message,
Expand All @@ -147,9 +146,9 @@ private extension PushAuthenticationManager {
/// - completion: A closure that receives a parameter, indicating whether the login attempt was confirmed or not.
///
func showLoginVerificationAlert(_ message: String, completion: @escaping ((_ approved: Bool) -> ())) {
let title = NSLocalizedString("Verify Log In", comment: "Push Authentication Alert Title")
let cancelButtonTitle = NSLocalizedString("Ignore", comment: "Ignore action. Verb")
let acceptButtonTitle = NSLocalizedString("Approve", comment: "Approve action. Verb")
let title = NSLocalizedString("Verify Log In", comment: "Push Authentication Alert Title")
let cancelButtonTitle = NSLocalizedString("Ignore", comment: "Ignore action. Verb")
let acceptButtonTitle = NSLocalizedString("Approve", comment: "Approve action. Verb")

alertControllerProxy.show(withTitle: title,
message: message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WebKitViewController: UIViewController, WebKitAuthenticatable {
style: .plain,
target: self,
action: #selector(share))
button.title = NSLocalizedString("Share", comment: "Button label to share a web page")
button.title = NSLocalizedString(SharedStrings.Button.share, comment: "Button label to share a web page")
return button
}()
@objc lazy var safariButton: UIBarButtonItem = {
Expand Down
10 changes: 4 additions & 6 deletions WordPress/Classes/Utility/ZendeskUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,6 @@ private extension ZendeskUtils {
struct LocalizedText {
static let alertMessageWithName = NSLocalizedString("To continue please enter your email address and name.", comment: "Instructions for alert asking for email and name.")
static let alertMessage = NSLocalizedString("Please enter your email address.", comment: "Instructions for alert asking for email.")
static let alertSubmit = NSLocalizedString("OK", comment: "Submit button on prompt for user information.")
static let alertCancel = NSLocalizedString("Cancel", comment: "Cancel prompt for user information.")
static let emailPlaceholder = NSLocalizedString("Email", comment: "Email address text field placeholder")
static let emailAccessibilityLabel = NSLocalizedString("Email", comment: "Accessibility label for the Email text field.")
static let namePlaceholder = NSLocalizedString("Name", comment: "Name text field placeholder")
Expand Down Expand Up @@ -1192,8 +1190,8 @@ extension ZendeskUtils {
optionalIdentity: false,
includesName: true,
message: LocalizedText.alertMessageWithName,
submit: LocalizedText.alertSubmit,
cancel: LocalizedText.alertCancel
submit: SharedStrings.Button.ok,
cancel: SharedStrings.Button.cancel
)
}

Expand All @@ -1202,8 +1200,8 @@ extension ZendeskUtils {
optionalIdentity: false,
includesName: false,
message: LocalizedText.alertMessage,
submit: LocalizedText.alertSubmit,
cancel: LocalizedText.alertCancel
submit: SharedStrings.Button.ok,
cancel: SharedStrings.Button.cancel
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ extension AztecPostViewController {

func displayUnableToPlayVideoAlert() {
let alertController = UIAlertController(title: MediaUnableToPlayVideoAlert.title, message: MediaUnableToPlayVideoAlert.message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .`default`, handler: nil))
alertController.addAction(UIAlertAction(title: SharedStrings.Button.ok, style: .default, handler: nil))
present(alertController, animated: true)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class DashboardPromptsCardCell: UICollectionViewCell, Reusable {
private lazy var shareButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle(Strings.shareButtonTitle, for: .normal)
button.setTitle(SharedStrings.Button.share, for: .normal)
button.setTitleColor(WPStyleGuide.BloggingPrompts.buttonTitleColor, for: .normal)
button.titleLabel?.font = WPStyleGuide.BloggingPrompts.buttonTitleFont
button.titleLabel?.adjustsFontForContentSizeCategory = true
Expand Down Expand Up @@ -552,7 +552,6 @@ private extension DashboardPromptsCardCell {
static let cardFrameTitle = NSLocalizedString("Prompts", comment: "Title label for the Prompts card in My Sites tab.")
static let answerButtonTitle = NSLocalizedString("Answer Prompt", comment: "Title for a call-to-action button on the prompts card.")
static let answeredLabelTitle = NSLocalizedString("✓ Answered", comment: "Title label that indicates the prompt has been answered.")
static let shareButtonTitle = NSLocalizedString("Share", comment: "Title for a button that allows the user to share their answer to the prompt.")
static let answerInfoSingularFormat = NSLocalizedString("%1$d answer", comment: "Singular format string for displaying the number of users "
+ "that answered the blogging prompt.")
static let answerInfoPluralFormat = NSLocalizedString("%1$d answers", comment: "Plural format string for displaying the number of users "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
func siteIconShouldAllowDroppedImages() -> Bool
func siteTitleTapped()
func siteSwitcherTapped(sourceView: UIView)
func buttonShareSiteTapped()
func visitSiteTapped()
}

Expand Down Expand Up @@ -116,6 +117,7 @@ class BlogDetailHeaderView: UIView {
self?.delegate?.siteIconReceivedDroppedImage(images.first)
}

titleView.subtitleButton.menu = makeSiteLinkMenu()
titleView.subtitleButton.addTarget(self, action: #selector(subtitleButtonTapped), for: .touchUpInside)
titleView.titleButton.addTarget(self, action: #selector(titleButtonTapped), for: .touchUpInside)

Expand All @@ -126,6 +128,20 @@ class BlogDetailHeaderView: UIView {
setupConstraintsForChildViews()
}

private func makeSiteLinkMenu() -> UIMenu {
UIMenu(children: [
UIAction(title: Strings.visitSite, image: UIImage(systemName: "safari"), handler: { [weak self] _ in
self?.delegate?.visitSiteTapped()
}),
UIAction(title: SharedStrings.Button.copyLink, image: UIImage(systemName: "doc.on.doc"), handler: { [weak self] _ in
UIPasteboard.general.url = URL(string: (self?.blog?.displayURL ?? "") as String)
}),
UIAction(title: SharedStrings.Button.share + "", image: UIImage(systemName: "square.and.arrow.up"), handler: { [weak self] _ in
self?.delegate?.buttonShareSiteTapped()
})
])
}

// MARK: - Constraints

private func setupConstraintsForChildViews() {
Expand Down Expand Up @@ -203,16 +219,6 @@ extension BlogDetailHeaderView {
configuration.contentInsets = isSidebarModeEnabled ? NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 2, trailing: 0) : NSDirectionalEdgeInsets(top: 2, leading: 0, bottom: 1, trailing: 0)
configuration.titleLineBreakMode = .byTruncatingTail
button.configuration = configuration

button.menu = UIMenu(children: [
UIAction(title: Strings.visitSite, image: UIImage(systemName: "safari"), handler: { [weak button] _ in
button?.sendActions(for: .touchUpInside)
}),
UIAction(title: Strings.actionCopyURL, image: UIImage(systemName: "doc.on.doc"), handler: { [weak button] _ in
UIPasteboard.general.url = URL(string: button?.titleLabel?.text ?? "")
})
])

button.accessibilityHint = NSLocalizedString("Tap to view your site", comment: "Accessibility hint for button used to view the user's site")
button.translatesAutoresizingMaskIntoConstraints = false
return button
Expand Down Expand Up @@ -354,7 +360,5 @@ private extension String {
}

private enum Strings {
static let visitSite = NSLocalizedString("blogHeader.actionVisitSite", value: "Visit site", comment: "Context menu button title")
static let actionCopyURL = NSLocalizedString("blogHeader.actionCopyURL", value: "Copy URL", comment: "Context menu button title")

static let visitSite = NSLocalizedString("blogHeader.actionVisitSite", value: "Visit Site", comment: "Context menu button title")
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension HomeSiteHeaderViewController {

private func makePrimarySection() -> UIMenu {
let menuItems = [
MenuItem.visitSite({ [weak self] in self?.visitSiteTapped() }),
MenuItem.visitSite { [weak self] in self?.visitSiteTapped() },
MenuItem.shareSite { [weak self] in self?.buttonShareSiteTapped() },
]
return UIMenu(options: .displayInline, children: menuItems.map { $0.toAction })
Expand Down Expand Up @@ -54,7 +54,7 @@ extension HomeSiteHeaderViewController {

// MARK: - Actions

private func buttonShareSiteTapped() {
func buttonShareSiteTapped() {
guard let urlString = blog.homeURL as String?,
let url = URL(string: urlString) else {
assertionFailure("Site has no URL")
Expand Down Expand Up @@ -108,7 +108,7 @@ private enum MenuItem {
var title: String {
switch self {
case .visitSite: return Strings.visitSite
case .shareSite: return Strings.shareSite
case .shareSite: return SharedStrings.Button.share + ""
case .siteTitle: return Strings.siteTitle
case .personalizeHome: return Strings.personalizeHome
}
Expand Down Expand Up @@ -136,7 +136,6 @@ private enum MenuItem {

private enum Strings {
static let visitSite = NSLocalizedString("mySite.siteActions.visitSite", value: "Visit site", comment: "Menu title for the visit site option")
static let shareSite = NSLocalizedString("mySite.siteActions.shareSite", value: "Share site", comment: "Menu title for the share site option")
static let siteTitle = NSLocalizedString("mySite.siteActions.siteTitle", value: "Change site title", comment: "Menu title for the change site title option")
static let siteIcon = NSLocalizedString("mySite.siteActions.siteIcon", value: "Change site icon", comment: "Menu title for the change site icon option")
static let personalizeHome = NSLocalizedString("mySite.siteActions.personalizeHome", value: "Personalize home", comment: "Menu title for the personalize home option")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private extension KeyringAccountHelper {
let alertBodyMessage = NSLocalizedString("The Facebook connection cannot find any Pages. Publicize cannot connect to Facebook Profiles, only published Pages.",
comment: "Error message shown to a user who is trying to share to Facebook but does not have any available Facebook Pages.")
let continueActionTitle = NSLocalizedString("Learn more", comment: "A button title.")
let cancelActionTitle = NSLocalizedString("OK", comment: "A button title for closing the dialog.")
let cancelActionTitle = SharedStrings.Button.ok

return ValidationError(header: alertHeaderMessage,
body: alertBodyMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ import WordPressShared
message.append(error.localizedDescription)
}
let controller = UIAlertController(title: title, message: message, preferredStyle: .alert)
controller.addCancelActionWithTitle(NSLocalizedString("OK", comment: "A button title."), handler: nil)
controller.addCancelActionWithTitle(SharedStrings.Button.ok, handler: nil)

controller.presentFromRootViewController()
}
Expand Down
Loading

0 comments on commit be2aa0d

Please sign in to comment.