Repository navigation
iOS: rename and pin workspaces from the phone #5512
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
Changes from 4 commits
61af99a
d524935
7ab6b17
284a6e0
90d1a8f
88a39cc
00faf13
6bc3e28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #if os(iOS) | ||
| import CmuxMobileSupport | ||
| import SwiftUI | ||
|
|
||
| /// A small sheet that renames a workspace from the mobile workspace list. | ||
| /// | ||
| /// Seeds its text field with the current name and hands the trimmed result back | ||
| /// through `onSave`; the caller forwards it to the Mac. Whitespace-only names are | ||
| /// rejected (Save is disabled). | ||
| struct WorkspaceRenameSheet: View { | ||
| @Environment(\.dismiss) private var dismiss | ||
| private let onSave: (String) -> Void | ||
| @State private var name: String | ||
|
|
||
| /// Creates the rename sheet. | ||
| /// - Parameters: | ||
| /// - currentName: The workspace's current name, used to seed the field. | ||
| /// - onSave: Called with the new trimmed name when the user taps Save. | ||
| init(currentName: String, onSave: @escaping (String) -> Void) { | ||
| self.onSave = onSave | ||
| _name = State(initialValue: currentName) | ||
| } | ||
|
|
||
| var body: some View { | ||
| NavigationStack { | ||
| Form { | ||
| TextField( | ||
| L10n.string("mobile.workspace.rename.placeholder", defaultValue: "Workspace name"), | ||
| text: $name | ||
| ) | ||
| .autocorrectionDisabled() | ||
| .submitLabel(.done) | ||
| .onSubmit(save) | ||
| .accessibilityIdentifier("WorkspaceRenameField") | ||
| } | ||
| .navigationTitle(L10n.string("mobile.workspace.rename.title", defaultValue: "Rename Workspace")) | ||
| .mobileInlineNavigationTitle() | ||
| .toolbar { | ||
| ToolbarItem(placement: .cancellationAction) { | ||
| Button(L10n.string("mobile.common.cancel", defaultValue: "Cancel")) { | ||
| dismiss() | ||
| } | ||
| .accessibilityIdentifier("WorkspaceRenameCancelButton") | ||
| } | ||
| ToolbarItem(placement: .confirmationAction) { | ||
| Button(L10n.string("mobile.common.save", defaultValue: "Save")) { | ||
| save() | ||
| } | ||
| .disabled(name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) | ||
| .accessibilityIdentifier("WorkspaceRenameSaveButton") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func save() { | ||
| let trimmed = name.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard !trimmed.isEmpty else { return } | ||
| onSave(trimmed) | ||
| dismiss() | ||
| } | ||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,9 @@ struct WorkspaceShellView: View { | |
| selectWorkspace: selectWorkspace, | ||
| createWorkspace: createWorkspaceInCompactStack, | ||
| rescanQR: { store.disconnectAndForgetActiveMac() }, | ||
| signOut: signOut | ||
| signOut: signOut, | ||
| renameWorkspace: renameWorkspace, | ||
| setPinned: setWorkspacePinned | ||
|
Contributor
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.
When the phone is connected to a Mac build from before this PR, Useful? React with 👍 / 👎. |
||
| ) | ||
| .navigationDestination(for: MobileWorkspacePreview.ID.self) { workspaceID in | ||
| workspaceDestination(for: workspaceID, createWorkspace: createWorkspaceInCompactStack) | ||
|
|
@@ -113,7 +115,9 @@ struct WorkspaceShellView: View { | |
| selectWorkspace: selectWorkspace, | ||
| createWorkspace: store.createWorkspace, | ||
| rescanQR: { store.disconnectAndForgetActiveMac() }, | ||
| signOut: signOut | ||
| signOut: signOut, | ||
| renameWorkspace: renameWorkspace, | ||
| setPinned: setWorkspacePinned | ||
| ) | ||
| .navigationSplitViewColumnWidth(min: 320, ideal: 380, max: 440) | ||
| } detail: { | ||
|
|
@@ -137,6 +141,14 @@ struct WorkspaceShellView: View { | |
| } | ||
| } | ||
|
|
||
| private func renameWorkspace(_ id: MobileWorkspacePreview.ID, _ title: String) { | ||
| Task { await store.renameWorkspace(id: id, title: title) } | ||
| } | ||
|
|
||
| private func setWorkspacePinned(_ id: MobileWorkspacePreview.ID, _ pinned: Bool) { | ||
| Task { await store.setWorkspacePinned(id: id, pinned) } | ||
| } | ||
|
|
||
| private func createWorkspaceInCompactStack() { | ||
| let existingWorkspaceIDs = Set(store.workspaces.map(\.id)) | ||
| pendingCompactCreateNavigationWorkspaceIDs = existingWorkspaceIDs | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.