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);
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">
<svg
xmlns="http://www.w3.org/2000/svg"

View File

@ -50,8 +50,8 @@ export default function DeleteCollectionModal({
toast.error(error.message);
} else {
onClose();
router.push("/collections");
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]")) {
router.push("/dashboard");
}
onClose();
toast.success(t("deleted"));
onClose();
}
},
});

View File

@ -1,8 +1,11 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import toast from "react-hot-toast";
import { useTranslation } from "next-i18next";
import { useSession } from "next-auth/react";
const useUsers = () => {
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",
});
};

View File

@ -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<CollectionIncludingMembersAndLinkCount[]> => {
@ -9,6 +12,7 @@ const useCollections = () => {
const data = await response.json();
return data.response;
},
enabled: status === "authenticated",
});
};

View File

@ -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<LinkIncludingShortenedCollectionAndTags[]> => {
@ -10,6 +13,7 @@ const useDashboardData = () => {
return data.response;
},
enabled: status === "authenticated",
});
};

View File

@ -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",
});
};

View File

@ -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",
});
};

View File

@ -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",
});
};

View File

@ -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: {},
});
};

View File

@ -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;
}

View File

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

View File

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

View File

@ -53,7 +53,7 @@ export default function PinnedLinks() {
placeholderCount={1}
useData={data}
/>
{!data.isLoading && !links[0] && (
{!data.isLoading && links && !links[0] && (
<div
style={{ flex: "1 1 auto" }}
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}
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">
List created with <span className="text-black">Linkwarden.</span>

View File

@ -203,17 +203,14 @@ export default function Account() {
<div>
<p className="mb-2">{t("language")}</p>
<select
value={user.locale || ""}
onChange={(e) => {
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"
>
{i18n.locales.map((locale) => (
<option
key={locale}
value={locale}
selected={user.locale === locale}
>
<option key={locale} value={locale}>
{new Intl.DisplayNames(locale, { type: "language" }).of(
locale
) || ""}

View File

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

View File

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