Skip to content
Merged
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
6 changes: 3 additions & 3 deletions App/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,9 @@ final class AppModel {
renaming = RenamePrompt(session: id, workspaceID: workspaceID, name: context.target.workspace)
}

func commitRename() async {
guard let prompt = renaming else { return }
renaming = nil
/// Takes the prompt as it was when the button was tapped: dismissing the alert clears
/// `renaming` right away, before an awaited `Task` would get a chance to read it.
func commitRename(_ prompt: RenamePrompt) async {
let name = prompt.name.trimmingCharacters(in: .whitespacesAndNewlines)
guard !name.isEmpty, name != context(for: prompt.session)?.target.workspace else { return }
do { try await cluster.renameWorkspace(prompt.workspaceID, to: name, onMachine: prompt.session.machineID) }
Expand Down
5 changes: 4 additions & 1 deletion App/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ struct MainView: View {
view
.alert("Rename Session", isPresented: Binding { model.renaming != nil } set: { if !$0 { model.renaming = nil } }) {
TextField("Name", text: Binding { model.renaming?.name ?? "" } set: { model.renaming?.name = $0 })
Button("Rename") { Task { await model.commitRename() } }
Button("Rename") {
guard let prompt = model.renaming else { return }
Task { await model.commitRename(prompt) }
}
Button("Cancel", role: .cancel) { model.renaming = nil }
} message: {
Text("Renames its Herdr workspace. Other panes in the same workspace share the name.")
Expand Down
Loading