oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import SwiftUI
2
3public struct ProjectsScreen: View {
4 let session: EquipoSession
5 @Environment(\.scenePhase) private var phase
6 let openProject: (String) -> Void
7 public init(session: EquipoSession, openProject: @escaping (String) -> Void) {
8 self.session = session; self.openProject = openProject
9 }
10 public var body: some View {
11 let catalog = session.projectCatalog
12 List {
13 ForEach(catalog.connections) { connection in
14 HStack {
15 Text(connection.title).font(Typo.secondaryStrong)
16 Spacer()
17 Text(connection.state == "connected"
18 ? String(format: EquipoStrings.text("chat.connections.connected"), connection.title)
19 : EquipoStrings.text("counts.unavailable"))
20 .font(Typo.caption).foregroundStyle(Palette.secondary)
21 }
22 }
23 if let notice = catalog.notice {
24 Text(notice).font(Typo.secondary).foregroundStyle(Palette.negative)
25 RosterButton(title: EquipoStrings.text("read.retry"), primary: false, expanded: false) { Task { await catalog.refresh() } }
26 }
27 Section(EquipoStrings.text("projects.yours")) {
28 ForEach(catalog.items) { project in
29 HStack(alignment: .top, spacing: 12) {
30 Button { openProject(project.id) } label: { ProjectSummary(project: project) }
31 .buttonStyle(.plain).frame(maxWidth: .infinity, alignment: .leading)
32 ProjectStar(project: project, catalog: catalog)
33 }
34 }
35 if catalog.loaded && catalog.items.isEmpty { Text(EquipoStrings.text("projects.empty")).foregroundStyle(Palette.secondary) }
36 if !catalog.loaded && catalog.notice == nil { ProgressView() }
37 }
38 if !catalog.available.isEmpty {
39 Section(EquipoStrings.text("projects.can_add")) {
40 ForEach(catalog.available) { repo in
41 VStack(alignment: .leading, spacing: 8) {
42 Text(repo.title.isEmpty ? repo.name : repo.title).font(Typo.secondaryStrong)
43 Text(repo.repo).font(Typo.caption).foregroundStyle(Palette.secondary)
44 if !repo.description.isEmpty { Text(repo.description).font(Typo.secondary) }
45 RosterButton(title: EquipoStrings.text("projects.add_reachable"), primary: true, expanded: false) { Task { await catalog.add(repo) } }
46 .disabled(catalog.pending.contains(repo.id))
47 }
48 }
49 }
50 }
51 }
52 .scrollContentBackground(.hidden).background(Palette.background)
53 .task { await catalog.refresh() }
54 .onChange(of: phase) { _, phase in if phase == .active { Task { await catalog.refresh() } } }
55 .refreshable { await catalog.refresh() }
56 }
57}
58
59struct ProjectSummary: View {
60 let project: ThinProject
61 var body: some View {
62 VStack(alignment: .leading, spacing: 5) {
63 Text(project.displayName).font(Typo.secondaryStrong).foregroundStyle(Palette.text)
64 Text(project.repo).font(Typo.caption).foregroundStyle(Palette.secondary)
65 if let description = project.description, !description.isEmpty {
66 Text(description).font(Typo.secondary).foregroundStyle(Palette.secondary)
67 }
68 }
69 .frame(maxWidth: .infinity, alignment: .leading).contentShape(Rectangle())
70 }
71}
72
73struct ProjectStar: View {
74 let project: ThinProject
75 let catalog: ProjectCatalog
76 var body: some View {
77 Button { Task { await catalog.setStar(project, project.starred != true) } } label: {
78 Image(systemName: project.starred == true ? "star.fill" : "star")
79 .foregroundStyle(project.starred == true ? Palette.accent : Palette.secondary)
80 .frame(minWidth: 44, minHeight: 44)
81 }
82 .buttonStyle(.plain).disabled(catalog.pending.contains(project.id))
83 .accessibilityLabel(String(format: EquipoStrings.text(project.starred == true ? "work.star.remove" : "work.star.add"), project.displayName))
84 }
85}
86
87public struct ProjectDetailScreen: View {
88 let session: EquipoSession
89 let projectID: String
90 let newRequest: (ThinProject) -> Void
91 let openTask: (String) -> Void
92 public init(session: EquipoSession, projectID: String, newRequest: @escaping (ThinProject) -> Void, openTask: @escaping (String) -> Void) {
93 self.session = session; self.projectID = projectID; self.newRequest = newRequest; self.openTask = openTask
94 }
95 public var body: some View {
96 let catalog = session.projectCatalog
97 ScrollView {
98 VStack(alignment: .leading, spacing: 20) {
99 if let project = catalog.projects[projectID], project.state == "active" {
100 HStack(alignment: .top) { ProjectSummary(project: project); ProjectStar(project: project, catalog: catalog) }
101 RosterButton(title: EquipoStrings.text("projects.new_request"), primary: true, expanded: false) { newRequest(project) }
102 if let notice = catalog.notice { Text(notice).foregroundStyle(Palette.negative) }
103 if let names = project.names, !names.isEmpty {
104 SectionTitle(text: EquipoStrings.text("projects.names"))
105 ForEach(names, id: \.self) { Text($0).font(Typo.body) }
106 }
107 if let names = project.personalNames, !names.isEmpty {
108 SectionTitle(text: EquipoStrings.text("projects.personal_names"))
109 ForEach(names, id: \.self) { name in
110 VStack(alignment: .leading, spacing: 4) {
111 Text(name).font(Typo.body)
112 RosterButton(title: EquipoStrings.text("projects.forget_name"), primary: false, expanded: false) { Task { await catalog.forgetName(name, in: project) } }
113 .disabled(catalog.pending.contains(project.id))
114 .accessibilityValue(name)
115 }
116 }
117 }
118 if session.me?.role == "owner" {
119 Link(EquipoStrings.text("projects.edit"), destination: catalog.detailsURL(project))
120 }
121 ForEach(session.tasks.filter { $0.projectId == project.id }) { task in
122 TaskRowButton(task: task, needsYou: session.waitsOnYou(task)) { openTask(task.id) }
123 }
124 } else { Text(EquipoStrings.text("api.not_found")).foregroundStyle(Palette.secondary) }
125 }
126 .padding(16).frame(maxWidth: 760, alignment: .leading).frame(maxWidth: .infinity)
127 }
128 .background(Palette.background)
129 .refreshable { await catalog.refresh() }
130 }
131}
132
133/// The selection belongs to the next composer message, and never to a task thread.
134public struct ProjectSelectionChip: View {
135 let catalog: ProjectCatalog
136 public init(catalog: ProjectCatalog) { self.catalog = catalog }
137 public var body: some View {
138 if let notice = catalog.selectionNotice {
139 Text(notice).font(Typo.secondary).foregroundStyle(Palette.secondary).padding(.horizontal, 16)
140 }
141 if let project = catalog.selection {
142 HStack(spacing: 8) {
143 Image(systemName: "folder")
144 Text(project.displayName).font(Typo.secondaryStrong)
145 Button { catalog.selection = nil } label: { Image(systemName: "xmark").frame(minWidth: 44, minHeight: 44) }
146 .buttonStyle(.plain).accessibilityLabel(EquipoStrings.text("projects.remove_selection"))
147 }
148 .padding(.leading, 12).background(Palette.surface2, in: Capsule()).padding(.horizontal, 16)
149 .frame(maxWidth: .infinity, alignment: .leading)
150 }
151 }
152}
153