mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-10-15 19:45:42 -04:00
fix(tracking): clamp same-day log-a-watch time to now
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
13 files changed
+69
-3
No files matched your search
@@ -26,6 +26,22 @@ function todayLocal() {
|
||||
return `${now.getFullYear()}-${month}-${day}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the picked date/time to a timestamp. Date-only watches land at local noon (matching
|
||||
* imported date-only watches), clamped to `now` when noon hasn't happened yet today. Returns
|
||||
* null for an invalid or future result.
|
||||
*/
|
||||
export function resolveWatchedAt(date: string, time: string, now: Date): Date | null {
|
||||
if (time) {
|
||||
const picked = new Date(`${date}T${time}:00`);
|
||||
if (Number.isNaN(picked.getTime()) || picked > now) return null;
|
||||
return picked;
|
||||
}
|
||||
const noon = new Date(`${date}T12:00:00`);
|
||||
if (Number.isNaN(noon.getTime())) return null;
|
||||
return noon > now ? now : noon;
|
||||
}
|
||||
|
||||
/** Log a watch of a movie on a chosen date (and optional time). */
|
||||
export function LogWatchDialog({ titleId }: { titleId: string }) {
|
||||
const { t } = useLingui();
|
||||
@@ -58,9 +74,11 @@ export function LogWatchDialog({ titleId }: { titleId: string }) {
|
||||
function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!date || isPending) return;
|
||||
// Date-only watches land at local noon, matching imported date-only watches.
|
||||
const watchedAt = new Date(`${date}T${time || "12:00"}:00`);
|
||||
if (Number.isNaN(watchedAt.getTime())) return;
|
||||
const watchedAt = resolveWatchedAt(date, time, new Date());
|
||||
if (!watchedAt) {
|
||||
toast.error(t`That time is in the future`);
|
||||
return;
|
||||
}
|
||||
mutate({ kind: "movie", id: titleId, watchedAt: watchedAt.toISOString() });
|
||||
}
|
||||
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "التبديل إلى {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "يسري بعد إعادة تشغيل التطبيق"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Zu {name} wechseln"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Tritt nach einem Neustart der App in Kraft"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Switch to {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Takes effect after restarting the app"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr "That time is in the future"
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr "That URL doesn't look right. Include the full server address."
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Cambiar a {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Tendrá efecto tras reiniciar la app"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Passer à {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Prend effet après le redémarrage de l'application"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "עבור ל-{name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "ייכנס לתוקף לאחר הפעלה מחדש של האפליקציה"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Passa a {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Avrà effetto dopo il riavvio dell'app"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "{name}に切り替え"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "アプリを再起動後に反映されます"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "{name}(으)로 전환"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "앱을 다시 시작하면 적용됩니다"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Overschakelen naar {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Van kracht na het herstarten van de app"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "Mudar para {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "Entra em vigor após reiniciar a aplicação"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
@@ -3338,6 +3338,10 @@ msgstr "切换到 {name}"
|
||||
msgid "Takes effect after restarting the app"
|
||||
msgstr "重启应用后生效"
|
||||
|
||||
#: apps/web/src/components/titles/log-watch-dialog.tsx
|
||||
msgid "That time is in the future"
|
||||
msgstr ""
|
||||
|
||||
#: apps/native/src/app/(auth)/server-url.tsx
|
||||
msgid "That URL doesn't look right. Include the full server address."
|
||||
msgstr ""
|
||||
|
||||
Reference in new issue
Block a user