This commit is contained in:
daniel31x13 2024-08-14 16:44:07 -04:00
parent 9cc3a7206e
commit 8031432995
19 changed files with 39 additions and 25 deletions

View File

@ -8,7 +8,7 @@ const InstallApp = (props: Props) => {
const [isOpen, setIsOpen] = useState(true); const [isOpen, setIsOpen] = useState(true);
return isOpen && !isPWA() ? ( return isOpen && !isPWA() ? (
<div className="absolute left-0 right-0 bottom-10 w-full p-5"> <div className="fixed left-0 right-0 bottom-10 w-full p-5">
<div className="mx-auto w-fit p-2 flex justify-between gap-2 items-center border border-neutral-content rounded-xl bg-base-300 backdrop-blur-md bg-opacity-80 max-w-md"> <div className="mx-auto w-fit p-2 flex justify-between gap-2 items-center border border-neutral-content rounded-xl bg-base-300 backdrop-blur-md bg-opacity-80 max-w-md">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"

View File

@ -50,8 +50,8 @@ export default function DeleteCollectionModal({
toast.error(error.message); toast.error(error.message);
} else { } else {
onClose(); onClose();
router.push("/collections");
toast.success(t("deleted")); toast.success(t("deleted"));
router.push("/collections");
} }
}, },
}); });

View File

@ -37,8 +37,8 @@ export default function DeleteLinkModal({ onClose, activeLink }: Props) {
if (router.pathname.startsWith("/links/[id]")) { if (router.pathname.startsWith("/links/[id]")) {
router.push("/dashboard"); router.push("/dashboard");
} }
onClose();
toast.success(t("deleted")); toast.success(t("deleted"));
onClose();
} }
}, },
}); });

View File

@ -1,8 +1,11 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
import { useSession } from "next-auth/react";
const useUsers = () => { const useUsers = () => {
const { status } = useSession();
return useQuery({ return useQuery({
queryKey: ["users"], queryKey: ["users"],
queryFn: async () => { queryFn: async () => {
@ -17,6 +20,7 @@ const useUsers = () => {
const data = await response.json(); const data = await response.json();
return data.response; return data.response;
}, },
enabled: status === "authenticated",
}); });
}; };

View File

@ -1,7 +1,10 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { CollectionIncludingMembersAndLinkCount } from "@/types/global"; import { CollectionIncludingMembersAndLinkCount } from "@/types/global";
import { useSession } from "next-auth/react";
const useCollections = () => { const useCollections = () => {
const { status } = useSession();
return useQuery({ return useQuery({
queryKey: ["collections"], queryKey: ["collections"],
queryFn: async (): Promise<CollectionIncludingMembersAndLinkCount[]> => { queryFn: async (): Promise<CollectionIncludingMembersAndLinkCount[]> => {
@ -9,6 +12,7 @@ const useCollections = () => {
const data = await response.json(); const data = await response.json();
return data.response; return data.response;
}, },
enabled: status === "authenticated",
}); });
}; };

View File

@ -1,7 +1,10 @@
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { useSession } from "next-auth/react";
const useDashboardData = () => { const useDashboardData = () => {
const { status } = useSession();
return useQuery({ return useQuery({
queryKey: ["dashboardData"], queryKey: ["dashboardData"],
queryFn: async (): Promise<LinkIncludingShortenedCollectionAndTags[]> => { queryFn: async (): Promise<LinkIncludingShortenedCollectionAndTags[]> => {
@ -10,6 +13,7 @@ const useDashboardData = () => {
return data.response; return data.response;
}, },
enabled: status === "authenticated",
}); });
}; };

View File

@ -12,6 +12,7 @@ import {
LinkRequestQuery, LinkRequestQuery,
} from "@/types/global"; } from "@/types/global";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
const useLinks = (params: LinkRequestQuery = {}) => { const useLinks = (params: LinkRequestQuery = {}) => {
const router = useRouter(); const router = useRouter();
@ -58,6 +59,8 @@ const useLinks = (params: LinkRequestQuery = {}) => {
}; };
const useFetchLinks = (params: string) => { const useFetchLinks = (params: string) => {
const { status } = useSession();
return useInfiniteQuery({ return useInfiniteQuery({
queryKey: ["links", { params }], queryKey: ["links", { params }],
queryFn: async (params) => { queryFn: async (params) => {
@ -80,6 +83,7 @@ const useFetchLinks = (params: string) => {
} }
return lastPage.at(-1).id; return lastPage.at(-1).id;
}, },
enabled: status === "authenticated",
}); });
}; };

View File

@ -1,7 +1,10 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { TagIncludingLinkCount } from "@/types/global"; import { TagIncludingLinkCount } from "@/types/global";
import { useSession } from "next-auth/react";
const useTags = () => { const useTags = () => {
const { status } = useSession();
return useQuery({ return useQuery({
queryKey: ["tags"], queryKey: ["tags"],
queryFn: async () => { queryFn: async () => {
@ -11,6 +14,7 @@ const useTags = () => {
const data = await response.json(); const data = await response.json();
return data.response; return data.response;
}, },
enabled: status === "authenticated",
}); });
}; };

View File

@ -1,7 +1,10 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { AccessToken } from "@prisma/client"; import { AccessToken } from "@prisma/client";
import { useSession } from "next-auth/react";
const useTokens = () => { const useTokens = () => {
const { status } = useSession();
return useQuery({ return useQuery({
queryKey: ["tokens"], queryKey: ["tokens"],
queryFn: async () => { queryFn: async () => {
@ -12,6 +15,7 @@ const useTokens = () => {
const data = await response.json(); const data = await response.json();
return data.response as AccessToken[]; return data.response as AccessToken[];
}, },
enabled: status === "authenticated",
}); });
}; };

View File

@ -2,7 +2,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { useSession } from "next-auth/react"; import { useSession } from "next-auth/react";
const useUser = () => { const useUser = () => {
const { data } = useSession(); const { data, status } = useSession();
const userId = data?.user.id; const userId = data?.user.id;
@ -16,7 +16,7 @@ const useUser = () => {
return data.response; return data.response;
}, },
enabled: !!userId, enabled: !!userId && status === "authenticated",
placeholderData: {}, placeholderData: {},
}); });
}; };

