2023-06-15 07:39:30 -05:00
|
|
|
import {
|
|
|
|
PublicCollectionIncludingLinks,
|
|
|
|
PublicLinkRequestQuery,
|
|
|
|
} from "@/types/global";
|
2023-06-14 17:34:54 -05:00
|
|
|
import { Dispatch, SetStateAction } from "react";
|
|
|
|
|
2023-06-02 22:50:16 -05:00
|
|
|
const getPublicCollectionData = async (
|
2023-06-15 07:39:30 -05:00
|
|
|
collectionId: number,
|
2023-06-14 17:34:54 -05:00
|
|
|
prevData: PublicCollectionIncludingLinks,
|
|
|
|
setData: Dispatch<SetStateAction<PublicCollectionIncludingLinks | undefined>>
|
2023-06-02 22:50:16 -05:00
|
|
|
) => {
|
2023-06-15 07:39:30 -05:00
|
|
|
const requestBody: PublicLinkRequestQuery = {
|
|
|
|
cursor: prevData?.links?.at(-1)?.id,
|
|
|
|
collectionId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const encodedData = encodeURIComponent(JSON.stringify(requestBody));
|
|
|
|
|
2023-05-29 14:40:23 -05:00
|
|
|
const res = await fetch(
|
2023-08-20 11:00:42 -05:00
|
|
|
"/api/public/collections?body=" + encodeURIComponent(encodedData)
|
2023-05-29 14:40:23 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
2023-06-14 17:34:54 -05:00
|
|
|
prevData
|
|
|
|
? setData({
|
|
|
|
...data.response,
|
|
|
|
links: [...prevData.links, ...data.response.links],
|
|
|
|
})
|
|
|
|
: setData(data.response);
|
2023-05-29 14:40:23 -05:00
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default getPublicCollectionData;
|