mirror of
https://github.com/awizemann/scarf.git
synced 2026-05-10 10:36:35 +00:00
Merge pull request #34 from awizemann/fix/code-review-apr22
fix: address code-review findings from Apr 22 commits
This commit is contained in:
@@ -82,6 +82,11 @@ final class ServerRegistry {
|
||||
/// Flip the default server to `id`. Passing `ServerContext.local.id`
|
||||
/// clears the flag on every remote entry, making Local the implicit
|
||||
/// default. Passing an unknown ID is a no-op. Persisted on return.
|
||||
///
|
||||
/// Intentionally doesn't fire `onEntriesChanged` — that hook means "the
|
||||
/// set of servers changed" and drives the menu-bar fanout rebuild. A
|
||||
/// default-flag flip doesn't change the set; SwiftUI views reading
|
||||
/// `defaultServerID` redraw via `@Observable`'s tracking of `entries`.
|
||||
func setDefaultServer(_ id: ServerID) {
|
||||
var changed = false
|
||||
for idx in entries.indices {
|
||||
@@ -93,7 +98,6 @@ final class ServerRegistry {
|
||||
}
|
||||
if changed {
|
||||
save()
|
||||
onEntriesChanged?()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,19 +143,20 @@ struct ManageServersView: View {
|
||||
}
|
||||
|
||||
/// A star button that marks the open-on-launch default. Filled + yellow
|
||||
/// on the current default row (and non-interactive — clicking it is a
|
||||
/// no-op since the flag is already set); outline + secondary elsewhere,
|
||||
/// clicking promotes that row to default.
|
||||
/// on the current default row (disabled, since clicking would be a
|
||||
/// no-op); outline + secondary elsewhere, clicking promotes that row
|
||||
/// to default.
|
||||
@ViewBuilder
|
||||
private func defaultStar(for id: ServerID, currentDefault: ServerID) -> some View {
|
||||
let isDefault = id == currentDefault
|
||||
Button {
|
||||
if !isDefault { registry.setDefaultServer(id) }
|
||||
registry.setDefaultServer(id)
|
||||
} label: {
|
||||
Image(systemName: isDefault ? "star.fill" : "star")
|
||||
.foregroundStyle(isDefault ? .yellow : .secondary)
|
||||
}
|
||||
.buttonStyle(.borderless)
|
||||
.disabled(isDefault)
|
||||
.help(isDefault ? "Opens on launch" : "Set as default — open this server when Scarf launches.")
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import SwiftUI
|
||||
|
||||
struct SidebarView: View {
|
||||
@Environment(AppCoordinator.self) private var coordinator
|
||||
@Environment(\.serverContext) private var serverContext
|
||||
|
||||
var body: some View {
|
||||
@Bindable var coordinator = coordinator
|
||||
@@ -59,6 +60,6 @@ struct SidebarView: View {
|
||||
}
|
||||
.listStyle(.sidebar)
|
||||
.navigationTitle("Scarf")
|
||||
.splitViewAutosaveName("ScarfMainSidebar")
|
||||
.splitViewAutosaveName("ScarfMainSidebar.\(serverContext.id)")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user