@devries-cameron20 / t3code Mirror · read-only / commits / c3858bf1f7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 13:15 UTC

fix(web): snooze options sort soonest first, fit 2 digits, and link from custom snooze (#26427)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 28, 2026 at 04:05 UTC c3858bf1f70a1a16a3582ff870307c55b358b5c3
4 files changed +117 -15
apps/web/src/components/CustomSnoozeDialog.tsx
+18 -1
@@ -1,4 +1,5 @@
1 import { useEffect, useId, useState } from "react";
2 +import { useNavigate } from "@tanstack/react-router";
3 import { create } from "zustand";
4 import {
5 localSnoozeDate,
@@ -7,7 +8,7 @@ import {
8 type CustomSnoozeInput,
9 } from "@t3tools/client-runtime/state/thread-settled";
10 import { Button } from "./ui/button";
10 -import { CalendarIcon } from "lucide-react";
11 +import { CalendarIcon, Settings2Icon } from "lucide-react";
12 import { Calendar } from "./ui/calendar";
13 import { weekStartsOn } from "../timestampFormat";
14 import { useNowMinute } from "../hooks/useNowMinute";
@@ -63,6 +64,7 @@ export function CustomSnoozeDialogHost() {
64
65 function CustomSnoozeDialog() {
66 const id = useId();
67 + const navigate = useNavigate();
68 const [initial] = useState(() => new Date(Date.now() + 3_600_000));
69 const nowMinute = useNowMinute();
70 // Follows the clock so a dialog left open past midnight stops offering yesterday.
@@ -225,6 +227,21 @@ function CustomSnoozeDialog() {
227 )}
228 </DialogPanel>
229 <DialogFooter>
230 + <Button
231 + type="button"
232 + variant="ghost-muted"
233 + className="sm:mr-auto"
234 + onClick={() => {
235 + finish(null);
236 + void navigate({
237 + to: "/settings/threads",
238 + hash: "snooze-options",
239 + });
240 + }}
241 + >
242 + <Settings2Icon />
243 + Edit snooze options
244 + </Button>
245 <Button type="button" variant="outline" onClick={() => finish(null)}>
246 Cancel
247 </Button>
apps/web/src/components/settings/SnoozePresetsSettings.logic.test.ts
+19 -1
@@ -1,6 +1,6 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { reconcileSnoozeDraft } from "./SnoozePresetsSettings.logic";
3 +import { reconcileSnoozeDraft, sortSnoozeRows } from "./SnoozePresetsSettings.logic";
4
5 describe("reconcileSnoozeDraft", () => {
6 it("keeps the draft while our own writes echo back in order", () => {
@@ -18,3 +18,21 @@ describe("reconcileSnoozeDraft", () => {
18 expect(reconcileSnoozeDraft(["a", "b", "a"], "b")).toEqual({ adopt: false, pending: ["a"] });
19 });
20 });
21 +
22 +describe("sortSnoozeRows", () => {
23 + it("orders rows by wake time and puts a passed today option last", () => {
24 + // 16:00 local, so 20 hours wakes tomorrow and today 09:00 has passed.
25 + const now = new Date(2026, 9, 28, 16, 0);
26 + const sorted = sortSnoozeRows(
27 + [
28 + { kind: "after", minutes: 20 * 60 },
29 + { kind: "at", day: "today", time: "09:00" },
30 + { kind: "at", day: "today", time: "18:00" },
31 + { kind: "after", minutes: 60 },
32 + ],
33 + ["20h", "passed", "evening", "1h"],
34 + now,
35 + );
36 + expect(sorted.keys).toEqual(["1h", "evening", "20h", "passed"]);
37 + });
38 +});
apps/web/src/components/settings/SnoozePresetsSettings.logic.ts
+25
@@ -1,3 +1,5 @@
1 +import type { SnoozePresetSetting } from "@t3tools/contracts/settings";
2 +import { resolveSnoozePreset } from "@t3tools/client-runtime/state/thread-settled";
3 import * as Equal from "effect/Equal";
4
5 /**
@@ -13,3 +15,26 @@ export function reconcileSnoozeDraft<T>(
15 ? { adopt: true }
16 : { adopt: false, pending: pending.slice(acknowledged + 1) };
17 }
18 +
19 +/**
20 + * Orders editor rows the way the menu lists them: soonest wake first, with options that
21 + * have no wake right now (a passed "Today") last. Ties keep their current order.
22 + */
23 +export function sortSnoozeRows<K>(
24 + presets: ReadonlyArray<SnoozePresetSetting>,
25 + keys: ReadonlyArray<K>,
26 + now: Date,
27 +): { readonly presets: ReadonlyArray<SnoozePresetSetting>; readonly keys: ReadonlyArray<K> } {
28 + const order = presets
29 + .map((preset, index) => ({
30 + index,
31 + wake: resolveSnoozePreset(preset, now)?.snoozedUntil ?? null,
32 + }))
33 + .toSorted((a, b) =>
34 + a.wake === b.wake ? 0 : a.wake === null ? 1 : b.wake === null ? -1 : a.wake < b.wake ? -1 : 1,
35 + );
36 + return {
37 + presets: order.map(({ index }) => presets[index]!),
38 + keys: order.map(({ index }) => keys[index]!),
39 + };
40 +}
apps/web/src/components/settings/SnoozePresetsSettings.tsx
+55 -13
@@ -16,7 +16,7 @@ import * as Schema from "effect/Schema";
16 import { PlusIcon, XIcon } from "lucide-react";
17
18 import { useNowMinute } from "../../hooks/useNowMinute";
19 -import { reconcileSnoozeDraft } from "./SnoozePresetsSettings.logic";
19 +import { reconcileSnoozeDraft, sortSnoozeRows } from "./SnoozePresetsSettings.logic";
20 import { formatShortTimestamp } from "../../timestampFormat";
21 import { Button } from "../ui/button";
22 import { Input } from "../ui/input";
@@ -90,6 +90,16 @@ function nextCandidate(presets: ReadonlyArray<SnoozePresetSetting>): SnoozePrese
90 );
91 }
92
93 +// Row order is only display order, so it does not make a list differ from the defaults.
94 +function sameSnoozePresets(
95 + left: ReadonlyArray<SnoozePresetSetting>,
96 + right: ReadonlyArray<SnoozePresetSetting>,
97 +) {
98 + const ids = (presets: ReadonlyArray<SnoozePresetSetting>) =>
99 + presets.map(snoozePresetId).toSorted();
100 + return Equal.equals(ids(left), ids(right));
101 +}
102 +
103 const isSnoozePresetDay = Schema.is(SnoozePresetDay);
104
105 interface KindMemory {
@@ -109,16 +119,28 @@ function withWhen(
119 return { kind: "at", day: when, time: preset.kind === "at" ? preset.time : memory.time };
120 }
121
112 -/** Edits the snooze menu's options. Menus sort them by wake time, so rows keep the order they were added in. */
122 +/**
123 + * Edits the snooze menu's options. Rows sort by wake time like the menu, but only when focus
124 + * leaves the list, so a row never moves under the pointer mid-edit.
125 + */
126 export function SnoozePresetsRow() {
127 const settings = useScopedSettings();
128 const updateSettings = useUpdateScopedSettings();
129 const saved = settings.snoozePresets;
130 + const nowMinute = useNowMinute();
131 + const now = new Date(`${nowMinute}Z`);
132 // Edits build on a local draft, so a second edit before the first save echoes back
133 // does not restore what the first one changed. Echoes of our own writes keep the draft.
119 - const [presets, setPresets] = useState(saved);
120 - // Row keys survive removals, so a row's in-progress field state stays with that row.
121 - const [keys, setKeys] = useState<ReadonlyArray<number>>(() => saved.map((_, index) => index));
134 + // Row keys survive removals and sorts, so a row's in-progress field state stays with it.
135 + // One state, so a sort queued in the same event as an edit applies on top of it.
136 + const [rows, setRows] = useState(() =>
137 + sortSnoozeRows(
138 + saved,
139 + saved.map((_, index) => index),
140 + now,
141 + ),
142 + );
143 + const { presets, keys } = rows;
144 const [nextKey, setNextKey] = useState(saved.length);
145 // Null forces the next render to adopt the saved value, as after a failed write.
146 const [savedSource, setSavedSource] = useState<ReadonlyArray<SnoozePresetSetting> | null>(saved);
@@ -134,8 +156,7 @@ export function SnoozePresetsRow() {
156 const reconciled = reconcileSnoozeDraft(written, saved);
157 if (reconciled.adopt) {
158 setWritten([]);
137 - setPresets(saved);
138 - setKeys(freshKeys(saved.length));
159 + setRows(sortSnoozeRows(saved, freshKeys(saved.length), now));
160 } else {
161 setWritten(reconciled.pending);
162 }
@@ -145,8 +166,7 @@ export function SnoozePresetsRow() {
166 nextKeys: ReadonlyArray<number> = keys,
167 ) => {
168 if (!mixed && Equal.equals(snoozePresets, presets)) return;
148 - setPresets(snoozePresets);
149 - setKeys(nextKeys);
169 + setRows({ presets: snoozePresets, keys: nextKeys });
170 setWritten((previous) => [...previous, snoozePresets]);
171 updateSettings(
172 { snoozePresets },
@@ -168,10 +188,17 @@ export function SnoozePresetsRow() {
188 {...searchableSetting("snooze-options")}
189 description="Choices in every snooze menu, listed soonest first. Weekdays mean the next one after today."
190 resetAction={
171 - !mixed && Equal.equals(presets, DEFAULT_SNOOZE_PRESETS) ? null : (
191 + !mixed && sameSnoozePresets(presets, DEFAULT_SNOOZE_PRESETS) ? null : (
192 <SettingResetButton
193 label="snooze options"
174 - onClick={() => save(DEFAULT_SNOOZE_PRESETS, freshKeys(DEFAULT_SNOOZE_PRESETS.length))}
194 + onClick={() => {
195 + const sorted = sortSnoozeRows(
196 + DEFAULT_SNOOZE_PRESETS,
197 + freshKeys(DEFAULT_SNOOZE_PRESETS.length),
198 + now,
199 + );
200 + save(sorted.presets, sorted.keys);
201 + }}
202 />
203 )
204 }
@@ -188,6 +215,7 @@ export function SnoozePresetsRow() {
215 )
216 }
217 onAdd={() => save([...presets, nextCandidate(presets)], [...keys, ...freshKeys(1)])}
218 + onSettle={() => setRows((current) => sortSnoozeRows(current.presets, current.keys, now))}
219 />
220 </SettingsRow>
221 );
@@ -200,6 +228,7 @@ function SnoozePresetList(props: {
228 onChange: (index: number, preset: SnoozePresetSetting) => void;
229 onRemove: (index: number) => void;
230 onAdd: () => void;
231 + onSettle: () => void;
232 }) {
233 const nowMinute = useNowMinute();
234 const now = new Date(`${nowMinute}Z`);
@@ -232,7 +261,20 @@ function SnoozePresetList(props: {
261 );
262
263 return (
235 - <div className="flex flex-col gap-1.5 pt-3 pb-2">
264 + <div
265 + className="flex flex-col gap-1.5 pt-3 pb-2"
266 + onBlur={(event) => {
267 + const list = event.currentTarget;
268 + const next = event.relatedTarget;
269 + if (list.contains(next)) return;
270 + // Select popups portal out of the list, so focus moving into one is not leaving it.
271 + if (next instanceof Element && next.closest('[data-slot="select-popup"]')) return;
272 + // Waits for the amount field's blur commit, and skips its Enter blur-and-refocus.
273 + queueMicrotask(() => {
274 + if (!list.contains(document.activeElement)) props.onSettle();
275 + });
276 + }}
277 + >
278 {props.presets.map((preset, index) => {
279 const preview = previews[index]!;
280 return (
@@ -371,7 +413,7 @@ function DurationFields(props: { minutes: number; onChange: (minutes: number) =>
413 <>
414 <NumberField
415 size="sm"
374 - className="w-24"
416 + className="w-32"
417 min={1}
418 max={maxAmount}
419 step={1}