Feature/date picker (#238)

- Date range picker for tournaments.

- Resets date when closing picker

- tRPC and Jotai update
This commit is contained in:
Owen Rees
2024-01-16 12:28:08 +01:00
committed by GitHub
parent a3ec663384
commit efa9088336
10 changed files with 1058 additions and 775 deletions
+30
View File
@@ -0,0 +1,30 @@
import { Dispatch, RefObject, SetStateAction, useEffect } from "react";
import { DatePickerDirection } from "@/types";
const useDatePickerWidth = ({
datePickerRef,
setDateDirectionState,
}: {
datePickerRef: RefObject<HTMLDivElement>;
setDateDirectionState: Dispatch<SetStateAction<DatePickerDirection>>;
}) => {
useEffect(() => {
const updateDatePickerDirection = () => {
const datePickerWidth = datePickerRef.current?.offsetWidth ?? 0;
const isLg = datePickerWidth >= 680;
isLg
? setDateDirectionState("horizontal")
: setDateDirectionState("vertical");
};
updateDatePickerDirection();
window.addEventListener("resize", updateDatePickerDirection);
return () => {
window.removeEventListener("resize", updateDatePickerDirection);
};
}, [datePickerRef, setDateDirectionState]);
};
export default useDatePickerWidth;