DEV Community

Cover image for Kagelin v1.54.0: a keyboard-first focus timer and pickers that survive midnight
Achyuth S
Achyuth S

Posted on AI-assisted

Kagelin v1.54.0: a keyboard-first focus timer and pickers that survive midnight

Kagelin is a local-first task, habit and calendar app built on Next.js 16 with Supabase for sync. v1.54.0 removes friction from three common actions: starting a focus session, picking a date, and editing offline. Most of the work is only visible when it is missing.

Three changes are worth a closer look.

Focus mode should behave like a timer, not a page

The focus screen used to have one large play button and a lot of empty space. It now has a full shortcut set, handled by one window-level listener:

if (e.code === "Space" || e.key === " ") {
  e.preventDefault();
  if (state.isRunning) pause();
  else start();
  return;
}

if (e.key.toLowerCase() === "s" && !e.shiftKey) {
  e.preventDefault();
  skip();
  return;
}

if (e.key.toLowerCase() === "r" && e.shiftKey && isSessionActive) {
  e.preventDefault();
  setStopConfirmOpen(true);
  return;
}

if (e.key === "," && !e.shiftKey) {
  e.preventDefault();
  setSettingsOpen(true);
}
Enter fullscreen mode Exit fullscreen mode

The handler bails out when focus is inside an input, textarea, select, or contenteditable, and when a dialog or popover is open. Space also yields to a focused button so it does not double-fire. The rest is conventional: s skips, Shift+R opens a stop confirmation, , opens settings, Esc leaves focus mode.
Kagelin focus mode at rest, with a 25:00 timer, session count, and the Space to start hint

The bigger bug was how the timer calculated its total duration. Progress was computed from the current settings:

const totalSeconds = {
  focus: settings.focusDuration,
  shortBreak: settings.shortBreakDuration,
  longBreak: settings.longBreakDuration,
}[state.mode] * 60;
Enter fullscreen mode Exit fullscreen mode

That works until someone changes the focus duration while a session is paused. The finish line moves, the progress bar jumps, and a paused session can look like it has more time left than it started with. The store now stamps the session length when the session starts:

sessionDurationSeconds:
  s.state.sessionDurationSeconds ??
  getDurationForMode(s.state.mode, s.settings),
Enter fullscreen mode Exit fullscreen mode

and every consumer reads that stamp:

const totalSeconds =
  state.sessionDurationSeconds ?? getDurationForMode(state.mode, settings);

const isPausedMidSession =
  !state.isRunning &&
  (state.sessionDurationSeconds != null ||
    state.remainingSeconds < totalSeconds);
Enter fullscreen mode Exit fullscreen mode

Settings changes now only adjust the displayed duration when the timer is genuinely idle. A paused mid-session timer keeps its original length, shows a PAUSED badge, and gets a muted progress fill instead of the brand colour.

The countdown also moved into the tab title. Running sessions show the remaining time and mode; paused sessions get a prefix:

if (isPausedMidSession) {
  document.title = `Paused (${formatMmSs(state.remainingSeconds)}) · Kagelin`;
}
Enter fullscreen mode Exit fullscreen mode

The tab title makes the timer usable from another tab. Accessibility was the bigger gap: the old screen had no live region, so a screen reader user could not tell when a session started or when five minutes remained. There is now a polite live region that announces start, pause, five minutes left, one minute left, and completion. It deliberately does not announce every tick.

Timer settings dialog with the animated Keep, Pause, Reset pill under On task switch

A date picker should not make you choose a date before choosing a time

The old picker disabled the Time tab until a date was selected. That is backwards for the common case: you know you want 3pm, and the date is the easy part. The Time tab is now always available, and opening it without a date defaults to noon today:

if (nextStep === "time" && !tempDate) {
  const todayNoon = new Date();
  todayNoon.setHours(12, 0, 0, 0);
  setTempDate(todayNoon);
}
Enter fullscreen mode Exit fullscreen mode

The date step also gained four presets in a 2x2 grid, each with the weekday or time printed on the button: Today, Tomorrow, Next Week, Evening. The hint is generated, not hard-coded, so it stays correct as the week rolls over:

{ label: "Today", hint: format(new Date(), "EEE"), onClick: ... },
{ label: "Tomorrow", hint: format(addDays(new Date(), 1), "EEE"), onClick: ... },
{ label: "Next Week", hint: format(addDays(new Date(), 7), "EEE"), onClick: ... },
{ label: "Evening", hint: "6pm", onClick: ... },
Enter fullscreen mode Exit fullscreen mode

