ai generated tasks check for duplicates, existing streaks, and more before creation

This commit is contained in:
masongga
2026-05-23 23:39:54 -06:00
parent c5b20e094e
commit bffe0f941c
8 changed files with 401 additions and 25 deletions

View File

@@ -23,6 +23,7 @@ import {
import {
addHabit,
getCustomHabits,
getTodayDateKey,
isHabitCompletedToday,
removeHabit,
toggleHabitCompletion,
@@ -198,6 +199,7 @@ export function HabitTracker({ mode = "daily" }: HabitTrackerProps) {
);
const [toggleErrors, setToggleErrors] = useState<Record<string, string>>({});
const [coinMessage, setCoinMessage] = useState<string | null>(null);
const [todayKey, setTodayKey] = useState(() => getTodayDateKey());
const getIsCompleted = useCallback(
(habit: DailyTask) => {
@@ -256,6 +258,37 @@ export function HabitTracker({ mode = "daily" }: HabitTrackerProps) {
};
}, [coinMessage]);
useEffect(() => {
const syncForNewDay = () => {
const nextTodayKey = getTodayDateKey();
if (nextTodayKey === todayKey) {
return;
}
setTodayKey(nextTodayKey);
setOptimisticCompletion({});
setCoinMessage(null);
void refresh();
};
const intervalId = window.setInterval(syncForNewDay, 60_000);
const handleVisibilityChange = () => {
if (document.visibilityState === "visible") {
syncForNewDay();
}
};
window.addEventListener("focus", syncForNewDay);
document.addEventListener("visibilitychange", handleVisibilityChange);
return () => {
window.clearInterval(intervalId);
window.removeEventListener("focus", syncForNewDay);
document.removeEventListener("visibilitychange", handleVisibilityChange);
};
}, [refresh, todayKey]);
useEffect(() => {
void refresh();