mirror of
https://github.com/morten-olsen/bob-the-algorithm.git
synced 2026-02-08 00:46:25 +01:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { useAsync, useAsyncCallback } from "#/features/async";
|
|
import { useContext } from "react"
|
|
import { Day, useDate } from "../day";
|
|
import { AppointmentsContext, AppointmentsStatus } from "./context"
|
|
|
|
export const useAppointmentStatus = () => {
|
|
const { status } = useContext(AppointmentsContext);
|
|
return status;
|
|
};
|
|
|
|
export const useAppointments = () => {
|
|
const date = useDate();
|
|
const context = useContext(AppointmentsContext);
|
|
const result = useAsync(
|
|
async () => {
|
|
if (context.status !== AppointmentsStatus.approved) {
|
|
return [];
|
|
}
|
|
const appointments = await context.getDay(date);
|
|
return appointments;
|
|
},
|
|
[
|
|
context.status === AppointmentsStatus.approved && context.getDay,
|
|
date,
|
|
],
|
|
);
|
|
return result;
|
|
}
|
|
|
|
export const useGetAppointments = () => {
|
|
const context = useContext(AppointmentsContext);
|
|
const result = useAsyncCallback(
|
|
async (date: Day) => {
|
|
if (context.status !== AppointmentsStatus.approved) {
|
|
return [];
|
|
}
|
|
const appointments = await context.getDay(date);
|
|
return appointments;
|
|
},
|
|
[
|
|
context.status === AppointmentsStatus.approved && context.getDay,
|
|
],
|
|
);
|
|
return result;
|
|
}
|