bug fixed
This commit is contained in:
parent
9c9fd969bc
commit
836360f99d
|
@ -29,7 +29,7 @@ const CollectionListing = () => {
|
||||||
const updateCollection = useUpdateCollection();
|
const updateCollection = useUpdateCollection();
|
||||||
const { data: collections = [], isLoading } = useCollections();
|
const { data: collections = [], isLoading } = useCollections();
|
||||||
|
|
||||||
const { data: user = {} } = useUser();
|
const { data: user = {}, refetch } = useUser();
|
||||||
const updateUser = useUpdateUser();
|
const updateUser = useUpdateUser();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -38,10 +38,7 @@ const CollectionListing = () => {
|
||||||
const [tree, setTree] = useState<TreeData | undefined>();
|
const [tree, setTree] = useState<TreeData | undefined>();
|
||||||
|
|
||||||
const initialTree = useMemo(() => {
|
const initialTree = useMemo(() => {
|
||||||
if (
|
if (collections.length > 0) {
|
||||||
// !tree &&
|
|
||||||
collections.length > 0
|
|
||||||
) {
|
|
||||||
return buildTreeFromCollections(
|
return buildTreeFromCollections(
|
||||||
collections,
|
collections,
|
||||||
router,
|
router,
|
||||||
|
@ -52,12 +49,12 @@ const CollectionListing = () => {
|
||||||
}, [collections, user, router]);
|
}, [collections, user, router]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// if (!tree)
|
|
||||||
setTree(initialTree);
|
setTree(initialTree);
|
||||||
}, [initialTree]);
|
}, [initialTree]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user.username) {
|
if (user.username) {
|
||||||
|
refetch();
|
||||||
if (
|
if (
|
||||||
(!user.collectionOrder || user.collectionOrder.length === 0) &&
|
(!user.collectionOrder || user.collectionOrder.length === 0) &&
|
||||||
collections.length > 0
|
collections.length > 0
|
||||||
|
@ -65,11 +62,7 @@ const CollectionListing = () => {
|
||||||
updateUser.mutate({
|
updateUser.mutate({
|
||||||
...user,
|
...user,
|
||||||
collectionOrder: collections
|
collectionOrder: collections
|
||||||
.filter(
|
.filter((e) => e.parentId === null)
|
||||||
(e) =>
|
|
||||||
e.parentId === null ||
|
|
||||||
!collections.find((i) => i.id === e.parentId)
|
|
||||||
) // Filter out collections with non-null parentId
|
|
||||||
.map((e) => e.id as number),
|
.map((e) => e.id as number),
|
||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
|
@ -103,7 +96,7 @@ const CollectionListing = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [collections]);
|
}, [user, collections]);
|
||||||
|
|
||||||
const onExpand = (movedCollectionId: ItemId) => {
|
const onExpand = (movedCollectionId: ItemId) => {
|
||||||
setTree((currentTree) =>
|
setTree((currentTree) =>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import MainLayout from "@/layouts/MainLayout";
|
import MainLayout from "@/layouts/MainLayout";
|
||||||
import { BaseSyntheticEvent, useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { toast } from "react-hot-toast";
|
import { toast } from "react-hot-toast";
|
||||||
|
@ -90,23 +90,44 @@ export default function Dashboard() {
|
||||||
data: request,
|
data: request,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch("/api/v1/migration", {
|
try {
|
||||||
method: "POST",
|
const response = await fetch("/api/v1/migration", {
|
||||||
body: JSON.stringify(body),
|
method: "POST",
|
||||||
});
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
|
||||||
await response.json();
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
toast.dismiss(load);
|
||||||
|
|
||||||
toast.dismiss(load);
|
toast.error(
|
||||||
|
errorData.response ||
|
||||||
|
"Failed to import bookmarks. Please try again."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
toast.success("Imported the Bookmarks! Reloading the page...");
|
await response.json();
|
||||||
|
toast.dismiss(load);
|
||||||
|
toast.success("Imported the Bookmarks! Reloading the page...");
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
location.reload();
|
location.reload();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Request failed", error);
|
||||||
|
toast.dismiss(load);
|
||||||
|
toast.error(
|
||||||
|
"An error occurred while importing bookmarks. Please check the logs for more info."
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.onerror = function (e) {
|
reader.onerror = function (e) {
|
||||||
console.log("Error:", e);
|
console.log("Error reading file:", e);
|
||||||
|
toast.error(
|
||||||
|
"Failed to read the file. Please make sure the file is correct and try again."
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -233,7 +254,7 @@ export default function Dashboard() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="sky-shadow flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200">
|
<div className="flex flex-col justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200">
|
||||||
<p className="text-center text-2xl">
|
<p className="text-center text-2xl">
|
||||||
{t("view_added_links_here")}
|
{t("view_added_links_here")}
|
||||||
</p>
|
</p>
|
||||||
|
@ -382,7 +403,7 @@ export default function Dashboard() {
|
||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
style={{ flex: "1 1 auto" }}
|
style={{ flex: "1 1 auto" }}
|
||||||
className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200"
|
className="flex flex-col gap-2 justify-center h-full border border-solid border-neutral-content w-full mx-auto p-10 rounded-2xl bg-base-200 bg-gradient-to-tr from-neutral-content/70 to-50% to-base-200"
|
||||||
>
|
>
|
||||||
<i className="bi-pin mx-auto text-6xl text-primary"></i>
|
<i className="bi-pin mx-auto text-6xl text-primary"></i>
|
||||||
<p className="text-center text-2xl">
|
<p className="text-center text-2xl">
|
||||||
|
|
Ŝarĝante…
Reference in New Issue