#if DEBUG import SwiftUI /// In-memory fixture through the real session and device wire decoder. public enum NeedsViewFixture { @MainActor public static func makeModel() -> EquipoAppModel { let transport = NeedsFixtureTransport() let store = MemorySecretStore() let accounts = DeviceAccounts(store: store) var account = DeviceAccount.new(origin: transport.origin, label: "Fixture") account.credential = DeviceCredential(id: "fixture", token: "fixture", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: .distantFuture) account.teamName = "Oficina"; account.address = "paul@example.com" try! accounts.commit(.save(account), lifetime: accounts.lifetimes.current) let model = EquipoAppModel(store: store, makeTransport: { _ in transport }) model.destination = Destination(pane: .needs) return model } } #if os(iOS) public struct PhoneNeedsFixture: View { @State private var model = NeedsViewFixture.makeModel() public init() {} public var body: some View { if let session = model.session { PhoneTabs(model: model, session: session) .tint(Palette.accent) .preferredColorScheme(.light) .task { await session.refresh() } } } } #endif private struct NeedsFixtureTransport: EquipoTransport { let origin = URL(string: "https://fixture.invalid")! private var scenario: String { ProcessInfo.processInfo.environment["EQUIPO_NEEDS_FIXTURE"] ?? "list" } private var needs: [[String: Any]] { scenario == "empty" || scenario.hasPrefix("today") ? [] : [retry, merge, question] } private var tasks: [[String: Any]] { scenario == "empty" ? [] : needs + [running, finished] } func send(_ request: APIRequest) async throws -> APIResponse { let value: [String: Any] switch request.path { case "/snapshot": value = ["me": ["id": "fixture", "address": "paul@example.com", "role": "owner", "team_id": "fixture", "team_name": "Oficina", "revision": 1], "cursor": 1, "tasks": tasks, "messages": [], "turns": [], "cards": scenario == "empty" ? [] : cards, "projects": []] case "/tasks": value = ["items": tasks] case "/needs-you": value = ["items": needs] default: value = tasks.first { request.path == "/tasks/" + ($0["id"] as! String) } ?? [:] } return APIResponse(status: 200, data: try JSONSerialization.data(withJSONObject: value)) } func lines(_ request: APIRequest) async throws -> AsyncThrowingStream { AsyncThrowingStream { $0.finish() } } private var at: String { ISO8601DateFormatter().string(from: Calendar.current.startOfDay(for: Date()).addingTimeInterval(20 * 60)) } private func task(_ id: String, _ title: String, stage: String, need: String = "", steps: [[String: Any]] = []) -> [String: Any] { ["id": id, "revision": 1, "project_id": "project", "project": "Equipo", "repo": "oficina/equipo", "title": title, "brief": title, "stage": stage, "needs_you": need, "creator": "paul@example.com", "branch": "equipo/" + id, "url": "", "candidate_sha": "3f9c2a167de8", "checks": "", "checks_reason": "", "verdict": "", "review_label": "", "created_at": at, "updated_at": at, "steps": steps] } private func step(_ id: String, specialist: String = "engineering", state: String = "done", reason: String = "", headline: String = "") -> [String: Any] { ["id": id, "specialist": specialist, "state": state, "reason": reason, "headline": headline, "summary": "", "verdict": "", "review_label": "", "checks": "", "gate": "", "terminated": true, "started_at": at, "finished_at": at] } private var retry: [String: Any] { task("retry", "Clear the badge after sign-out", stage: "in_progress", need: "retry", steps: [step("failed", state: "failed", reason: "push_failed")]) } private var merge: [String: Any] { var task = task("merge", "Keep the sign-in button visible", stage: "ready_to_merge", need: "merge") task["checks"] = "passed"; task["verdict"] = "approve"; task["review_label"] = "other_family" var review = step("approved", specialist: "review", headline: "Keep the sign-in button visible") review["candidate_sha"] = task["candidate_sha"]; review["verdict"] = "approve"; review["review_label"] = "other_family" task["steps"] = [review] return task } private var question: [String: Any] { task("question", "Name the team in sign-in emails", stage: "in_review", need: "fix_rounds", steps: [step("review", specialist: "review", headline: "The subject still needs a decision")]) } private var running: [String: Any] { task("running", "Keep the task list up to date", stage: "in_progress", steps: [step("live", state: "running", headline: "Updating the list after a task finishes")]) } private var finished: [String: Any] { var task = task("finished", "Explain why the upload stopped", stage: "done", steps: [step("merged", specialist: "merge", headline: "Merged into main")]) task["done_at"] = at task["undo_offered"] = scenario != "today-no-undo" task["merged"] = ["into": "main", "sha": "3f9c2a167de8", "without_checks": true, "at": at] return task } private var cards: [[String: Any]] { [card("merge-card", task: "merge", kind: "merge", question: "Merge this fix?", options: ["merge", "not_now"]), card("question-card", task: "question", kind: "question", question: "Should the subject name the team?", options: ["Yes, name the team", "Keep it short"]), card("receipt", task: "finished", kind: "merge_receipt", question: "Merged", options: ["undo"])] } private func card(_ id: String, task: String, kind: String, question: String, options: [String]) -> [String: Any] { ["aside": scenario == "aside" && kind == "merge", "id": id, "revision": 1, "kind": kind, "state": "open", "turn_id": "", "project_id": "project", "name": "", "question": question, "options": options, "choice": "", "task_id": task, "created_at": at, "updated_at": at] } } #endif