From d438eb70697fe7ef4d9a9bfdcb9d6c268ca15e1d Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Tue, 6 Feb 2024 05:55:45 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=86=20Wired=20up=20the=20datepicker=20?= =?UTF-8?q?to=20LoCG=20pull=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/components/Dashboard/PullList.tsx | 41 ++++++----- src/client/components/shared/DatePicker.tsx | 73 +++++++++++++------- 2 files changed, 71 insertions(+), 43 deletions(-) diff --git a/src/client/components/Dashboard/PullList.tsx b/src/client/components/Dashboard/PullList.tsx index a7e69bc..346bac2 100644 --- a/src/client/components/Dashboard/PullList.tsx +++ b/src/client/components/Dashboard/PullList.tsx @@ -15,6 +15,7 @@ import { useKeenSlider } from "keen-slider/react"; import { COMICVINE_SERVICE_URI } from "../../constants/endpoints"; import { Field, Form } from "react-final-form"; import DatePickerDialog from "../shared/DatePicker"; +import { format } from "date-fns"; type PullListProps = { issues: any; @@ -28,11 +29,10 @@ const http = rateLimiter(axios.create(), { const cachedAxios = setupCache(axios); export const PullList = (): ReactElement => { // datepicker - const [selected, setSelected] = useState(); - let footer =

Please pick a day.

; - if (selected) { - footer =

You picked {format(selected, "PP")}.

; - } + const date = new Date(); + const [inputValue, setInputValue] = useState( + format(date, "M-dd-yyyy"), + ); // keen slider const [sliderRef, instanceRef] = useKeenSlider( @@ -55,6 +55,7 @@ export const PullList = (): ReactElement => { const { data: pullList, + refetch, isSuccess, isLoading, isError, @@ -62,9 +63,9 @@ export const PullList = (): ReactElement => { queryFn: async (): any => await cachedAxios(`${COMICVINE_SERVICE_URI}/getWeeklyPullList`, { method: "get", - params: { startDate: "2024-2-20", pageSize: "15", currentPage: "1" }, + params: { startDate: inputValue, pageSize: "15", currentPage: "1" }, }), - queryKey: ["pullList"], + queryKey: ["pullList", inputValue], }); const addToLibrary = (sourceName: string, locgMetadata) => importToDB(sourceName, { locg: locgMetadata }); @@ -83,28 +84,30 @@ export const PullList = (): ReactElement => { headerContent="Discover" subHeaderContent="Pull List aggregated for the week from League Of Comic Geeks" iconClassNames="fa-solid fa-binoculars mr-2" + link="/pull-list/all/" /> -
+
{/* select week */}
{}} render={({ handleSubmit }) => ( - {/* week selection for pull list */} - - +
+ {/* week selection for pull list */} + + {inputValue && ( +
+ Showing pull list for {inputValue} +
+ )} +
)} /> -
- {/* See all pull list issues */} - - - -
diff --git a/src/client/components/shared/DatePicker.tsx b/src/client/components/shared/DatePicker.tsx index 7aebf83..47b7436 100644 --- a/src/client/components/shared/DatePicker.tsx +++ b/src/client/components/shared/DatePicker.tsx @@ -1,13 +1,14 @@ import React, { ChangeEventHandler, useRef, useState } from "react"; -import { format, isValid, parse } from "date-fns"; +import { format, isValid, parse, parseISO } from "date-fns"; import FocusTrap from "focus-trap-react"; import { DayPicker, SelectSingleEventHandler } from "react-day-picker"; import { usePopper } from "react-popper"; -export default function DatePickerDialog() { +export const DatePickerDialog = (props) => { + console.log(props); + const { setter, apiAction } = props; const [selected, setSelected] = useState(); - const [inputValue, setInputValue] = useState(""); const [isPopperOpen, setIsPopperOpen] = useState(false); const popperRef = useRef(null); @@ -16,6 +17,39 @@ export default function DatePickerDialog() { null, ); + const customStyles = { + container: { + // Style for the entire container + border: "1px solid #ccc", + borderRadius: "4px", + padding: "10px", + width: "300px", + }, + day: { + // Style for individual days + + padding: "5px", + margin: "2px", + }, + selected: { + // Style for selected days + backgroundColor: "#007bff", + color: "#fff", + }, + disabled: { + // Style for disabled days + color: "#ccc", + }, + today: { + // Style for today's date + backgroundColor: "#f0f0f0", + }, + dayWrapper: { + // Style for the wrapper around each day + display: "inline-block", + }, + }; + const popper = usePopper(popperRef.current, popperElement, { placement: "bottom-start", }); @@ -25,16 +59,6 @@ export default function DatePickerDialog() { buttonRef?.current?.focus(); }; - const handleInputChange: ChangeEventHandler = (e) => { - setInputValue(e.currentTarget.value); - const date = parse(e.currentTarget.value, "y-MM-dd", new Date()); - if (isValid(date)) { - setSelected(date); - } else { - setSelected(undefined); - } - }; - const handleButtonClick = () => { setIsPopperOpen(true); }; @@ -42,29 +66,27 @@ export default function DatePickerDialog() { const handleDaySelect: SelectSingleEventHandler = (date) => { setSelected(date); if (date) { - setInputValue(format(date, "y-MM-dd")); + setter(format(date, "M-dd-yyyy")); + apiAction(); closePopper(); } else { - setInputValue(""); + setter(""); } }; return (
-
@@ -82,7 +104,7 @@ export default function DatePickerDialog() {
)}
); -} +}; + +export default DatePickerDialog;