Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

fix: automation page issues

Khuram Niaz592783e148ac
diff --git a/src/actions/automation.actions.ts b/src/actions/automation.actions.ts
index 9b50ea1..17bcedb 100644
--- a/src/actions/automation.actions.ts
+++ b/src/actions/automation.actions.ts
@@ -384,6 +384,7 @@ export async function getDiscoveredJobs(options?: {
success: boolean;
data?: DiscoveredJob[];
total?: number;
+ statusCounts?: { new: number; dismissed: number; accepted: number };
message?: string;
}> {
try {
@@ -416,7 +417,11 @@ export async function getDiscoveredJobs(options?: {
where.discoveryStatus = discoveryStatus;
}
- const [jobs, total] = await Promise.all([
+ // Status counts ignore the discoveryStatus filter so callers get the full
+ // per-status breakdown for the whole automation, not just the current page.
+ const { discoveryStatus: _omit, ...countWhere } = where;
+
+ const [jobs, total, grouped] = await Promise.all([
db.job.findMany({
where,
skip,
@@ -432,12 +437,26 @@ export async function getDiscoveredJobs(options?: {
},
}),
db.job.count({ where }),
+ db.job.groupBy({
+ by: ["discoveryStatus"],
+ where: countWhere,
+ _count: true,
+ }),
]);
+ const statusCounts = { new: 0, dismissed: 0, accepted: 0 };
+ for (const g of grouped) {
+ if (g.discoveryStatus && g.discoveryStatus in statusCounts) {
+ statusCounts[g.discoveryStatus as keyof typeof statusCounts] =
+ g._count;
+ }
+ }
+
return {
success: true,
data: jobs as unknown as DiscoveredJob[],
total,
+ statusCounts,
};
} catch (error) {
return formatError(error, "Failed to get discovered jobs");
diff --git a/src/app/dashboard/automations/[id]/page.tsx b/src/app/dashboard/automations/[id]/page.tsx
index 54364aa..8818ce4 100644
--- a/src/app/dashboard/automations/[id]/page.tsx
+++ b/src/app/dashboard/automations/[id]/page.tsx
@@ -73,6 +73,11 @@ export default function AutomationDetailPage() {
);
const [runs, setRuns] = useState<AutomationRun[]>([]);
const [jobs, setJobs] = useState<DiscoveredJob[]>([]);
+ const [jobStatusCounts, setJobStatusCounts] = useState<{
+ new: number;
+ dismissed: number;
+ accepted: number;
+ }>({ new: 0, dismissed: 0, accepted: 0 });
const [loading, setLoading] = useState(true);
const [actionLoading, setActionLoading] = useState(false);
const [runNowLoading, setRunNowLoading] = useState(false);
@@ -126,6 +131,9 @@ export default function AutomationDetailPage() {
if (jobsResult.success && jobsResult.data) {
setJobs(jobsResult.data);
+ if (jobsResult.statusCounts) {
+ setJobStatusCounts(jobsResult.statusCounts);
+ }
}
} catch (error) {
toast({
@@ -190,6 +198,20 @@ export default function AutomationDetailPage() {
};
}, [automationId, runKey]);
+ // When a run is being followed only via the SSE (user navigated away and
+ // back, so runNowLoading is false and the run watcher isn't polling), the
+ // page won't otherwise refresh its tabs when the run ends. Detect the
+ // live->done transition off the stream and reload then.
+ const wasRunningRef = useRef(false);
+ useEffect(() => {
+ if (logData.isRunning) {
+ wasRunningRef.current = true;
+ } else if (wasRunningRef.current) {
+ wasRunningRef.current = false;
+ if (!runNowLoading) loadData();
+ }
+ }, [logData.isRunning, runNowLoading, loadData]);
+
const handleClearLogs = useCallback(async () => {
try {
await fetch(`/api/automations/${automationId}/logs/clear`, {
@@ -198,13 +220,18 @@ export default function AutomationDetailPage() {
} catch (err) {
console.error("Failed to clear server logs:", err);
}
- setLogData({ logs: [], isRunning: false });
+ // Only empty the visible logs; keep isRunning/started/completed so the
+ // "Running" badge survives and the live SSE keeps feeding new logs in.
+ setLogData((prev) => ({ ...prev, logs: [] }));
}, [automationId]);
const refreshJobs = useCallback(async () => {
const jobsResult = await getDiscoveredJobs({ automationId });
if (jobsResult.success && jobsResult.data) {
setJobs(jobsResult.data);
+ if (jobsResult.statusCounts) {
+ setJobStatusCounts(jobsResult.statusCounts);
+ }
}
}, [automationId]);
@@ -349,7 +376,7 @@ export default function AutomationDetailPage() {
if (loading) {
return (
- <div className="container mx-auto py-6">
+ <div className="col-span-3 flex items-center justify-center min-h-[60vh]">
<Loading />
</div>
);
@@ -361,6 +388,10 @@ export default function AutomationDetailPage() {
const resumeMissing = !automation.resume;
const newJobsCount = jobs.filter((j) => j.discoveryStatus === "new").length;
+ // The button must reflect the real run state, not just this page instance's
+ // runNowLoading: after navigating away and back, runNowLoading resets but the
+ // SSE reports the run is still live, so fall back to logData.isRunning.
+ const runActive = runNowLoading || logData.isRunning;
return (
<div className="col-span-3 py-6 space-y-6">
@@ -398,7 +429,7 @@ export default function AutomationDetailPage() {
)}
{automation.status === "active" ? "Pause" : "Resume"}
</Button>
- {runNowLoading ? (
+ {runActive ? (
<Button
variant="destructive"
onClick={() => setAbortConfirmOpen(true)}
@@ -530,6 +561,8 @@ export default function AutomationDetailPage() {
<TabsContent value="jobs" className="mt-4">
<DiscoveredJobsList
jobs={jobs}
+ dismissedCount={jobStatusCounts.dismissed}
+ newCount={jobStatusCounts.new}
automationId={automationId}
onRefresh={loadData}
onViewDetails={handleViewJobDetails}
diff --git a/src/components/automations/DiscoveredJobDetail.tsx b/src/components/automations/DiscoveredJobDetail.tsx
index f479828..cf07246 100644
--- a/src/components/automations/DiscoveredJobDetail.tsx
+++ b/src/components/automations/DiscoveredJobDetail.tsx
@@ -58,67 +58,67 @@ export function DiscoveredJobDetail({
const handleAnalyze = async () => {
setLoadingAction("analyze");
- const result = await analyzeDiscoveredJob(job.id);
- setLoadingAction(null);
-
- if (result.success) {
- toast({ title: "Match analyzed", description: "AI match score is ready." });
- onOpenChange(false);
- onRefresh();
- } else {
- toast({
- title: "Error",
- description: result.message,
- variant: "destructive",
- });
+ try {
+ const result = await analyzeDiscoveredJob(job.id);
+ if (result.success) {
+ toast({ title: "Match analyzed", description: "AI match score is ready." });
+ onOpenChange(false);
+ onRefresh();
+ } else {
+ toast({
+ title: "Error",
+ description: result.message,
+ variant: "destructive",
+ });
+ }
+ } catch {
+ toast({ title: "Error", description: "Failed to analyze job", variant: "destructive" });
+ } finally {
+ setLoadingAction(null);
}
};
const handleAccept = async () => {
setLoadingAction("accept");
- if (!analyzed) {
- const analysis = await analyzeDiscoveredJob(job.id);
- if (!analysis.success) {
- setLoadingAction(null);
+ try {
+ const result = await acceptDiscoveredJob(job.id);
+ if (result.success) {
+ toast({ title: "Job accepted", description: "The job has been added to your tracked jobs." });
+ onOpenChange(false);
+ onRefresh();
+ } else {
toast({
title: "Error",
- description: analysis.message,
+ description: result.message,
variant: "destructive",
});
- return;
}
- }
- const result = await acceptDiscoveredJob(job.id);
- setLoadingAction(null);
-
- if (result.success) {
- toast({ title: "Job accepted", description: "The job has been added to your tracked jobs." });
- onOpenChange(false);
- onRefresh();
- } else {
- toast({
- title: "Error",
- description: result.message,
- variant: "destructive",
- });
+ } catch {
+ toast({ title: "Error", description: "Failed to accept job", variant: "destructive" });
+ } finally {
+ setLoadingAction(null);
}
};
const handleDismiss = async () => {
setLoadingAction("dismiss");
- const result = await dismissDiscoveredJob(job.id);
- setLoadingAction(null);
-
- if (result.success) {
- toast({ title: "Job dismissed" });
- onOpenChange(false);
- onRefresh();
- } else {
- toast({
- title: "Error",
- description: result.message,
- variant: "destructive",
- });
+ try {
+ const result = await dismissDiscoveredJob(job.id);
+ if (result.success) {
+ toast({ title: "Job dismissed" });
+ onOpenChange(false);
+ onRefresh();
+ } else {
+ toast({
+ title: "Error",
+ description: result.message,
+ variant: "destructive",
+ });
+ }
+ } catch {
+ toast({ title: "Error", description: "Failed to dismiss job", variant: "destructive" });
+ } finally {
+ setLoadingAction(null);
}
};
diff --git a/src/components/automations/DiscoveredJobsList.tsx b/src/components/automations/DiscoveredJobsList.tsx
index 8ab78a5..af8765f 100644
--- a/src/components/automations/DiscoveredJobsList.tsx
+++ b/src/components/automations/DiscoveredJobsList.tsx
@@ -74,11 +74,14 @@ function getPrerankPercent(job: DiscoveredJob): number | null {
interface DiscoveredJobsListProps {
jobs: DiscoveredJob[];
+ // Full per-status counts for the automation (not just the loaded page), so
+ // the clear dialog matches what clearDiscoveredJobs actually deletes.
+ dismissedCount: number;
+ newCount: number;
automationId: string;
onRefresh: () => void;
onViewDetails?: (job: DiscoveredJob) => void;
- // True while an automation run is in flight. LLM-triggering actions (Analyze,
- // Accept of un-analyzed jobs) are blocked to avoid concurrent model calls.
+ // True while an automation run is in flight. The Analyze button is blocked to avoid concurrent LLM calls.
runInProgress?: boolean;
// Reports whether a per-job LLM action is in flight so the parent can block
// starting a new run while a single-job analysis is still processing.
@@ -87,6 +90,8 @@ interface DiscoveredJobsListProps {
export function DiscoveredJobsList({
jobs,
+ dismissedCount,
+ newCount,
automationId,
onRefresh,
onViewDetails,
@@ -102,11 +107,6 @@ export function DiscoveredJobsList({
onBusyChange?.(loadingAction !== null);
}, [loadingAction, onBusyChange]);
- const dismissedCount = jobs.filter(
- (j) => j.discoveryStatus === "dismissed",
- ).length;
- const newCount = jobs.filter((j) => j.discoveryStatus === "new").length;
-
// Analyzed-first, then by matchScore desc (un-analyzed sort by their lexical
// matchScore value). The analyzed flag lives in matchData JSON, so sort in JS.
const sortedJobs = useMemo(() => {
@@ -120,66 +120,64 @@ export function DiscoveredJobsList({
const handleAnalyze = async (jobId: string) => {
setLoadingAction(jobId);
- const result = await analyzeDiscoveredJob(jobId);
- setLoadingAction(null);
-
- if (result.success) {
- toast({ title: "Match analyzed", description: "AI match score is ready." });
- onRefresh();
- } else {
- toast({
- title: "Error",
- description: result.message,
- variant: "destructive",
- });
+ try {
+ const result = await analyzeDiscoveredJob(jobId);
+ if (result.success) {
+ toast({ title: "Match analyzed", description: "AI match score is ready." });
+ onRefresh();
+ } else {
+ toast({
+ title: "Error",
+ description: result.message,
+ variant: "destructive",
+ });
+ }
+ } catch {
+ toast({ title: "Error", description: "Failed to analyze job", variant: "destructive" });
+ } finally {
+ setLoadingAction(null);
}
};
const handleAccept = async (job: DiscoveredJob) => {
setLoadingAction(job.id);
- // Un-analyzed listings are analyzed first so they reach the jobs board with
- // a real AI score, never the internal lexical number.
- if (!isAnalyzed(job)) {
- const analysis = await analyzeDiscoveredJob(job.id);
- if (!analysis.success) {
- setLoadingAction(null);
+ try {
+ const result = await acceptDiscoveredJob(job.id);
+ if (result.success) {
+ toast({ title: "Job accepted", description: "The job has been added to your tracked jobs." });
+ onRefresh();
+ } else {
toast({
title: "Error",
- description: analysis.message,
+ description: result.message,
variant: "destructive",
});
- return;
}
- }
- const result = await acceptDiscoveredJob(job.id);
- setLoadingAction(null);
-
- if (result.success) {
- toast({ title: "Job accepted", description: "The job has been added to your tracked jobs." });
- onRefresh();
- } else {
- toast({
- title: "Error",
- description: result.message,
- variant: "destructive",
- });
+ } catch {
+ toast({ title: "Error", description: "Failed to accept job", variant: "destructive" });
+ } finally {
+ setLoadingAction(null);
}
};
const handleDismiss = async (jobId: string) => {
setLoadingAction(jobId);
- const result = await dismissDiscoveredJob(jobId);
- setLoadingAction(null);
-
- if (result.success) {
- toast({ title: "Job dismissed" });
- onRefresh();
- } else {
- toast({
- title: "Error",
- description: result.message,
- variant: "destructive",
- });
+ try {
+ const result = await dismissDiscoveredJob(jobId);
+ if (result.success) {
+ toast({ title: "Job dismissed" });
+ onRefresh();
+ } else {
+ toast({
+ title: "Error",
+ description: result.message,
+ variant: "destructive",
+ });
+ }
+ } catch {
+ toast({ title: "Error", description: "Failed to dismiss job", variant: "destructive" });
+ } finally {
+ setLoadingAction(null);
}
};
@@ -369,12 +367,7 @@ export function DiscoveredJobsList({
size="sm"
variant="outline"
onClick={() => handleAccept(job)}
- disabled={isLoading || (runInProgress && !analyzed)}
- title={
- runInProgress && !analyzed
- ? "A run is in progress. Wait until it completes."
- : undefined
- }
+ disabled={isLoading}
>
{isLoading ? (
<Loader2 className="h-4 w-4 animate-spin" />
@@ -409,10 +402,10 @@ export function DiscoveredJobsList({
<AlertDialogHeader>
<AlertDialogTitle>Clear discovered jobs?</AlertDialogTitle>
<AlertDialogDescription>
- Accepted jobs are always kept. This permanently deletes{" "}
- {dismissedCount} dismissed job(s)
+ Accepted jobs are always kept. This permanently deletes all
+ dismissed jobs
{clearIncludeNew && newCount > 0
- ? ` and ${newCount} unreviewed new job(s)`
+ ? " and all unreviewed new jobs"
: ""}
. This action cannot be undone.
</AlertDialogDescription>
diff --git a/src/components/automations/LogsTab.tsx b/src/components/automations/LogsTab.tsx
index 7ce3177..9952301 100644
--- a/src/components/automations/LogsTab.tsx
+++ b/src/components/automations/LogsTab.tsx
@@ -5,6 +5,17 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Button } from "@/components/ui/button";
+import { buttonVariants } from "@/components/ui/button";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog";
import {
AlertCircle,
CheckCircle2,
@@ -29,6 +40,7 @@ interface LogsTabProps {
export function LogsTab({ logData, onClearLogs }: LogsTabProps) {
const [filter, setFilter] = useState<LogLevel | "all">("all");
+ const [clearConfirmOpen, setClearConfirmOpen] = useState(false);
const filteredLogs =
filter === "all"
@@ -51,13 +63,13 @@ export function LogsTab({ logData, onClearLogs }: LogsTabProps) {
const getLevelColor = (level: LogLevel) => {
switch (level) {
case "info":
- return "text-blue-600";
+ return "text-blue-600 dark:text-blue-400";
case "success":
- return "text-green-600";
+ return "text-green-600 dark:text-green-400";
case "warning":
- return "text-amber-600";
+ return "text-amber-600 dark:text-amber-400";
case "error":
- return "text-red-600";
+ return "text-red-600 dark:text-red-400";
}
};
@@ -120,7 +132,7 @@ export function LogsTab({ logData, onClearLogs }: LogsTabProps) {
<Button
size="sm"
variant="outline"
- onClick={onClearLogs}
+ onClick={() => setClearConfirmOpen(true)}
disabled={logData.logs.length === 0}
>
<Trash2 className="h-4 w-4" />
@@ -187,6 +199,31 @@ export function LogsTab({ logData, onClearLogs }: LogsTabProps) {
)}
</ScrollArea>
</CardContent>
+
+ <AlertDialog open={clearConfirmOpen} onOpenChange={setClearConfirmOpen}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Clear logs?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This will permanently remove all current logs. This action cannot
+ be undone.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ className={buttonVariants({ variant: "destructive" })}
+ onClick={(e) => {
+ e.preventDefault();
+ setClearConfirmOpen(false);
+ onClearLogs();
+ }}
+ >
+ Clear logs
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
</Card>
);
}
diff --git a/src/lib/automation-logger.ts b/src/lib/automation-logger.ts
index ec25ca9..d255abd 100644
--- a/src/lib/automation-logger.ts
+++ b/src/lib/automation-logger.ts
@@ -102,6 +102,14 @@ class AutomationLoggerService {
}
clearLogs(automationId: string): void {
+ const store = this.logStores.get(automationId);
+ // Don't drop the store mid-run: the runner keeps writing to it, and a
+ // deleted store means every later log is discarded ("No store found").
+ // Clearing during a run just empties the visible log buffer.
+ if (store?.isRunning) {
+ store.logs = [];
+ return;
+ }
this.logStores.delete(automationId);
}