import SwiftUI public struct ProjectsScreen: View { let session: EquipoSession @Environment(\.scenePhase) private var phase let openProject: (String) -> Void public init(session: EquipoSession, openProject: @escaping (String) -> Void) { self.session = session; self.openProject = openProject } public var body: some View { let catalog = session.projectCatalog List { ForEach(catalog.connections) { connection in HStack { Text(connection.title).font(Typo.secondaryStrong) Spacer() Text(connection.state == "connected" ? String(format: EquipoStrings.text("chat.connections.connected"), connection.title) : EquipoStrings.text("counts.unavailable")) .font(Typo.caption).foregroundStyle(Palette.secondary) } } if let notice = catalog.notice { Text(notice).font(Typo.secondary).foregroundStyle(Palette.negative) RosterButton(title: EquipoStrings.text("read.retry"), primary: false, expanded: false) { Task { await catalog.refresh() } } } Section(EquipoStrings.text("projects.yours")) { ForEach(catalog.items) { project in HStack(alignment: .top, spacing: 12) { Button { openProject(project.id) } label: { ProjectSummary(project: project) } .buttonStyle(.plain).frame(maxWidth: .infinity, alignment: .leading) ProjectStar(project: project, catalog: catalog) } } if catalog.loaded && catalog.items.isEmpty { Text(EquipoStrings.text("projects.empty")).foregroundStyle(Palette.secondary) } if !catalog.loaded && catalog.notice == nil { ProgressView() } } if !catalog.available.isEmpty { Section(EquipoStrings.text("projects.can_add")) { ForEach(catalog.available) { repo in VStack(alignment: .leading, spacing: 8) { Text(repo.title.isEmpty ? repo.name : repo.title).font(Typo.secondaryStrong) Text(repo.repo).font(Typo.caption).foregroundStyle(Palette.secondary) if !repo.description.isEmpty { Text(repo.description).font(Typo.secondary) } RosterButton(title: EquipoStrings.text("projects.add_reachable"), primary: true, expanded: false) { Task { await catalog.add(repo) } } .disabled(catalog.pending.contains(repo.id)) } } } } } .scrollContentBackground(.hidden).background(Palette.background) .task { await catalog.refresh() } .onChange(of: phase) { _, phase in if phase == .active { Task { await catalog.refresh() } } } .refreshable { await catalog.refresh() } } } struct ProjectSummary: View { let project: ThinProject var body: some View { VStack(alignment: .leading, spacing: 5) { Text(project.displayName).font(Typo.secondaryStrong).foregroundStyle(Palette.text) Text(project.repo).font(Typo.caption).foregroundStyle(Palette.secondary) if let description = project.description, !description.isEmpty { Text(description).font(Typo.secondary).foregroundStyle(Palette.secondary) } } .frame(maxWidth: .infinity, alignment: .leading).contentShape(Rectangle()) } } struct ProjectStar: View { let project: ThinProject let catalog: ProjectCatalog var body: some View { Button { Task { await catalog.setStar(project, project.starred != true) } } label: { Image(systemName: project.starred == true ? "star.fill" : "star") .foregroundStyle(project.starred == true ? Palette.accent : Palette.secondary) .frame(minWidth: 44, minHeight: 44) } .buttonStyle(.plain).disabled(catalog.pending.contains(project.id)) .accessibilityLabel(String(format: EquipoStrings.text(project.starred == true ? "work.star.remove" : "work.star.add"), project.displayName)) } } public struct ProjectDetailScreen: View { let session: EquipoSession let projectID: String let newRequest: (ThinProject) -> Void let openTask: (String) -> Void public init(session: EquipoSession, projectID: String, newRequest: @escaping (ThinProject) -> Void, openTask: @escaping (String) -> Void) { self.session = session; self.projectID = projectID; self.newRequest = newRequest; self.openTask = openTask } public var body: some View { let catalog = session.projectCatalog ScrollView { VStack(alignment: .leading, spacing: 20) { if let project = catalog.projects[projectID], project.state == "active" { HStack(alignment: .top) { ProjectSummary(project: project); ProjectStar(project: project, catalog: catalog) } RosterButton(title: EquipoStrings.text("projects.new_request"), primary: true, expanded: false) { newRequest(project) } if let notice = catalog.notice { Text(notice).foregroundStyle(Palette.negative) } if let names = project.names, !names.isEmpty { SectionTitle(text: EquipoStrings.text("projects.names")) ForEach(names, id: \.self) { Text($0).font(Typo.body) } } if let names = project.personalNames, !names.isEmpty { SectionTitle(text: EquipoStrings.text("projects.personal_names")) ForEach(names, id: \.self) { name in VStack(alignment: .leading, spacing: 4) { Text(name).font(Typo.body) RosterButton(title: EquipoStrings.text("projects.forget_name"), primary: false, expanded: false) { Task { await catalog.forgetName(name, in: project) } } .disabled(catalog.pending.contains(project.id)) .accessibilityValue(name) } } } if session.me?.role == "owner" { Link(EquipoStrings.text("projects.edit"), destination: catalog.detailsURL(project)) } ForEach(session.tasks.filter { $0.projectId == project.id }) { task in TaskRowButton(task: task, needsYou: session.waitsOnYou(task)) { openTask(task.id) } } } else { Text(EquipoStrings.text("api.not_found")).foregroundStyle(Palette.secondary) } } .padding(16).frame(maxWidth: 760, alignment: .leading).frame(maxWidth: .infinity) } .background(Palette.background) .refreshable { await catalog.refresh() } } } /// The selection belongs to the next composer message, and never to a task thread. public struct ProjectSelectionChip: View { let catalog: ProjectCatalog public init(catalog: ProjectCatalog) { self.catalog = catalog } public var body: some View { if let notice = catalog.selectionNotice { Text(notice).font(Typo.secondary).foregroundStyle(Palette.secondary).padding(.horizontal, 16) } if let project = catalog.selection { HStack(spacing: 8) { Image(systemName: "folder") Text(project.displayName).font(Typo.secondaryStrong) Button { catalog.selection = nil } label: { Image(systemName: "xmark").frame(minWidth: 44, minHeight: 44) } .buttonStyle(.plain).accessibilityLabel(EquipoStrings.text("projects.remove_selection")) } .padding(.leading, 12).background(Palette.surface2, in: Capsule()).padding(.horizontal, 16) .frame(maxWidth: .infinity, alignment: .leading) } } }