improved UX + improved performance

This commit is contained in:
daniel31x13
2024-03-10 06:08:28 -04:00
parent 3feeecdc1d
commit 4a0e75c6e5
18 changed files with 135 additions and 57 deletions
+9 -1
View File
@@ -1,5 +1,5 @@
import { LinkRequestQuery } from "@/types/global";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import useDetectPageBottom from "./useDetectPageBottom";
import { useRouter } from "next/router";
import useLinkStore from "@/store/links";
@@ -22,6 +22,8 @@ export default function useLinks(
useLinkStore();
const router = useRouter();
const [isLoading, setIsLoading] = useState(true);
const { reachedBottom, setReachedBottom } = useDetectPageBottom();
const getLinks = async (isInitialCall: boolean, cursor?: number) => {
@@ -61,10 +63,14 @@ export default function useLinks(
basePath = "/api/v1/public/collections/links";
} else basePath = "/api/v1/links";
setIsLoading(true);
const response = await fetch(`${basePath}?${queryString}`);
const data = await response.json();
setIsLoading(false);
if (response.ok) setLinks(data.response, isInitialCall);
};
@@ -92,4 +98,6 @@ export default function useLinks(
setReachedBottom(false);
}, [reachedBottom]);
return { isLoading };
}