Added PWA support (#40)

This commit is contained in:
Doh
2025-01-15 20:07:23 -05:00
committed by GitHub
parent 1bb968b7c1
commit 71b9d1b408
32 changed files with 1274 additions and 312 deletions

View File

@@ -1,19 +1,21 @@
import { atom } from "jotai";
import {
import {
getDefaultSettings,
getDefaultHabitsData,
getDefaultCoinsData,
getDefaultWishlistData
getDefaultWishlistData,
Habit
} from "./types";
import {
getTodayInTimezone,
isSameDate,
import {
getTodayInTimezone,
isSameDate,
t2d,
calculateCoinsEarnedToday,
calculateTotalEarned,
calculateTotalSpent,
calculateCoinsSpentToday,
calculateTransactionsToday
calculateTransactionsToday,
getCompletionsForToday
} from "@/lib/utils";
export const settingsAtom = atom(getDefaultSettings());
@@ -53,3 +55,35 @@ export const transactionsTodayAtom = atom((get) => {
const settings = get(settingsAtom);
return calculateTransactionsToday(coins.transactions, settings.system.timezone);
});
/* transient atoms */
interface PomodoroAtom {
show: boolean
selectedHabitId: string | null
autoStart: boolean
minimized: boolean
}
export const pomodoroAtom = atom<PomodoroAtom>({
show: false,
selectedHabitId: null,
autoStart: true,
minimized: false,
})
// Derived atom for today's completions of selected habit
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
})
})

View File

@@ -83,6 +83,16 @@ export function getCompletionsForDate({
).length
}
export function getCompletionsForToday({
habit,
timezone
}: {
habit: Habit,
timezone: string
}): number {
return getCompletionsForDate({ habit, date: getTodayInTimezone(timezone), timezone })
}
export function getCompletedHabitsForDate({
habits,
date,