Files
nucleic-remote-ios/NucleicRemote/NucleicRemote/Views/ProjectsView.swift
T

85 lines
3.6 KiB
Swift

import SwiftUI
import NucleicProtocol
/// Projects overview (mirrors the Mac's per-project pages): each project with its session
/// counts; tap through to that project's sessions + a scoped composer.
struct ProjectsView: View {
@EnvironmentObject var store: RemoteStore
var body: some View {
NavigationStack {
Group {
if store.dashboard.projects.isEmpty {
ContentUnavailableView("No projects", systemImage: "folder",
description: Text("Add a project on the Mac to see it here."))
} else {
List(store.dashboard.projects) { project in
NavigationLink {
ProjectDetailView(project: project)
} label: {
HStack(spacing: 12) {
Image(systemName: "folder.fill").foregroundStyle(Palette.accent)
VStack(alignment: .leading, spacing: 2) {
Text(project.name).font(.body.weight(.medium))
Text(project.defaultBranch).font(.caption).foregroundStyle(.secondary)
}
Spacer()
if project.activeCount > 0 {
Text("\(project.activeCount) active")
.font(.caption2.bold())
.padding(.horizontal, 7).padding(.vertical, 3)
.background(Palette.active.opacity(0.18), in: Capsule())
.foregroundStyle(Palette.active)
}
Text("\(project.sessionCount)").foregroundStyle(.secondary)
}
}
}
}
}
.navigationTitle("Projects")
.refreshable { store.refreshSessions() }
}
}
}
struct ProjectDetailView: View {
@EnvironmentObject var store: RemoteStore
let project: WireProject
@State private var draft = ""
private var sessions: [WireSessionSummary] {
store.liveSessions
.filter { $0.projectID == project.id.rawValue }
.sorted { StatusStyle.sortRank($0) < StatusStyle.sortRank($1) }
}
var body: some View {
List {
Section {
HStack(alignment: .bottom, spacing: 8) {
TextField("Start a chat in \(project.name)…", text: $draft, axis: .vertical)
.textFieldStyle(.roundedBorder).lineLimit(1...4)
Button {
store.startChat(in: project.id, message: draft)
draft = ""
} label: { Image(systemName: "arrow.up.circle.fill").font(.title2) }
.disabled(draft.trimmingCharacters(in: .whitespaces).isEmpty || !store.canControl)
}
}
Section("Sessions") {
if sessions.isEmpty {
Text("No sessions yet.").foregroundStyle(.secondary)
}
ForEach(sessions, id: \.sessionID) { summary in
NavigationLink {
SessionDetailView(sessionID: summary.sessionID)
} label: { SessionRow(summary: summary, showProjectName: false) }
}
}
}
.navigationTitle(project.name)
.navigationBarTitleDisplayMode(.inline)
}
}