import SwiftUI import JobleyKit /// Search and the three filters, as on jobley.ai/jobs/. public struct BoardFilters: View { @ObservedObject var board: BoardModel public init(board: BoardModel) { self.board = board } public var body: some View { HStack(spacing: 8) { picker("Any workplace", $board.workplace, Meta.workplaceOrder, board.labels.workplace) picker("Any job type", $board.type, Meta.employmentTypeOrder, board.labels.type) picker("Any category", $board.category, Meta.categoryOrder, board.labels.category) } .onChange(of: board.workplace) { Task { await board.reload() } } .onChange(of: board.type) { Task { await board.reload() } } .onChange(of: board.category) { Task { await board.reload() } } } func picker(_ any: String, _ value: Binding, _ order: [String], _ label: @escaping (String) -> String) -> some View { Menu { Picker(any, selection: value) { Text(any).tag("") ForEach(order, id: \.self) { Text(label($0)).tag($0) } } .pickerStyle(.inline) } label: { HStack(spacing: 4) { Text(value.wrappedValue.isEmpty ? any : label(value.wrappedValue)).lineLimit(1) Image(systemName: "chevron.down").font(.caption2) } .font(.subheadline) .foregroundStyle(value.wrappedValue.isEmpty ? Theme.ink2 : Theme.accent) .padding(.horizontal, 10).padding(.vertical, 6) .overlay(Capsule().strokeBorder(value.wrappedValue.isEmpty ? Theme.line : Theme.accent)) } .menuStyle(.button) .buttonStyle(.plain) .fixedSize() } } /// "Put me forward": for one job or for a kind of job. A person reads it; no software sorts it. public struct PutMeForwardForm: View { let api: APIClient let job: Job? var onDone: () -> Void @State private var draft: CandidateDraft @State private var sending = false @State private var error: APIError? @State private var received: Received? @StateObject private var gate = TurnstileGate() public init(api: APIClient, job: Job?, onDone: @escaping () -> Void) { self.api = api; self.job = job; self.onDone = onDone _draft = State(initialValue: CandidateDraft(jobID: job?.id)) } public var body: some View { if let received { Confirmation(title: received.already == true ? "You're already on our list." : "Thank you. A person will read it.", detail: job.map { "If you're a good fit for “\($0.title)”, we'll introduce you to the people hiring by email." } ?? "When a good job comes in that fits, we'll introduce you by email.", done: onDone) } else { Form { if let job { Section { JobRow(job: job, labels: Labels()) } header: { Text("For this job") } } Section { field("Your name", $draft.name, "name") field("Email", $draft.email, "email") field("Headline, e.g. “Support engineer, six years”", $draft.headline, "headline") field("Where you are (optional)", $draft.location, "location") } header: { Text("About you") } footer: { Text("Private. Only the people hiring see it, and only when we introduce you.") } if job == nil { Section("What you're looking for") { TextField("The kind of job, place and hours", text: $draft.lookingFor, axis: .vertical).lineLimit(2...5) errorText("looking_for") } } Section { TextField("A few lines about your work (optional)", text: $draft.about, axis: .vertical).lineLimit(3...8) TextField("Links to your work, one per line (optional)", text: $draft.links, axis: .vertical).lineLimit(1...5) .autocorrectionDisabled() field("Link to your resume (optional)", $draft.resumeURL, "resume_url") } header: { Text("Your work") } Section { Toggle("I agree that Jobley may share these details with the people hiring when a person introduces me.", isOn: $draft.consent) errorText("consent") if TurnstileGate.isNeeded(for: api.base) { TurnstileView(page: api.turnstilePage, onResult: gate.receive).id(gate.generation) Text(gate.statusText).font(.caption).foregroundStyle(Theme.muted) } if let error { Text(error.message).foregroundStyle(Theme.danger).font(.callout) } Button { Task { await send() } } label: { Text(sending ? "Sending…" : "Put me forward").frame(maxWidth: .infinity) } .buttonStyle(PrimaryButtonStyle()) .disabled(sending || !draft.consent || (TurnstileGate.isNeeded(for: api.base) && !gate.isReady)) .accessibilityIdentifier("putMeForwardSend") } footer: { Text("A person reads every one. Nothing ranks, scores or filters you.") } } .formStyle(.grouped) } } func field(_ title: String, _ text: Binding, _ key: String) -> some View { VStack(alignment: .leading, spacing: 2) { TextField(title, text: text) .autocorrectionDisabled(key == "email" || key == "resume_url") #if os(iOS) .textInputAutocapitalization(key == "email" || key == "resume_url" ? .never : .words) .keyboardType(key == "email" ? .emailAddress : key == "resume_url" ? .URL : .default) #endif errorText(key) } } @ViewBuilder func errorText(_ key: String) -> some View { if let message = error?.fields[key] { Text(message).font(.caption).foregroundStyle(Theme.danger) } } func send() async { sending = true; error = nil defer { sending = false } do { received = try await api.putForward(draft, turnstileToken: gate.token) } catch let failure as APIError { error = failure gate.reset() } catch {} } } /// "Post a job": one form, no account. It waits for a person to read it. public struct PostJobForm: View { let api: APIClient var onDone: () -> Void @State private var draft = JobDraft() @State private var sending = false @State private var error: APIError? @State private var posted: PostedJob? @StateObject private var gate = TurnstileGate() let labels = Labels() public init(api: APIClient, onDone: @escaping () -> Void) { self.api = api; self.onDone = onDone } public var body: some View { if let posted { VStack(alignment: .leading, spacing: 16) { Confirmation(title: "Thank you. Your post is waiting for a person.", detail: "\(HouseRules.guarantee) It's in the review queue as \(posted.id). If it's a good job it will appear on the board. If not, we'll write to you with the reason.", done: onDone) VStack(alignment: .leading, spacing: 6) { Text("Keep this. It's the only way to take the job down yourself when it's filled. We can't show it again.") .font(.callout).foregroundStyle(Theme.ink2) Text(posted.manageToken).font(Theme.mono(12)).textSelection(.enabled) .padding(10).background(Theme.surface2, in: RoundedRectangle(cornerRadius: 8)) Button("Copy the id and token") { Clipboard.copy("\(posted.id)\n\(posted.manageToken)") } } .padding(.horizontal, 24) } } else { Form { Section("The job") { field("Job title", $draft.title, "title") field("Company", $draft.company, "company") field("Company website (optional)", $draft.companyURL, "company_url") choice("Workplace", $draft.workplace, Meta.workplaceOrder, labels.workplace, "workplace") choice("Job type", $draft.employmentType, Meta.employmentTypeOrder, labels.type, "employment_type") choice("Category", $draft.category, Meta.categoryOrder, labels.category, "category") field("Location", $draft.location, "location") } Section { field("Lowest, such as 100", $draft.payMin, "pay_min") field("Highest, such as 140", $draft.payMax, "pay_max") Picker("Per", selection: $draft.payPeriod) { ForEach(Meta.payPeriodOrder, id: \.self) { Text($0).tag($0) } } field("Currency", $draft.payCurrency, "pay_currency") } header: { Text("Pay") } footer: { Text("We publish jobs that pay \(HouseRules.payFloorShort) (or the same in local currency), by the hour or salaried, full or part time, with or without benefits. Give a lowest and a highest figure.") } Section("Description") { TextField("What the person would do, with whom, where and when", text: $draft.description, axis: .vertical).lineLimit(5...14) errorText("description") field("Your own job page (optional)", $draft.applyURL, "apply_url") } Section { field("Your name", $draft.contactName, "contact_name") field("Your email", $draft.contactEmail, "contact_email") } header: { Text("You") } footer: { Text("Private. We use it to reach you about this post and to introduce candidates.") } Section { if TurnstileGate.isNeeded(for: api.base) { TurnstileView(page: api.turnstilePage, onResult: gate.receive).id(gate.generation) Text(gate.statusText).font(.caption).foregroundStyle(Theme.muted) } if let error { Text(error.message).foregroundStyle(Theme.danger).font(.callout) } Button { Task { await send() } } label: { Text(sending ? "Sending…" : "Send for review").frame(maxWidth: .infinity) } .buttonStyle(PrimaryButtonStyle()) .disabled(sending || (TurnstileGate.isNeeded(for: api.base) && !gate.isReady)) } footer: { Text("Free. No account. \(HouseRules.guarantee)") } } .formStyle(.grouped) } } func field(_ title: String, _ text: Binding, _ key: String) -> some View { VStack(alignment: .leading, spacing: 2) { TextField(title, text: text) .autocorrectionDisabled(key.contains("url") || key.contains("email")) #if os(iOS) .textInputAutocapitalization(key.contains("url") || key.contains("email") ? .never : .sentences) .keyboardType(key.hasPrefix("pay_m") ? .numberPad : key.contains("email") ? .emailAddress : key.contains("url") ? .URL : .default) #endif errorText(key) } } func choice(_ title: String, _ value: Binding, _ order: [String], _ label: @escaping (String) -> String, _ key: String) -> some View { VStack(alignment: .leading, spacing: 2) { Picker(title, selection: value) { Text("Choose…").tag("") ForEach(order, id: \.self) { Text(label($0)).tag($0) } } errorText(key) } } @ViewBuilder func errorText(_ key: String) -> some View { if let message = error?.fields[key] { Text(message).font(.caption).foregroundStyle(Theme.danger) } } func send() async { sending = true; error = nil defer { sending = false } if HouseRules.belowPayFloor(min: Int(draft.payMin.filter(\.isNumber)), period: draft.payPeriod, currency: draft.payCurrency) { error = APIError(code: "invalid", message: "Please fix the marked fields.", fields: ["pay_min": HouseRules.payFloorMessage]) return } do { posted = try await api.post(draft, turnstileToken: gate.token) } catch let failure as APIError { error = failure; gate.reset() } catch {} } } struct Confirmation: View { let title: String, detail: String let done: () -> Void var body: some View { VStack(alignment: .leading, spacing: 12) { Image(systemName: "checkmark.seal.fill").font(.system(size: 40)).foregroundStyle(Theme.seal) Text(title).font(Theme.display(26)).foregroundStyle(Theme.ink) Text(detail).foregroundStyle(Theme.ink2) Button("Done", action: done).buttonStyle(PrimaryButtonStyle()) } .padding(24) .frame(maxWidth: .infinity, alignment: .leading) } } public enum Clipboard { public static func copy(_ text: String) { #if os(macOS) NSPasteboard.general.clearContents() NSPasteboard.general.setString(text, forType: .string) #else UIPasteboard.general.string = text #endif } }