import React, { ReactElement, useState } from "react"; import { map } from "lodash"; import Card from "../shared/Carda"; import Header from "../shared/Header"; import ellipsize from "ellipsize"; import axios from "axios"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import useEmblaCarousel from "embla-carousel-react"; import { LIBRARY_SERVICE_BASE_URI } from "../../constants/endpoints"; import { Form } from "react-final-form"; import DatePickerDialog from "../shared/DatePicker"; import { format } from "date-fns"; import { LocgMetadata, useGetWeeklyPullListQuery } from "../../graphql/generated"; interface PullListProps { issues?: LocgMetadata[]; } export const PullList = (): ReactElement => { const queryClient = useQueryClient(); // datepicker const date = new Date(); const [inputValue, setInputValue] = useState( format(date, "yyyy/M/dd"), ); // embla carousel const [emblaRef, emblaApi] = useEmblaCarousel({ loop: false, align: "start", containScroll: "trimSnaps", slidesToScroll: 1, }); const { data: pullListData, refetch, isSuccess, isLoading, isError, } = useGetWeeklyPullListQuery({ input: { startDate: inputValue, pageSize: 15, currentPage: 1, }, }); // Transform the data to match the old structure const pullList = pullListData ? { data: pullListData.getWeeklyPullList } : undefined; const { mutate: addToLibrary } = useMutation({ mutationFn: async ({ sourceName, metadata }: { sourceName: string; metadata: any }) => { const comicBookMetadata = { importType: "new", payload: { rawFileDetails: { name: "", }, importStatus: { isImported: true, tagged: false, matchedResult: { score: "0", }, }, sourcedMetadata: metadata || null, acquisition: { source: { wanted: true, name: sourceName } }, }, }; return await axios.request({ url: `${LIBRARY_SERVICE_BASE_URI}/rawImportToDb`, method: "POST", data: comicBookMetadata, }); }, onSuccess: () => { // Invalidate and refetch wanted comics queries queryClient.invalidateQueries({ queryKey: ["wantedComics"] }); }, }); const next = () => { // sliderRef.slickNext(); }; const previous = () => { // sliderRef.slickPrev(); }; return ( <> {/* TODO: Switch iconClassNames to Solar icon */}
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 */} {inputValue && (
Showing pull list for{" "} {inputValue}
)}
)} />
{isSuccess && !isLoading && (
{map(pullList?.data.result, (issue: LocgMetadata, idx: number) => { return (
{issue.publisher || 'Unknown Publisher'}
); })}
)} {isLoading &&
Loading...
} {isError &&
An error occurred while retrieving the pull list.
}
); }; export default PullList;