Files
jobtrackingapp/job-tracker-ui/src/jobsQuery.ts
T
2026-09-29 17:26:08 +02:00

24 lines
1.3 KiB
TypeScript

// The existing Jobs URL vocabulary, shared by the separate Table and Board routes.
// Pagination is Table-only; neither view may reinterpret the logical filters.
export type JobSortKey = "dateApplied" | "company" | "jobTitle" | "status" | "daysSince" | "location";
export type ReadinessFilter = "all" | "needs-work" | "interview";
const sortKeys: JobSortKey[] = ["dateApplied", "company", "jobTitle", "status", "daysSince", "location"];
export function jobsQueryFromSearch(search: string) {
const query = new URLSearchParams(search);
const company = Number(query.get("companyId"));
const readiness = query.get("readiness");
const sort = query.get("sortBy") as JobSortKey | null;
return {
q: query.get("q") ?? "",
status: query.get("status") || "All",
companyId: Number.isInteger(company) && company > 0 ? company : undefined,
location: query.get("location") ?? "",
needsFollowUp: query.get("needsFollowUp") === "1",
readiness: readiness === "needs-work" || readiness === "interview" ? readiness as Exclude<ReadinessFilter, "all"> : undefined,
includeDeleted: query.get("includeDeleted") === "1",
sortBy: sort && sortKeys.includes(sort) ? sort : "dateApplied" as JobSortKey,
sortDir: query.get("sortDir") === "asc" ? "asc" as const : "desc" as const,
};
}