feat(ui): Mine/Starters rig toggle + seed starters into existing libraries

Two fixes so shipped starter rigs are actually reachable:

- Seeding no longer requires an empty library. On launch it installs any
  factory rigs whose stable ids are missing, once per FactoryRigLibrary
  .seedVersion (a per-device UserDefaults marker). Existing users therefore
  receive the starters on their next launch; a starter the user later
  deletes stays deleted (the marker has advanced); bumping seedVersion when
  new starters ship re-runs catch-up for just the new ones. Idempotent by id,
  so iCloud-synced devices never duplicate.
- Sidebar gains a segmented Mine / Starters toggle. "Mine" is the flat,
  reorderable user list; "Starters" groups the shipped rigs by category. A
  "Restore Starter Rigs" action (Starters empty-state button + library menu)
  re-installs missing starters on demand via RigLibraryBootstrap.restoreStarterRigs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 14:11:22 -07:00
parent fba32ff0aa
commit ad6ed41674
4 changed files with 168 additions and 77 deletions
@@ -45,6 +45,9 @@ struct RigLibrarySidebarView: View {
let onImportArchive: () -> Void
let onExportArchive: () -> Void
/// Invoked to (re-)install any shipped starter rigs missing from the library. Defaults to a no-op.
var onRestoreStarters: () -> Void = {}
/// Invoked when the local-only (iCloud-unavailable) status icon is tapped, so the host can
/// explain how to re-enable iCloud sync. Defaults to a no-op.
var onShowCloudStatus: () -> Void = {}
@@ -52,6 +55,16 @@ struct RigLibrarySidebarView: View {
private static let timestampFormat: Date.FormatStyle =
Date.FormatStyle(date: .abbreviated, time: .shortened)
/// Which group of rigs the list is currently showing.
private enum RigTab: String, CaseIterable, Identifiable {
case mine = "Mine"
case starters = "Starters"
var id: String { rawValue }
}
/// The selected list tab. Defaults to the user's own rigs.
@State private var tab: RigTab = .mine
// MARK: - Body
var body: some View {
@@ -99,46 +112,83 @@ struct RigLibrarySidebarView: View {
// MARK: - List
@ViewBuilder
private var rigList: some View {
ScrollView(.vertical, showsIndicators: true) {
LazyVStack(alignment: .leading, spacing: RigLibrarySidebarView.rowSpacing) {
if !store.isLoaded {
HStack(spacing: 6) {
ProgressView().controlSize(.small)
Text("Loading…")
.font(.caption)
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.emptyOpacity))
}
.padding(.vertical, RigLibrarySidebarView.rowPadding)
} else if store.entries.isEmpty {
Text("No saved rigs yet.\nTap New or Save to add one.")
.font(.caption)
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.emptyOpacity))
.padding(.vertical, RigLibrarySidebarView.rowPadding)
}
// Shipped starter rigs, grouped by category (fixed catalog order, not reorderable).
ForEach(factorySections, id: \.category) { section in
sectionHeader(section.category.displayName)
ForEach(section.entries) { entry in
rigRow(entry, reorderable: false)
if !store.isLoaded {
HStack(spacing: 6) {
ProgressView().controlSize(.small)
Text("Loading…")
.font(.caption)
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.emptyOpacity))
}
.padding(.vertical, RigLibrarySidebarView.rowPadding)
.frame(maxHeight: .infinity, alignment: .top)
} else {
VStack(alignment: .leading, spacing: RigLibrarySidebarView.rowSpacing) {
tabPicker
ScrollView(.vertical, showsIndicators: true) {
LazyVStack(alignment: .leading, spacing: RigLibrarySidebarView.rowSpacing) {
switch tab {
case .mine: mineList
case .starters: startersList
}
}
}
.frame(maxHeight: .infinity)
}
}
}
// The user's own rigs, reorderable. Only headed when starter rigs are also shown, so
// a library with no factory rigs (e.g. after Erase All) reads as a plain list.
let userRigs: [RigEntry] = userEntries
if !userRigs.isEmpty {
if !factorySections.isEmpty {
sectionHeader("My Rigs")
}
ForEach(userRigs) { entry in
rigRow(entry, reorderable: true)
}
/// Segmented Mine / Starters switch at the top of the list.
private var tabPicker: some View {
Picker("", selection: $tab) {
ForEach(RigTab.allCases) { option in
Text(option.rawValue).tag(option)
}
}
.pickerStyle(.segmented)
.labelsHidden()
}
/// The user's own rigs — a flat, reorderable list.
@ViewBuilder
private var mineList: some View {
let userRigs: [RigEntry] = userEntries
if userRigs.isEmpty {
Text("No saved rigs yet.\nTap New or Save to add one.")
.font(.caption)
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.emptyOpacity))
.padding(.vertical, RigLibrarySidebarView.rowPadding)
} else {
ForEach(userRigs) { entry in
rigRow(entry, reorderable: true)
}
}
}
/// The shipped starter rigs, grouped by category (fixed catalog order, not reorderable).
@ViewBuilder
private var startersList: some View {
let sections: [(category: FactoryRigCategory, entries: [RigEntry])] = factorySections
if sections.isEmpty {
VStack(alignment: .leading, spacing: 6) {
Text("No starter rigs installed.")
.font(.caption)
.foregroundStyle(Color.white.opacity(RigLibrarySidebarView.emptyOpacity))
Button("Restore Starter Rigs") { onRestoreStarters() }
.buttonStyle(.bordered)
.tint(.orange)
.controlSize(.small)
}
.padding(.vertical, RigLibrarySidebarView.rowPadding)
} else {
ForEach(sections, id: \.category) { section in
sectionHeader(section.category.displayName)
ForEach(section.entries) { entry in
rigRow(entry, reorderable: false)
}
}
}
.frame(maxHeight: .infinity)
}
/// A small uppercase section header for a group of rigs.
@@ -286,6 +336,8 @@ struct RigLibrarySidebarView: View {
Button("Import Archive…") { onImportArchive() }
Button("Export Archive…") { onExportArchive() }
Divider()
Button("Restore Starter Rigs") { onRestoreStarters() }
Divider()
Button("Erase All Rigs…", role: .destructive) { onEraseAll() }
} label: {
Image(systemName: "ellipsis.circle")