first commit. working

This commit is contained in:
2025-06-26 13:09:12 -04:00
parent 86df5c354a
commit 45d8efdce6
14 changed files with 4185 additions and 255 deletions
+31
View File
@@ -0,0 +1,31 @@
import { useState, useEffect } from 'react';
import { db, AttendanceRecord } from '../utils/db';
import { v4 as uuid } from 'uuid';
export function useAttendance() {
const [todayRecords, setTodayRecords] = useState<AttendanceRecord[]>([]);
useEffect(() => {
const dayStart = new Date();
dayStart.setHours(0,0,0,0);
db.records
.where('timestamp')
.above(dayStart.getTime())
.toArray()
.then(setTodayRecords);
}, []);
const clockToggle = (teacherId: string) => {
const recs = todayRecords.filter(r => r.teacherId === teacherId);
const next: 'in' | 'out' = recs.pop()?.type === 'in' ? 'out' : 'in';
const rec: AttendanceRecord = {
id: uuid(),
teacherId,
timestamp: Date.now(),
type: next
};
db.records.add(rec).then(() => setTodayRecords(prev => [...prev, rec]));
};
return { todayRecords, clockToggle };
}
+18
View File
@@ -0,0 +1,18 @@
import { useState, useEffect } from 'react';
import { db, Teacher } from '../utils/db';
import { v4 as uuid } from 'uuid';
export function useTeachers() {
const [teachers, setTeachers] = useState<Teacher[]>([]);
useEffect(() => {
db.teachers.toArray().then(setTeachers);
}, []);
const addTeacher = (name: string) => {
const t: Teacher = { id: uuid(), name };
db.teachers.add(t).then(() => setTeachers(prev => [...prev, t]));
};
return { teachers, addTeacher };
}