import SwiftUI import JobleyKit import JobleyUI /// Candidates: per job or "any job", oldest first. People mark them reviewed or declined and make /// introductions themselves. There is no score, rank or match anywhere. struct CandidateList: View { @ObservedObject var desk: DeskModel @ObservedObject var model: CandidatesModel let jobs: [Job] var body: some View { VStack(spacing: 0) { HStack { Picker("Who", selection: $model.scope) { Text("Everyone").tag(CandidatesModel.Scope.everyone) Text("Any job (asked about a kind of job)").tag(CandidatesModel.Scope.anyJob) if !jobs.isEmpty { Divider() } ForEach(jobs) { Text("\($0.title) · \($0.company)").tag(CandidatesModel.Scope.job($0.id)) } } Picker("Status", selection: $model.status) { Text("Any status").tag("") ForEach(["new", "reviewed", "introduced", "declined", "withdrawn"], id: \.self) { Text($0.capitalized).tag($0) } } .frame(width: 150) } .labelsHidden() .padding(10) if model.candidates.isEmpty { StateMessage("No one here yet", detail: "When someone asks to be put forward they appear here, oldest first.", systemImage: "person.2") } else { List(model.candidates, selection: $desk.selectedCandidateID) { person in VStack(alignment: .leading, spacing: 4) { HStack { Text(person.name).font(.headline) Spacer() StatusPill(person.status) } Text(person.headline).font(.subheadline).foregroundStyle(Theme.ink2) Text(person.jobID.flatMap { id in jobs.first { $0.id == id }?.title } ?? (person.jobID == nil ? "Any job" : "A job no longer on the board")) .font(.caption).foregroundStyle(Theme.muted) Text("Asked \(APIDate.short(person.createdAt))").font(.caption2).foregroundStyle(Theme.muted) } .padding(.vertical, 4) .tag(person.id) } } } .navigationTitle("Candidates") .navigationSubtitle("Oldest first") .onChange(of: model.scope) { Task { await model.reload() } } .onChange(of: model.status) { Task { await model.reload() } } .onChange(of: desk.selectedCandidateID) { Task { await model.open(desk.selectedCandidateID) } } .alert("Something went wrong", isPresented: Binding(get: { model.error != nil }, set: { if !$0 { model.error = nil } })) { Button("OK") { model.error = nil } } message: { Text(model.error ?? "") } } } struct CandidateDetailView: View { @ObservedObject var model: CandidatesModel let detail: CandidateDetail let jobs: [Job] @ObservedObject var curator: CuratorModel @State private var introducing = false var person: Candidate { detail.candidate } var body: some View { ScrollView { VStack(alignment: .leading, spacing: 18) { HStack { StatusPill(person.status) Text("Asked \(APIDate.full(person.createdAt))").font(.caption).foregroundStyle(Theme.muted) } Text(person.name).font(Theme.display(28)) Text(person.headline).font(.title3).foregroundStyle(Theme.ink2) HStack(spacing: 10) { Button { introducing = true } label: { Label("Introduce", systemImage: "envelope.badge.person.crop") } .buttonStyle(PrimaryButtonStyle()).disabled(jobs.isEmpty) Button("Mark reviewed") { Task { await model.setStatus(person, "reviewed") } }.buttonStyle(SecondaryButtonStyle()) Button("Decline") { Task { await model.setStatus(person, "declined") } }.buttonStyle(SecondaryButtonStyle()) } GroupBox { VStack(alignment: .leading, spacing: 6) { Text(person.email).textSelection(.enabled) if let location = person.location { Text(location).foregroundStyle(Theme.ink2) } }.frame(maxWidth: .infinity, alignment: .leading) } label: { Label("Private", systemImage: "lock").font(.caption.weight(.semibold)).foregroundStyle(Theme.muted) } if let looking = person.lookingFor { section("Looking for", looking) } if let about = person.about { section("About their work", about) } if !person.links.isEmpty || person.resumeURL != nil { VStack(alignment: .leading, spacing: 6) { Text("Links").font(Theme.display(18)) ForEach(person.links, id: \.self) { link in if let url = URL(string: link) { Link(link, destination: url) } } if let resume = person.resumeURL, let url = URL(string: resume) { Link("Resume", destination: url) } } } if !detail.introductions.isEmpty { VStack(alignment: .leading, spacing: 6) { Text("Introductions").font(Theme.display(18)) ForEach(detail.introductions) { intro in Text("\(jobs.first { $0.id == intro.jobID }?.title ?? intro.jobID) · by \(intro.introducedBy) · \(APIDate.short(intro.createdAt))") .font(.callout) } } } } .padding(28) .frame(maxWidth: 760, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading) } .background(Theme.background) .sheet(isPresented: $introducing) { IntroduceSheet(model: model, person: person, jobs: jobs, curator: curator) } } func section(_ title: String, _ text: String) -> some View { VStack(alignment: .leading, spacing: 6) { Text(title).font(Theme.display(18)) Text(text).textSelection(.enabled).fixedSize(horizontal: false, vertical: true) } } } /// A person writes the introduction: pick the job, write the note, send the mail draft to both /// sides from Mail, then record that it happened. struct IntroduceSheet: View { @ObservedObject var model: CandidatesModel let person: Candidate let jobs: [Job] @ObservedObject var curator: CuratorModel @State private var jobID = "" @State private var note = "" @State private var drafted = false @Environment(\.dismiss) private var dismiss @Environment(\.openURL) private var openURL var body: some View { VStack(alignment: .leading, spacing: 14) { Text("Introduce \(person.name)").font(Theme.display(22)) Picker("Job", selection: $jobID) { Text("Choose a job…").tag("") ForEach(jobs) { Text("\($0.title) · \($0.company)").tag($0.id) } } Text("A few words for both of them").font(.callout).foregroundStyle(Theme.ink2) TextEditor(text: $note).frame(minHeight: 120).scrollContentBackground(.hidden) .padding(6).background(Theme.surface2, in: RoundedRectangle(cornerRadius: 8)) Text("First open the mail draft and send it from Mail. Then record the introduction here.") .font(.caption).foregroundStyle(Theme.muted) HStack { Button("Cancel") { dismiss() } Spacer() Button("Open mail draft") { Task { // The poster's contact is on the admin copy of the job. guard let item = try? await curator.api.reviewItem(jobID), let mail = MailDraft.introduction(candidate: person, job: item.job, note: note) else { return } openURL(mail); drafted = true } } .disabled(jobID.isEmpty) Button("Record introduction") { Task { if await model.introduce(person, jobID: jobID, note: note) { dismiss() } } } .buttonStyle(PrimaryButtonStyle()) .disabled(jobID.isEmpty || !drafted) } } .padding(22) .frame(width: 520) .onAppear { jobID = person.jobID.flatMap { id in jobs.contains { $0.id == id } ? id : nil } ?? "" } } } /// Moderator applications and moderators (curator only). struct ModeratorsView: View { @ObservedObject var model: ModeratorsModel @State private var grantCandidates: Set = [] var body: some View { List { Section("Applications") { if model.applications.isEmpty { Text("No new applications.").foregroundStyle(.secondary) } ForEach(model.applications) { app in VStack(alignment: .leading, spacing: 6) { HStack { Text(app.name).font(.headline) Text(app.email).foregroundStyle(.secondary).textSelection(.enabled) Spacer() Text(APIDate.short(app.createdAt)).font(.caption).foregroundStyle(.secondary) } if let hours = app.hoursPerWeek { Text("\(hours) hours a week\(app.timezone.map { " · \($0)" } ?? "")").font(.caption) } Text(app.why).font(.callout).fixedSize(horizontal: false, vertical: true) if let experience = app.experience { Text(experience).font(.caption).foregroundStyle(Theme.ink2) } HStack { Toggle("Can see candidates", isOn: Binding(get: { grantCandidates.contains(app.id) }, set: { if $0 { grantCandidates.insert(app.id) } else { grantCandidates.remove(app.id) } })) Spacer() Button("Decline") { Task { await model.decline(app) } } Button("Approve") { Task { await model.approve(app, canSeeCandidates: grantCandidates.contains(app.id)) } } .buttonStyle(.borderedProminent) } } .padding(.vertical, 6) } } Section("Moderators") { if model.moderators.isEmpty { Text("No moderators yet.").foregroundStyle(.secondary) } ForEach(model.moderators) { moderator in HStack { VStack(alignment: .leading) { Text(moderator.name).font(.headline) Text(moderator.email).font(.caption).foregroundStyle(.secondary) Text(moderator.lastSeenAt.map { "Last seen \(APIDate.short($0))" } ?? "Not seen yet").font(.caption2).foregroundStyle(.secondary) } Spacer() if moderator.active { Toggle("Candidates", isOn: Binding(get: { moderator.canSeeCandidates }, set: { value in Task { await model.setAccess(moderator, value) } })) Button("Setup link") { Task { await model.makeSetupLink(moderator) } } .help("A new one-time link to add a passkey, for a moderator setting up or one who lost theirs") Button("Revoke", role: .destructive) { Task { await model.revoke(moderator) } } } else { Text("Revoked").foregroundStyle(.secondary) } } } } } .navigationTitle("Moderators") .task { await model.reload() } .sheet(item: $model.newSetupLink) { made in VStack(alignment: .leading, spacing: 14) { Text("A passkey setup link for \(made.name)").font(Theme.display(22)) Text("Send it to them yourself. They open Jobley, choose Add a passkey and paste it. It works once, until \(APIDate.full(made.link.expiresAt)), and we show it only now.") .foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true) Text(made.link.url).font(Theme.mono(12)).textSelection(.enabled).padding(10) .background(Theme.surface2, in: RoundedRectangle(cornerRadius: 8)) HStack { Button("Copy") { Clipboard.copy(made.link.url) } Spacer() Button("Done") { model.newSetupLink = nil }.buttonStyle(PrimaryButtonStyle()) } } .padding(22).frame(width: 480) } } }