Added notification for admin user (#106)

This commit is contained in:
Doh
2025-04-13 22:01:07 -04:00
committed by GitHub
parent e53e2f649a
commit 909bfa7c6f
14 changed files with 723 additions and 47 deletions

View File

@@ -9,6 +9,7 @@ import {
getDefaultUsersData,
CompletionCache,
getDefaultServerSettings,
User,
} from "./types";
import {
getTodayInTimezone,
@@ -110,16 +111,16 @@ export const completionCacheAtom = atom((get) => {
const habits = get(habitsAtom).habits;
const timezone = get(settingsAtom).system.timezone;
const cache: CompletionCache = {};
habits.forEach(habit => {
habit.completions.forEach(utcTimestamp => {
const localDate = t2d({ timestamp: utcTimestamp, timezone })
.toFormat('yyyy-MM-dd');
if (!cache[localDate]) {
cache[localDate] = {};
}
cache[localDate][habit.id] = (cache[localDate][habit.id] || 0) + 1;
});
});
@@ -173,12 +174,12 @@ export const hasTasksAtom = atom((get) => {
})
// Atom family for habits by specific date
export const habitsByDateFamily = atomFamily((dateString: string) =>
export const habitsByDateFamily = atomFamily((dateString: string) =>
atom((get) => {
const habits = get(habitsAtom).habits;
const settings = get(settingsAtom);
const timezone = settings.system.timezone;
const date = DateTime.fromISO(dateString).setZone(timezone);
return habits.filter(habit => isHabitDue({ habit, timezone, date }));
})

View File

@@ -31,7 +31,8 @@ export type SafeUser = SessionUser & {
}
export type User = SafeUser & {
password: string
password?: string // Optional: Allow users without passwords (e.g., initial setup)
lastNotificationReadTimestamp?: string // UTC ISO date string
}
export type Habit = {
@@ -101,8 +102,9 @@ export const getDefaultUsersData = (): UserData => ({
{
id: uuid(),
username: 'admin',
password: '',
// password: '', // No default password for admin initially? Or set a secure default?
isAdmin: true,
lastNotificationReadTimestamp: undefined, // Initialize as undefined
}
]
});