View File

@ -1,24 +1,14 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { useSession } from "next-auth/react"; import { useSession } from "next-auth/react";
import useLocalSettingsStore from "@/store/localSettings"; import useLocalSettingsStore from "@/store/localSettings";
import { useUser } from "./store/user";
export default function useInitialData() { export default function useInitialData() {
const { status, data } = useSession(); const { status, data } = useSession();
// const { setLinks } = useLinkStore();
const { data: user = {} } = useUser();
const { setSettings } = useLocalSettingsStore(); const { setSettings } = useLocalSettingsStore();
useEffect(() => { useEffect(() => {
setSettings(); setSettings();
}, [status, data]); }, [status, data]);
// Get the rest of the data
useEffect(() => {
if (user.id && (!process.env.NEXT_PUBLIC_STRIPE || user.username)) {
// setLinks();
}
}, [user]);
return status; return status;
} }

View File

@ -322,7 +322,7 @@ export default function Index() {
placeholderCount={1} placeholderCount={1}
useData={data} useData={data}
/> />
{!data.isLoading && !links[0] && <NoLinksFound />} {!data.isLoading && links && !links[0] && <NoLinksFound />}
</div> </div>
{activeCollection && ( {activeCollection && (
<> <>

View File

@ -58,7 +58,7 @@ export default function Index() {
placeholderCount={1} placeholderCount={1}
useData={data} useData={data}
/> />
{!data.isLoading && !links[0] && ( {!data.isLoading && links && !links[0] && (
<NoLinksFound text={t("you_have_not_added_any_links")} /> <NoLinksFound text={t("you_have_not_added_any_links")} />
)} )}
</div> </div>

View File

@ -53,7 +53,7 @@ export default function PinnedLinks() {
placeholderCount={1} placeholderCount={1}
useData={data} useData={data}
/> />
{!data.isLoading && !links[0] && ( {!data.isLoading && links && !links[0] && (
<div <div
style={{ flex: "1 1 auto" }} style={{ flex: "1 1 auto" }}
className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10" className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10"

View File

@ -230,7 +230,9 @@ export default function PublicCollections() {
placeholderCount={1} placeholderCount={1}
useData={data} useData={data}
/> />
{!data.isLoading && !links[0] && <p>{t("collection_is_empty")}</p>} {!data.isLoading && links && !links[0] && (
<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>

View File

@ -203,17 +203,14 @@ export default function Account() {
<div> <div>
<p className="mb-2">{t("language")}</p> <p className="mb-2">{t("language")}</p>
<select <select
value={user.locale || ""}
onChange={(e) => { onChange={(e) => {
setUser({ ...user, locale: e.target.value }); setUser({ ...user, locale: e.target.value });
}} }}
className="select border border-neutral-content focus:outline-none focus:border-primary duration-100 w-full bg-base-200 rounded-[0.375rem] min-h-0 h-[2.625rem] leading-4 p-2" className="select border border-neutral-content focus:outline-none focus:border-primary duration-100 w-full bg-base-200 rounded-[0.375rem] min-h-0 h-[2.625rem] leading-4 p-2"
> >
{i18n.locales.map((locale) => ( {i18n.locales.map((locale) => (
<option <option key={locale} value={locale}>
key={locale}
value={locale}
selected={user.locale === locale}
>
{new Intl.DisplayNames(locale, { type: "language" }).of( {new Intl.DisplayNames(locale, { type: "language" }).of(
locale locale
) || ""} ) || ""}

View File

@ -114,8 +114,8 @@ export default function Index() {
if (error) { if (error) {
toast.error(error.message); toast.error(error.message);
} else { } else {
router.push("/links");
toast.success(t("tag_deleted")); toast.success(t("tag_deleted"));
router.push("/links");
} }
}, },
}); });

View File

@ -297,6 +297,7 @@
"create_new_collection": "Create a New Collection", "create_new_collection": "Create a New Collection",
"color": "Color", "color": "Color",
"reset": "Reset", "reset": "Reset",
"updating_collection": "Updating Collection...",
"collection_name_placeholder": "e.g. Example Collection", "collection_name_placeholder": "e.g. Example Collection",
"collection_description_placeholder": "The purpose of this Collection...", "collection_description_placeholder": "The purpose of this Collection...",
"create_collection_button": "Create Collection", "create_collection_button": "Create Collection",