From 8031432995961f443cef7d38551f10d9b12bf433 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Wed, 14 Aug 2024 16:44:07 -0400 Subject: [PATCH] bug fix --- components/InstallApp.tsx | 2 +- components/ModalContent/DeleteCollectionModal.tsx | 2 +- components/ModalContent/DeleteLinkModal.tsx | 2 +- hooks/store/admin/users.tsx | 4 ++++ hooks/store/collections.tsx | 4 ++++ hooks/store/dashboardData.tsx | 4 ++++ hooks/store/links.tsx | 4 ++++ hooks/store/tags.tsx | 4 ++++ hooks/store/tokens.tsx | 4 ++++ hooks/store/user.tsx | 4 ++-- hooks/useInitialData.tsx | 10 ---------- hooks/useReorderCollection.tsx | 0 pages/collections/[id].tsx | 2 +- pages/links/index.tsx | 2 +- pages/links/pinned.tsx | 2 +- pages/public/collections/[id].tsx | 4 +++- pages/settings/account.tsx | 7 ++----- pages/tags/[id].tsx | 2 +- public/locales/en/common.json | 1 + 19 files changed, 39 insertions(+), 25 deletions(-) delete mode 100644 hooks/useReorderCollection.tsx diff --git a/components/InstallApp.tsx b/components/InstallApp.tsx index 4b70309..f191f00 100644 --- a/components/InstallApp.tsx +++ b/components/InstallApp.tsx @@ -8,7 +8,7 @@ const InstallApp = (props: Props) => { const [isOpen, setIsOpen] = useState(true); return isOpen && !isPWA() ? ( -
+
{ + const { status } = useSession(); + return useQuery({ queryKey: ["users"], queryFn: async () => { @@ -17,6 +20,7 @@ const useUsers = () => { const data = await response.json(); return data.response; }, + enabled: status === "authenticated", }); }; diff --git a/hooks/store/collections.tsx b/hooks/store/collections.tsx index e16a326..efa3809 100644 --- a/hooks/store/collections.tsx +++ b/hooks/store/collections.tsx @@ -1,7 +1,10 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; +import { useSession } from "next-auth/react"; const useCollections = () => { + const { status } = useSession(); + return useQuery({ queryKey: ["collections"], queryFn: async (): Promise => { @@ -9,6 +12,7 @@ const useCollections = () => { const data = await response.json(); return data.response; }, + enabled: status === "authenticated", }); }; diff --git a/hooks/store/dashboardData.tsx b/hooks/store/dashboardData.tsx index 358b035..d808ffd 100644 --- a/hooks/store/dashboardData.tsx +++ b/hooks/store/dashboardData.tsx @@ -1,7 +1,10 @@ import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import { useQuery } from "@tanstack/react-query"; +import { useSession } from "next-auth/react"; const useDashboardData = () => { + const { status } = useSession(); + return useQuery({ queryKey: ["dashboardData"], queryFn: async (): Promise => { @@ -10,6 +13,7 @@ const useDashboardData = () => { return data.response; }, + enabled: status === "authenticated", }); }; diff --git a/hooks/store/links.tsx b/hooks/store/links.tsx index da503f4..4702ff4 100644 --- a/hooks/store/links.tsx +++ b/hooks/store/links.tsx @@ -12,6 +12,7 @@ import { LinkRequestQuery, } from "@/types/global"; import { useRouter } from "next/router"; +import { useSession } from "next-auth/react"; const useLinks = (params: LinkRequestQuery = {}) => { const router = useRouter(); @@ -58,6 +59,8 @@ const useLinks = (params: LinkRequestQuery = {}) => { }; const useFetchLinks = (params: string) => { + const { status } = useSession(); + return useInfiniteQuery({ queryKey: ["links", { params }], queryFn: async (params) => { @@ -80,6 +83,7 @@ const useFetchLinks = (params: string) => { } return lastPage.at(-1).id; }, + enabled: status === "authenticated", }); }; diff --git a/hooks/store/tags.tsx b/hooks/store/tags.tsx index deab456..a2c0b7d 100644 --- a/hooks/store/tags.tsx +++ b/hooks/store/tags.tsx @@ -1,7 +1,10 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { TagIncludingLinkCount } from "@/types/global"; +import { useSession } from "next-auth/react"; const useTags = () => { + const { status } = useSession(); + return useQuery({ queryKey: ["tags"], queryFn: async () => { @@ -11,6 +14,7 @@ const useTags = () => { const data = await response.json(); return data.response; }, + enabled: status === "authenticated", }); }; diff --git a/hooks/store/tokens.tsx b/hooks/store/tokens.tsx index b48fce0..35ac345 100644 --- a/hooks/store/tokens.tsx +++ b/hooks/store/tokens.tsx @@ -1,7 +1,10 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { AccessToken } from "@prisma/client"; +import { useSession } from "next-auth/react"; const useTokens = () => { + const { status } = useSession(); + return useQuery({ queryKey: ["tokens"], queryFn: async () => { @@ -12,6 +15,7 @@ const useTokens = () => { const data = await response.json(); return data.response as AccessToken[]; }, + enabled: status === "authenticated", }); }; diff --git a/hooks/store/user.tsx b/hooks/store/user.tsx index 98ba03c..200fd45 100644 --- a/hooks/store/user.tsx +++ b/hooks/store/user.tsx @@ -2,7 +2,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useSession } from "next-auth/react"; const useUser = () => { - const { data } = useSession(); + const { data, status } = useSession(); const userId = data?.user.id; @@ -16,7 +16,7 @@ const useUser = () => { return data.response; }, - enabled: !!userId, + enabled: !!userId && status === "authenticated", placeholderData: {}, }); }; diff --git a/hooks/useInitialData.tsx b/hooks/useInitialData.tsx index 04cf247..21832d1 100644 --- a/hooks/useInitialData.tsx +++ b/hooks/useInitialData.tsx @@ -1,24 +1,14 @@ import { useEffect } from "react"; import { useSession } from "next-auth/react"; import useLocalSettingsStore from "@/store/localSettings"; -import { useUser } from "./store/user"; export default function useInitialData() { const { status, data } = useSession(); - // const { setLinks } = useLinkStore(); - const { data: user = {} } = useUser(); const { setSettings } = useLocalSettingsStore(); useEffect(() => { setSettings(); }, [status, data]); - // Get the rest of the data - useEffect(() => { - if (user.id && (!process.env.NEXT_PUBLIC_STRIPE || user.username)) { - // setLinks(); - } - }, [user]); - return status; } diff --git a/hooks/useReorderCollection.tsx b/hooks/useReorderCollection.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index c96f807..5ff146f 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -322,7 +322,7 @@ export default function Index() { placeholderCount={1} useData={data} /> - {!data.isLoading && !links[0] && } + {!data.isLoading && links && !links[0] && }
{activeCollection && ( <> diff --git a/pages/links/index.tsx b/pages/links/index.tsx index 7b1e539..582e962 100644 --- a/pages/links/index.tsx +++ b/pages/links/index.tsx @@ -58,7 +58,7 @@ export default function Index() { placeholderCount={1} useData={data} /> - {!data.isLoading && !links[0] && ( + {!data.isLoading && links && !links[0] && ( )}
diff --git a/pages/links/pinned.tsx b/pages/links/pinned.tsx index 3f59c44..9d1fb53 100644 --- a/pages/links/pinned.tsx +++ b/pages/links/pinned.tsx @@ -53,7 +53,7 @@ export default function PinnedLinks() { placeholderCount={1} useData={data} /> - {!data.isLoading && !links[0] && ( + {!data.isLoading && links && !links[0] && (
- {!data.isLoading && !links[0] &&

{t("collection_is_empty")}

} + {!data.isLoading && links && !links[0] && ( +

{t("collection_is_empty")}

+ )} {/*

List created with Linkwarden. diff --git a/pages/settings/account.tsx b/pages/settings/account.tsx index 06d1172..ded4683 100644 --- a/pages/settings/account.tsx +++ b/pages/settings/account.tsx @@ -203,17 +203,14 @@ export default function Account() {

{t("language")}