fix: migrate atoms to normal functions

This commit is contained in:
2026-03-06 22:47:32 +01:00
parent c418bddd9e
commit f7034116a3
7 changed files with 39 additions and 61 deletions

View File

@@ -114,7 +114,7 @@ export const coinsBalanceAtom = atom((get) => {
});
/* transient atoms */
interface PomodoroAtom {
export interface PomodoroAtom {
show: boolean
selectedHabitId: string | null
autoStart: boolean
@@ -191,38 +191,6 @@ export const completedHabitsMapAtom = atom((get) => {
return map;
});
// Derived atom for habit frequency map
export const habitFreqMapAtom = atom((get) => {
const habits = get(habitsAtom).habits;
const map = new Map<string, Freq>();
habits.forEach(habit => {
map.set(habit.id, getHabitFreq(habit));
});
return map;
});
export const pomodoroTodayCompletionsAtom = atom((get) => {
const pomo = get(pomodoroAtom)
const habits = get(habitsAtom)
const settings = get(settingsAtom)
if (!pomo.selectedHabitId) return 0
const selectedHabit = habits.habits.find(h => h.id === pomo.selectedHabitId!)
if (!selectedHabit) return 0
return getCompletionsForToday({
habit: selectedHabit,
timezone: settings.system.timezone
})
})
// Derived atom to check if any habits are tasks
export const hasTasksAtom = atom((get) => {
const habits = get(habitsAtom)
return habits.habits.some(habit => habit.isTask === true)
})
// Atom family for habits by specific date
export const habitsByDateFamily = atomFamily((dateString: string) =>
atom((get) => {

View File

@@ -6,6 +6,7 @@ import { DateTime, DateTimeFormatOptions } from "luxon"
import { Formats } from "next-intl"
import { datetime, RRule } from 'rrule'
import { twMerge } from "tailwind-merge"
import { PomodoroAtom } from "./atoms"
import { DUE_MAP, INITIAL_DUE, RECURRENCE_RULE_MAP } from "./constants"
export function cn(...inputs: ClassValue[]) {
@@ -84,6 +85,20 @@ export function getCompletionsForToday({
return getCompletionsForDate({ habit, date: getTodayInTimezone(timezone), timezone })
}
export function getTodayCompletions({ selectedHabitId }: PomodoroAtom, { habits }: HabitsData, { system: { timezone } }: Settings): number {
if (!selectedHabitId)
return 0;
const selectedHabit = habits.find(h => h.id === selectedHabitId!);
if (!selectedHabit)
return 0;
return getCompletionsForToday({
habit: selectedHabit,
timezone: timezone
});
}
export function getCompletedHabitsForDate({
habits,
date,