bug fixed

This commit is contained in:
daniel31x13 2024-08-16 12:35:04 -04:00
parent 0e47ad9920
commit 5d26617251
3 changed files with 22 additions and 40 deletions

View File

@ -398,14 +398,13 @@ const useBulkEditLinks = () => {
return data.response; return data.response;
}, },
onSuccess: (data, { links, newData, removePreviousTags }) => { onSuccess: (data, { links, newData, removePreviousTags }) => {
queryClient.setQueryData(["dashboardData"], (oldData: any) => { // TODO: Fix these
if (!oldData) return undefined; // queryClient.setQueryData(["dashboardData"], (oldData: any) => {
return oldData.map((e: any) => // if (!oldData) return undefined;
data.find((d: any) => d.id === e.id) ? data : e // return oldData.map((e: any) =>
); // data.find((d: any) => d.id === e.id) ? data : e
}); // );
// });
// TODO: Fix this
// queryClient.setQueriesData({ queryKey: ["links"] }, (oldData: any) => { // queryClient.setQueriesData({ queryKey: ["links"] }, (oldData: any) => {
// if (!oldData) return undefined; // if (!oldData) return undefined;
// return { // return {
@ -417,6 +416,7 @@ const useBulkEditLinks = () => {
// }; // };
// }); // });
queryClient.invalidateQueries({ queryKey: ["links"] }); // Temporary workaround queryClient.invalidateQueries({ queryKey: ["links"] }); // Temporary workaround
queryClient.invalidateQueries({ queryKey: ["dashboardData"] }); // Temporary workaround
queryClient.invalidateQueries({ queryKey: ["collections"] }); queryClient.invalidateQueries({ queryKey: ["collections"] });
queryClient.invalidateQueries({ queryKey: ["tags"] }); queryClient.invalidateQueries({ queryKey: ["tags"] });

View File

@ -1,12 +1,4 @@
import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; const getPublicCollectionData = async (collectionId: number) => {
import { Dispatch, SetStateAction } from "react";
const getPublicCollectionData = async (
collectionId: number,
setData: Dispatch<
SetStateAction<CollectionIncludingMembersAndLinkCount | undefined>
>
) => {
const res = await fetch("/api/v1/public/collections/" + collectionId); const res = await fetch("/api/v1/public/collections/" + collectionId);
if (res.status === 400) if (res.status === 400)
@ -14,8 +6,6 @@ const getPublicCollectionData = async (
const data = await res.json(); const data = await res.json();
setData(data.response);
return data; return data;
}; };

View File

@ -19,7 +19,6 @@ import EditCollectionSharingModal from "@/components/ModalContent/EditCollection
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
import getServerSideProps from "@/lib/client/getServerSideProps"; import getServerSideProps from "@/lib/client/getServerSideProps";
import LinkListOptions from "@/components/LinkListOptions"; import LinkListOptions from "@/components/LinkListOptions";
import { useCollections } from "@/hooks/store/collections";
import { usePublicLinks } from "@/hooks/store/publicLinks"; import { usePublicLinks } from "@/hooks/store/publicLinks";
import Links from "@/components/LinkViews/Links"; import Links from "@/components/LinkViews/Links";
@ -28,8 +27,6 @@ export default function PublicCollections() {
const { settings } = useLocalSettingsStore(); const { settings } = useLocalSettingsStore();
const { data: collections = [] } = useCollections();
const router = useRouter(); const router = useRouter();
const [collectionOwner, setCollectionOwner] = useState({ const [collectionOwner, setCollectionOwner] = useState({
@ -71,25 +68,22 @@ export default function PublicCollections() {
useEffect(() => { useEffect(() => {
if (router.query.id) { if (router.query.id) {
getPublicCollectionData(Number(router.query.id), setCollection).then( getPublicCollectionData(Number(router.query.id)).then((res) => {
(res) => {
if (res.status === 400) { if (res.status === 400) {
router.push("/dashboard"); router.push("/dashboard");
} else {
setCollection(res.response);
} }
});
} }
); }, []);
}
}, [collections]);
useEffect(() => { useEffect(() => {
const fetchOwner = async () => {
if (collection) { if (collection) {
const owner = await getPublicUserData(collection.ownerId as number); getPublicUserData(collection.ownerId as number).then((owner) =>
setCollectionOwner(owner); setCollectionOwner(owner)
);
} }
};
fetchOwner();
}, [collection]); }, [collection]);
const [editCollectionSharingModal, setEditCollectionSharingModal] = const [editCollectionSharingModal, setEditCollectionSharingModal] =
@ -236,9 +230,7 @@ export default function PublicCollections() {
placeholderCount={1} placeholderCount={1}
useData={data} useData={data}
/> />
{!data.isLoading && links && !links[0] && ( {!data.isLoading && links && !links[0] && <p>{t("nothing_found")}</p>}
<p>{t("collection_is_empty")}</p>
)}
{/* <p className="text-center text-neutral"> {/* <p className="text-center text-neutral">
List created with <span className="text-black">Linkwarden.</span> List created with <span className="text-black">Linkwarden.</span>