Show Active Ticket on Clock Page - #506
Conversation
There was a problem hiding this comment.
Pull request overview
Adds active-ticket visibility to the clock status card.
Changes:
- Fetches and live-updates the running ticket.
- Displays a clickable, truncated ticket badge.
- Shows the plan-required badge when no ticket runs.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🚀 Preview Deployment Ready
Preview auto-deletes when this PR is closed. |
|
Duplicate "running ticket" logic — should be extracted into a shared hook
What to do: export function useRunningTicket(enabled: boolean) {
const [running, setRunning] = useState<{ id: string; title: string; sessionId: string } | null>(null);
const refetch = useCallback(async () => {
if (!localStorage.getItem('meteor_resume_token')) {
setRunning(null);
return;
}
try {
const dayEntries = await timerApi.getToday();
const session = dayEntries.flatMap((de) => de.sessions).find((t) => !t.endTime);
const dayEntry = session && dayEntries.find((de) => de.sessions.some((t) => t.id === session.id));
if (!session || !dayEntry?.entry.ticketId) {
setRunning(null);
return;
}
setRunning({
id: dayEntry.entry.ticketId,
title: dayEntry.entry.displayTitle || dayEntry.entry.ticketId,
sessionId: session.id,
});
} catch {
setRunning(null);
}
}, []);
useEffect(() => {
if (!enabled) {
setRunning(null);
return;
}
void refetch();
const ddp = getDdpClient();
const offChange = ddp.onCollectionChange('timers', () => void refetch());
const unsubscribe = ddp.subscribe('timers.liveForUser', []);
const onRefetch = () => void refetch();
window.addEventListener('work:refetch', onRefetch);
window.addEventListener('tickets:refetch', onRefetch);
return () => {
offChange();
unsubscribe();
window.removeEventListener('work:refetch', onRefetch);
window.removeEventListener('tickets:refetch', onRefetch);
};
}, [enabled, refetch]);
return running;
}How to wire it up:
This also fixes a small existing inconsistency between the two copies: Not a blocker for this PR, but worth a follow-up so we don't end up with a fourth copy the next time a ticket-timer indicator is added elsewhere. |
When clocked in, display a clickable ticket badge if a timer is running; otherwise keep the plan-required badge. Updates live via DDP. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
3952eb2 to
90174d3
Compare
Merge conflict resolved (rebase onto
|
Extract running-ticket lookup into one hook using getRunning + getDay so Clock and Tickets stay consistent across midnight and clear stale state. Co-authored-by: Cursor <cursoragent@cursor.com>
Re: shared `useRunningTicket` (Dharp02’s note)Done in 772b2c2. Extracted `src/lib/useRunningTicket.ts` and wired:
Fetch path uses `getRunning()` + `getDay(session.date)` (not `getToday()`), and clears on missing token / error so Tickets no longer keeps stale running ids. Left `WorkPage` alone — its `timers.liveForUser` wiring is day/week refetch, not “which ticket is running.” @Dharp02 ready for another look when you have a chance. |
|
Re-ran the failed PR Preview Environment job — |
Summary
Fixes #414: the clock status card did not show which ticket was running.
Changes (ClockPage only):
/app/tickets/:idtimerApi.getToday()+ DDPtimers.liveForUserTest plan
Made with Cursor