mirror of
https://github.com/ManInDark/HabitTrove.git
synced 2026-01-21 06:34:30 +01:00
Added notification for admin user (#106)
This commit is contained in:
11
lib/atoms.ts
11
lib/atoms.ts
@@ -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 }));
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user