-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add "Status" row to "Post Settings" #24939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kean
wants to merge
11
commits into
trunk
Choose a base branch
from
task/status-row
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
24fa25b
Add initial PostStatusPickerView
kean c911623
Integrate PostStatusPickerView
kean 54a3b1f
Update how timezone is formatted
kean 5440858
Restrict date for scheduling to the future dates
kean a0eecdf
Simplify how publishing works
kean 299af97
Show publish date for drafts
kean dc7a49d
Larger checkmark
kean b11dcf3
Update release notes
kean 190027b
Set date to now when publishing a scheduled post
kean c1e4511
Simplify SecureTextField
kean ba92c56
Show schedule date in the same row
kean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Modules/Sources/WordPressUI/Views/Settings/SecureTextField.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import SwiftUI | ||
import UIKit | ||
|
||
/// - note: The SwiftUI version of the secure text field does not allow you to | ||
/// change to the "view password" mode while preserving the focus – you have | ||
/// to create a separate (regular) text field for that, and it loses focus. | ||
public struct SecureTextField: UIViewRepresentable { | ||
@Binding var text: String | ||
var isSecure: Bool | ||
let placeholder: String | ||
|
||
public init(text: Binding<String>, isSecure: Bool, placeholder: String) { | ||
self._text = text | ||
self.isSecure = isSecure | ||
self.placeholder = placeholder | ||
} | ||
|
||
public func makeUIView(context: Context) -> UITextField { | ||
let textField = UITextField() | ||
textField.placeholder = placeholder | ||
textField.isSecureTextEntry = isSecure | ||
textField.borderStyle = .none | ||
textField.isSecureTextEntry = true | ||
textField.textContentType = .password | ||
textField.autocorrectionType = .no | ||
textField.autocapitalizationType = .none | ||
textField.spellCheckingType = .no | ||
textField.adjustsFontForContentSizeCategory = true | ||
textField.addTarget(context.coordinator, action: #selector(Coordinator.textFieldDidChange), for: .editingChanged) | ||
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) { | ||
textField.becomeFirstResponder() | ||
} | ||
return textField | ||
} | ||
|
||
public func updateUIView(_ textView: UITextField, context: Context) { | ||
textView.text = text | ||
textView.isSecureTextEntry = isSecure | ||
textView.font = { | ||
if isSecure { | ||
return UIFont.preferredFont(forTextStyle: .body) | ||
} | ||
guard let font = UIFont(name: "Menlo", size: 17) else { | ||
return UIFont.preferredFont(forTextStyle: .body) | ||
} | ||
return UIFontMetrics(forTextStyle: .body).scaledFont(for: font) | ||
}() | ||
} | ||
|
||
public func makeCoordinator() -> Coordinator { | ||
Coordinator(self) | ||
} | ||
|
||
public class Coordinator: NSObject { | ||
let parent: SecureTextField | ||
|
||
init(_ parent: SecureTextField) { | ||
self.parent = parent | ||
} | ||
|
||
@objc func textFieldDidChange(_ textField: UITextField) { | ||
parent.text = textField.text ?? "" | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Modules/Sources/WordPressUI/Views/Settings/SettingsCheckmark.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import SwiftUI | ||
import DesignSystem | ||
|
||
public struct SettingsCheckmark: View { | ||
let isSelected: Bool | ||
|
||
public init(isSelected: Bool) { | ||
self.isSelected = isSelected | ||
} | ||
|
||
public var body: some View { | ||
Image(systemName: "checkmark") | ||
.font(.headline) | ||
.opacity(isSelected ? 1 : 0) | ||
.foregroundStyle(AppColor.primary) | ||
.symbolEffect(.bounce.up, value: isSelected) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Modules/Sources/WordPressUI/Views/Settings/SettingsRow.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import SwiftUI | ||
|
||
public struct SettingsRow<Content: View>: View { | ||
let title: String | ||
let content: Content | ||
|
||
public init(_ title: String, @ViewBuilder content: () -> Content) { | ||
self.title = title | ||
self.content = content() | ||
} | ||
|
||
public var body: some View { | ||
HStack { | ||
Text(title) | ||
.layoutPriority(1) | ||
Spacer() | ||
content | ||
.font(.callout) | ||
.foregroundColor(.secondary) | ||
.textSelection(.enabled) | ||
} | ||
.lineLimit(1) | ||
} | ||
} | ||
|
||
public extension SettingsRow where Content == Text { | ||
init(_ title: String, value: String) { | ||
self.init(title) { | ||
Text(value) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
WordPress/Classes/ViewRelated/Post/PostSettings/Extensions/PostStatus+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import SwiftUI | ||
import WordPressData | ||
import WordPressShared | ||
|
||
extension BasePost.Status: @retroactive Identifiable { | ||
public var id: Self { self } | ||
|
||
var title: String { | ||
switch self { | ||
case .draft: NSLocalizedString("postStatus.draft.title", value: "Draft", comment: "Post status title") | ||
case .pending: NSLocalizedString("postStatus.pending.title", value: "Pending", comment: "Post status title") | ||
case .publishPrivate: NSLocalizedString("postStatus.private.title", value: "Private", comment: "Post status title") | ||
case .scheduled: NSLocalizedString("postStatus.scheduled.title", value: "Scheduled", comment: "Post status title") | ||
case .publish: NSLocalizedString("postStatus.published.title", value: "Published", comment: "Post status title") | ||
case .trash: NSLocalizedString("postStatus.trash.title", value: "Trashed", comment: "Post status title") | ||
case .deleted: NSLocalizedString("postStatus.deleted.title", value: "Deleted", comment: "Post status title") | ||
} | ||
} | ||
|
||
var details: String { | ||
switch self { | ||
case .draft: NSLocalizedString("postStatus.draft.details", value: "Not ready to publish", comment: "Post status details") | ||
case .pending: NSLocalizedString("postStatus.pending.details", value: "Waiting for review before publishing", comment: "Post status details") | ||
case .publishPrivate: NSLocalizedString("postStatus.private.details", value: "Only visible to site admins and editors", comment: "Post status details") | ||
case .scheduled: NSLocalizedString("postStatus.scheduled.details", value: "Publish automatically on a chosen date", comment: "Post status details") | ||
case .publish: NSLocalizedString("postStatus.published.details", value: "Visible to everyone", comment: "Post status details") | ||
case .trash: NSLocalizedString("postStatus.trash.details", value: "Trashed but not deleted yet", comment: "Post status title") | ||
case .deleted: NSLocalizedString("postStatus.deleted.details", value: "Permanently deleted", comment: "Post status title") | ||
} | ||
} | ||
|
||
var image: String { | ||
switch self { | ||
case .draft: "post-status-draft" | ||
case .pending: "post-status-pending" | ||
case .publishPrivate: "post-status-private" | ||
case .scheduled: "post-status-scheduled" | ||
case .publish: "post-status-published" | ||
case .trash, .deleted: "" // We don't show these anywhere in the UI | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ final class PostSettingsViewModel: NSObject, ObservableObject { | |
guard let date = settings.publishDate else { | ||
return nil | ||
} | ||
return Self.formattedDate(date, in: timeZone) | ||
} | ||
|
||
static func formattedDate(_ date: Date, in timeZone: TimeZone) -> String { | ||
let formatter = DateFormatter() | ||
formatter.dateStyle = .medium | ||
formatter.timeStyle = .short | ||
|
@@ -264,7 +268,7 @@ final class PostSettingsViewModel: NSObject, ObservableObject { | |
do { | ||
let settings = getSettingsToSave(for: self.settings) | ||
let coordinator = PostCoordinator.shared | ||
if coordinator.isSyncAllowed(for: post) { | ||
if coordinator.isSyncAllowed(for: post) && post.status == settings.status { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you try to change the status of a post, it will be performed as a synchronous operation (showing a spinner until succeeds). |
||
let revision = post.createRevision() | ||
settings.apply(to: revision) | ||
coordinator.setNeedsSync(for: revision) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
visilbilityRow
is displayed at the top of the screen in the "Publishing" sheet (matches the web).