Task detail panel with the due date wizard open, showing the calendar and the four preset buttons

On phones, the calendar event editor now uses a responsive dialog instead of a popover. The same DateTimeWizard component renders in both, but the mobile path gets a bottom sheet with a real title for assistive tech. A popover anchored to a field near the bottom of a phone viewport fights the virtual keyboard. The sheet does not.
Mobile date and time bottom sheet with the calendar and Today, Tomorrow, Next Week, Evening presets

Two smaller correctness fixes came with it. Changing an event's start date now preserves its duration instead of resetting the end to an hour later. And an end date before the start is clamped at submit time, so a bad range cannot be saved:

const clampedEndDate =
  safeEndDate.getTime() < safeStartDate.getTime()
    ? getDefaultEndDate(safeStartDate)
    : safeEndDate;
Enter fullscreen mode Exit fullscreen mode

The time picker itself was rebuilt around accessible spinbuttons. Arrow keys increment and decrement hours and minutes, typing a digit moves focus between fields, and AM/PM is a real focus target. The old control was two styled boxes that looked like inputs but were not.

Offline replay needs order and identity

The offline queue was the least visible change and the one most likely to lose data. Mutations were persisted and replayed as a loose pool. A create and an edit of the same row could run in either order, so the edit could hit a row that did not exist yet, or the create could overwrite the edit.

TanStack Query already has the primitive for this: mutation scopes. Each mutation now declares a scope, and replays within a scope are serialized:

client.setMutationDefaults(["createTask"], {
  mutationFn: taskMutations.create,
  scope: { id: "tasks" },
});
Enter fullscreen mode Exit fullscreen mode

The same is done for habits and calendar events. Creates also stamp a stable client ID at the moment the user acts, not when the network returns:

const tempId = input._clientId || crypto.randomUUID();
input._clientId = tempId;
Enter fullscreen mode Exit fullscreen mode

That ID is reused as the row ID, so a retried create is idempotent. Without it, a create that succeeded on the server but failed on the response would be retried and produce a duplicate.

The second bug was dates. Habit start dates used to be filled in inside the mutation function:

start_date: input.start_date || new Date().toISOString().split("T")[0]
Enter fullscreen mode Exit fullscreen mode

Two problems. toISOString() is UTC, so a local evening in a negative-offset timezone can already be tomorrow in UTC. And the value was computed at replay time, so a habit created at 23:55 and replayed at 00:05 got the wrong day even in UTC. The date is now captured when the mutation is enqueued, using the local calendar:

const today = format(new Date(), "yyyy-MM-dd");
input.start_date = input.start_date ?? today;
Enter fullscreen mode Exit fullscreen mode

Tasks, habits, habit entries and calendar events all have regression tests that create and edit offline, cross midnight, reconnect, and assert the original local date survived. The tests matter as much as the fix. The next person to touch the queue will otherwise reintroduce the bug.

Smaller changes

Vim selection used to be a border that vanished against some surfaces. It is now an inset ring plus a lighter row background, applied consistently to list rows and board cards.
Task list with a keyboard-selected row showing the new inset ring

There is a branded 404 page instead of the framework default (but needs more work), and production responses now send Strict-Transport-Security: max-age=63072000; includeSubDomains. Telemetry consent and any queued events are cleared on sign-out and account switch, so a shared device does not inherit the previous person's choice.

Kagelin branded 404 page with the ERR-404 label and a Go home button

Try to break it

The focus shortcuts are the part I most want stress-tested: Space while a button is focused, s inside an input, Esc with a dialog open, a paused session across a reload. The offline queue is the other: create something offline, edit it, cross midnight, reconnect. If the order or the date is wrong, I want the reproduction.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The offline queue fix is the part I'd steal first — stamping a stable client ID at creation and reusing it as the row ID so a retried create is idempotent is the kind of detail that only shows up after real data loss. The UTC habit-date bug is a classic too: toISOString() quietly moving a local evening into tomorrow is exactly the sort of thing that erodes trust in a habit app. Same with the paused timer's finish line moving when settings change — a timer that lies about its own end time is worse than one that crashes. The keyboard-first focus mode is a nice touch, but the offline correctness is the real story here. Of the two stress tests you listed, which one scares you more — the focus shortcuts, or the offline queue?