Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

bug fixes

daniel31x13a34f1d73080a
diff --git a/apps/web/components/CollectionCard.tsx b/apps/web/components/CollectionCard.tsx
index a2d4e8b4..aa6e7e21 100644
--- a/apps/web/components/CollectionCard.tsx
+++ b/apps/web/components/CollectionCard.tsx
@@ -6,7 +6,6 @@ import {
import React, { useEffect, useState } from "react";
import ProfilePhoto from "./ProfilePhoto";
import usePermissions from "@/hooks/usePermissions";
-import useLocalSettingsStore from "@/store/localSettings";
import getPublicUserData from "@/lib/client/getPublicUserData";
import EditCollectionModal from "./ModalContent/EditCollectionModal";
import EditCollectionSharingModal from "./ModalContent/EditCollectionSharingModal";
@@ -28,8 +27,7 @@ export default function CollectionCard({
collection: CollectionIncludingMembersAndLinkCount;
}) {
const { t } = useTranslation();
- const { settings } = useLocalSettingsStore();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const formattedDate = new Date(collection.createdAt as string).toLocaleString(
t("locale"),
@@ -48,18 +46,18 @@ export default function CollectionCard({
useEffect(() => {
const fetchOwner = async () => {
- if (collection && collection.ownerId !== user.id) {
+ if (collection && collection.ownerId !== user?.id) {
const owner = await getPublicUserData(collection.ownerId as number);
setCollectionOwner(owner);
- } else if (collection && collection.ownerId === user.id) {
+ } else if (collection && collection.ownerId === user?.id) {
setCollectionOwner({
- id: user.id as number,
- name: user.name,
- username: user.username as string,
- image: user.image as string,
- archiveAsScreenshot: user.archiveAsScreenshot as boolean,
- archiveAsMonolith: user.archiveAsMonolith as boolean,
- archiveAsPDF: user.archiveAsPDF as boolean,
+ id: user?.id as number,
+ name: user?.name,
+ username: user?.username as string,
+ image: user?.image as string,
+ archiveAsScreenshot: user?.archiveAsScreenshot as boolean,
+ archiveAsMonolith: user?.archiveAsMonolith as boolean,
+ archiveAsPDF: user?.archiveAsPDF as boolean,
});
}
};
@@ -161,9 +159,9 @@ export default function CollectionCard({
href={`/collections/${collection.id}`}
style={{
backgroundImage: `linear-gradient(45deg, ${collection.color}30 10%, ${
- settings.theme === "dark" ? "oklch(var(--b2))" : "oklch(var(--b2))"
+ user?.theme === "dark" ? "oklch(var(--b2))" : "oklch(var(--b2))"
} 50%, ${
- settings.theme === "dark" ? "oklch(var(--b2))" : "oklch(var(--b2))"
+ user?.theme === "dark" ? "oklch(var(--b2))" : "oklch(var(--b2))"
} 100%)`,
}}
className="card card-compact shadow-md hover:shadow-none duration-200 border border-neutral-content"
diff --git a/apps/web/components/CollectionListing.tsx b/apps/web/components/CollectionListing.tsx
index e34cd65f..bb63f60d 100644
--- a/apps/web/components/CollectionListing.tsx
+++ b/apps/web/components/CollectionListing.tsx
@@ -32,7 +32,7 @@ const CollectionListing = () => {
const updateCollection = useUpdateCollection();
const { data: collections = [], isLoading } = useCollections();
- const { data: user = {}, refetch } = useUser();
+ const { data: user, refetch } = useUser();
const updateUser = useUpdateUser();
const router = useRouter();
@@ -46,7 +46,7 @@ const CollectionListing = () => {
collections,
router,
tree,
- user.collectionOrder
+ user?.collectionOrder
);
} else return undefined;
}, [collections, user, router]);
@@ -56,7 +56,7 @@ const CollectionListing = () => {
}, [initialTree]);
useEffect(() => {
- if (user.username) {
+ if (user?.username) {
refetch();
if (
(!user.collectionOrder || user.collectionOrder.length === 0) &&
@@ -216,9 +216,9 @@ const CollectionListing = () => {
);
if (
- (movedCollection?.ownerId !== user.id &&
+ (movedCollection?.ownerId !== user?.id &&
destination.parentId !== source.parentId) ||
- (destinationCollection?.ownerId !== user.id &&
+ (destinationCollection?.ownerId !== user?.id &&
destination.parentId !== "root")
) {
return toast.error(t("cant_change_collection_you_dont_own"));
diff --git a/apps/web/components/LinkDetails.tsx b/apps/web/components/LinkDetails.tsx
index 7b0ed57f..f2f03f3d 100644
--- a/apps/web/components/LinkDetails.tsx
+++ b/apps/web/components/LinkDetails.tsx
@@ -64,7 +64,7 @@ export default function LinkDetails({
const permissions = usePermissions(link.collection.id as number);
const { t } = useTranslation();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const router = useRouter();
const isPublicRoute = router.pathname.startsWith("/public") ? true : false;
@@ -81,20 +81,20 @@ export default function LinkDetails({
useEffect(() => {
const fetchOwner = async () => {
- if (link.collection.ownerId !== user.id) {
+ if (link.collection.ownerId !== user?.id) {
const owner = await getPublicUserData(
link.collection.ownerId as number
);
setCollectionOwner(owner);
- } else if (link.collection.ownerId === user.id) {
+ } else if (link.collection.ownerId === user?.id) {
setCollectionOwner({
- id: user.id as number,
- name: user.name,
- username: user.username as string,
- image: user.image as string,
- archiveAsScreenshot: user.archiveAsScreenshot as boolean,
- archiveAsMonolith: user.archiveAsScreenshot as boolean,
- archiveAsPDF: user.archiveAsPDF as boolean,
+ id: user?.id as number,
+ name: user?.name as string,
+ username: user?.username as string,
+ image: user?.image as string,
+ archiveAsScreenshot: user?.archiveAsScreenshot as boolean,
+ archiveAsMonolith: user?.archiveAsScreenshot as boolean,
+ archiveAsPDF: user?.archiveAsPDF as boolean,
});
}
};
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
index 2ff2d7a9..dabc3a19 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
@@ -58,7 +58,7 @@ export default function LinkCard({ link, columns, editMode }: Props) {
const { data: collections = [] } = useCollections();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const { setSelectedLinks, selectedLinks } = useLinkStore();
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
index 8566d7dd..714f80d9 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
@@ -36,7 +36,7 @@ export default function LinkCardCompact({ link, editMode }: Props) {
const { data: collections = [] } = useCollections();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const { setSelectedLinks, selectedLinks } = useLinkStore();
const {
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
index 9a6431ea..6a19c29d 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
@@ -58,7 +58,7 @@ export default function LinkMasonry({ link, editMode, columns }: Props) {
);
const { data: collections = [] } = useCollections();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const { setSelectedLinks, selectedLinks } = useLinkStore();
diff --git a/apps/web/components/ModalContent/EditCollectionSharingModal.tsx b/apps/web/components/ModalContent/EditCollectionSharingModal.tsx
index 16980403..55b2caee 100644
--- a/apps/web/components/ModalContent/EditCollectionSharingModal.tsx
+++ b/apps/web/components/ModalContent/EditCollectionSharingModal.tsx
@@ -24,6 +24,7 @@ import {
DropdownMenuRadioItem,
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
+import { User } from "@linkwarden/prisma/client";
type Props = {
onClose: Function;
@@ -67,7 +68,7 @@ export default function EditCollectionSharingModal({
}
};
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const permissions = usePermissions(collection.id as number);
const currentURL = new URL(document.URL);
@@ -169,7 +170,7 @@ export default function EditCollectionSharingModal({
onKeyDown={(e) =>
e.key === "Enter" &&
addMemberToCollection(
- user,
+ user as any,
memberIdentifier.replace(/^@/, ""),
collection,
setMemberState,
@@ -184,7 +185,7 @@ export default function EditCollectionSharingModal({
className="h-10 w-10"
onClick={() =>
addMemberToCollection(
- user,
+ user as any,
memberIdentifier.replace(/^@/, ""),
collection,
setMemberState,
diff --git a/apps/web/components/ProfileDropdown.tsx b/apps/web/components/ProfileDropdown.tsx
index 2973d0f7..44722595 100644
--- a/apps/web/components/ProfileDropdown.tsx
+++ b/apps/web/components/ProfileDropdown.tsx
@@ -3,7 +3,7 @@ import ProfilePhoto from "./ProfilePhoto";
import Link from "next/link";
import { signOut } from "next-auth/react";
import { useTranslation } from "next-i18next";
-import { useUser } from "@linkwarden/router/user";
+import { useUpdateUserPreference, useUser } from "@linkwarden/router/user";
import { useConfig } from "@linkwarden/router/config";
import {
DropdownMenu,
@@ -15,16 +15,17 @@ import { Button } from "./ui/button";
export default function ProfileDropdown() {
const { t } = useTranslation();
- const { settings, updateSettings } = useLocalSettingsStore();
- const { data: user = {} } = useUser();
+ const { settings } = useLocalSettingsStore();
+ const updateUserPreference = useUpdateUserPreference();
+ const { data: user } = useUser();
const { data: config } = useConfig();
- const isAdmin = user.id === (config?.ADMIN || 1);
+ const isAdmin = user?.id === (config?.ADMIN || 1);
const handleToggle = () => {
- const newTheme = settings.theme === "dark" ? "light" : "dark";
- updateSettings({ theme: newTheme });
+ const newTheme = user?.theme === "dark" ? "light" : "dark";
+ updateUserPreference.mutate({ theme: newTheme });
};
return (
@@ -32,7 +33,7 @@ export default function ProfileDropdown() {
<DropdownMenuTrigger>
<Button variant="ghost" className="rounded-full p-1">
<ProfilePhoto
- src={user.image ? user.image : undefined}
+ src={user?.image ? user?.image : undefined}
priority={true}
/>
</Button>
@@ -50,13 +51,13 @@ export default function ProfileDropdown() {
onClick={() => handleToggle()}
className="whitespace-nowrap block sm:hidden"
>
- {settings.theme === "light" ? (
+ {user?.theme === "light" ? (
<i className="bi-moon-fill"></i>
) : (
<i className="bi-sun-fill"></i>
)}
{t("switch_to", {
- theme: settings.theme === "light" ? t("dark") : t("light"),
+ theme: user?.theme === "light" ? t("dark") : t("light"),
})}
</div>
</DropdownMenuItem>
diff --git a/apps/web/components/SettingsSidebar.tsx b/apps/web/components/SettingsSidebar.tsx
index 64902272..62dc8da9 100644
--- a/apps/web/components/SettingsSidebar.tsx
+++ b/apps/web/components/SettingsSidebar.tsx
@@ -11,7 +11,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {
const { data: user } = useUser();
const { data: config } = useConfig();
- const isAdmin = user.id === (config?.ADMIN || 1);
+ const isAdmin = user?.id === (config?.ADMIN || 1);
const router = useRouter();
const [active, setActive] = useState("");
@@ -107,7 +107,7 @@ export default function SettingsSidebar({ className }: { className?: string }) {
</Link>
)}
- {process.env.NEXT_PUBLIC_STRIPE && !user.parentSubscriptionId && (
+ {process.env.NEXT_PUBLIC_STRIPE && !user?.parentSubscriptionId && (
<Link href="/settings/billing">
<div
className={`${
diff --git a/apps/web/hooks/useCollectivePermissions.ts b/apps/web/hooks/useCollectivePermissions.ts
index 731169ca..474b949d 100644
--- a/apps/web/hooks/useCollectivePermissions.ts
+++ b/apps/web/hooks/useCollectivePermissions.ts
@@ -6,7 +6,7 @@ import { useUser } from "@linkwarden/router/user";
export default function useCollectivePermissions(collectionIds: number[]) {
const { data: collections = [] } = useCollections();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const [permissions, setPermissions] = useState<Member | true>();
useEffect(() => {
@@ -15,7 +15,7 @@ export default function useCollectivePermissions(collectionIds: number[]) {
if (collection) {
let getPermission: Member | undefined = collection.members.find(
- (e) => e.userId === user.id
+ (e) => e.userId === user?.id
);
if (
@@ -25,7 +25,7 @@ export default function useCollectivePermissions(collectionIds: number[]) {
)
getPermission = undefined;
- setPermissions(user.id === collection.ownerId || getPermission);
+ setPermissions(user?.id === collection.ownerId || getPermission);
}
}
}, [user, collections, collectionIds]);
diff --git a/apps/web/hooks/usePermissions.tsx b/apps/web/hooks/usePermissions.tsx
index db73a4fc..054b3621 100644
--- a/apps/web/hooks/usePermissions.tsx
+++ b/apps/web/hooks/usePermissions.tsx
@@ -6,7 +6,7 @@ import { useUser } from "@linkwarden/router/user";
export default function usePermissions(collectionId: number) {
const { data: collections = [] } = useCollections();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const [permissions, setPermissions] = useState<Member | true>();
useEffect(() => {
@@ -14,7 +14,7 @@ export default function usePermissions(collectionId: number) {
if (collection) {
let getPermission: Member | undefined = collection.members.find(
- (e) => e.userId === user.id
+ (e) => e.userId === user?.id
);
if (
@@ -24,7 +24,7 @@ export default function usePermissions(collectionId: number) {
)
getPermission = undefined;
- setPermissions(user.id === collection.ownerId || getPermission);
+ setPermissions(user?.id === collection.ownerId || getPermission);
}
}, [user, collections, collectionId]);
diff --git a/apps/web/layouts/AuthRedirect.tsx b/apps/web/layouts/AuthRedirect.tsx
index 54ec082c..cf6a2d65 100644
--- a/apps/web/layouts/AuthRedirect.tsx
+++ b/apps/web/layouts/AuthRedirect.tsx
@@ -14,7 +14,7 @@ export default function AuthRedirect({ children }: Props) {
const router = useRouter();
const { status } = useSession();
const [shouldRenderChildren, setShouldRenderChildren] = useState(false);
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
useInitialData();
@@ -23,8 +23,8 @@ export default function AuthRedirect({ children }: Props) {
const isUnauthenticated = status === "unauthenticated";
const isPublicPage = router.pathname.startsWith("/public");
const hasInactiveSubscription =
- user.id &&
- !user.subscription?.active &&
+ user?.id &&
+ !user?.subscription?.active &&
!user.parentSubscription?.active &&
stripeEnabled;
@@ -52,7 +52,7 @@ export default function AuthRedirect({ children }: Props) {
} else {
if (isLoggedIn && hasInactiveSubscription) {
redirectTo("/subscribe");
- } else if (isLoggedIn && !user.name && user.parentSubscriptionId) {
+ } else if (isLoggedIn && !user?.name && user?.parentSubscriptionId) {
redirectTo("/member-onboarding");
} else if (
isLoggedIn &&
diff --git a/apps/web/layouts/CenteredForm.tsx b/apps/web/layouts/CenteredForm.tsx
index 5367dd62..4d416ea5 100644
--- a/apps/web/layouts/CenteredForm.tsx
+++ b/apps/web/layouts/CenteredForm.tsx
@@ -3,6 +3,7 @@ import Image from "next/image";
import Link from "next/link";
import React, { ReactNode } from "react";
import { Trans } from "next-i18next";
+import { useUser } from "@linkwarden/router/user";
interface Props {
text?: string;
@@ -15,7 +16,7 @@ export default function CenteredForm({
children,
"data-testid": dataTestId,
}: Props) {
- const { settings } = useLocalSettingsStore();
+ const { data: user } = useUser();
return (
<div
@@ -23,11 +24,9 @@ export default function CenteredForm({
data-testid={dataTestId}
>
<div className="m-auto flex flex-col gap-2 w-full">
- {settings.theme && (
+ {user?.theme && (
<Image
- src={`/linkwarden_${
- settings.theme === "dark" ? "dark" : "light"
- }.png`}
+ src={`/linkwarden_${user?.theme === "dark" ? "dark" : "light"}.png`}
width={640}
height={136}
alt="Linkwarden"
diff --git a/apps/web/lib/api/controllers/users/userId/getUserById.ts b/apps/web/lib/api/controllers/users/userId/getUserById.ts
index 2da14719..a8f10b6a 100644
--- a/apps/web/lib/api/controllers/users/userId/getUserById.ts
+++ b/apps/web/lib/api/controllers/users/userId/getUserById.ts
@@ -45,8 +45,16 @@ export default async function getUserById(userId: number) {
},
},
} as Omit<User, "password"> &
- Partial<WhitelistedUser> &
- Partial<Subscription>;
+ Partial<{ subscription: Subscription }> & {
+ parentSubscription: {
+ active: boolean | undefined;
+ user: {
+ email: string | null | undefined;
+ };
+ };
+ } & {
+ whitelistedUsers: string[];
+ };
return { response: data, status: 200 };
}
diff --git a/apps/web/lib/client/openLink.ts b/apps/web/lib/client/openLink.ts
index 756360a4..d905ce8a 100644
--- a/apps/web/lib/client/openLink.ts
+++ b/apps/web/lib/client/openLink.ts
@@ -7,7 +7,7 @@ import { LinksRouteTo } from "@linkwarden/prisma/client";
const openLink = (
link: LinkIncludingShortenedCollectionAndTags,
- user: AccountSettings,
+ user: any,
openModal: () => void
) => {
if (user.linksRouteTo === LinksRouteTo.DETAILS) {
diff --git a/apps/web/lib/client/pinLink.ts b/apps/web/lib/client/pinLink.ts
index 09ef7805..f028fedf 100644
--- a/apps/web/lib/client/pinLink.ts
+++ b/apps/web/lib/client/pinLink.ts
@@ -7,7 +7,7 @@ import { useUser } from "@linkwarden/router/user";
const usePinLink = () => {
const { t } = useTranslation();
const updateLink = useUpdateLink();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
// Return a function that can be used to pin/unpin the link
const pinLink = async (link: LinkIncludingShortenedCollectionAndTags) => {
@@ -19,7 +19,9 @@ const usePinLink = () => {
await updateLink.mutateAsync(
{
...link,
- pinnedBy: isAlreadyPinned ? [{ id: undefined }] : [{ id: user.id }],
+ pinnedBy: (isAlreadyPinned
+ ? [{ id: undefined }]
+ : [{ id: user?.id }]) as any,
},
{
onSettled: (data, error) => {
diff --git a/apps/web/pages/collections/[id].tsx b/apps/web/pages/collections/[id].tsx
index a47b2795..2447305a 100644
--- a/apps/web/pages/collections/[id].tsx
+++ b/apps/web/pages/collections/[id].tsx
@@ -10,7 +10,6 @@ import MainLayout from "@/layouts/MainLayout";
import ProfilePhoto from "@/components/ProfilePhoto";
import usePermissions from "@/hooks/usePermissions";
import NoLinksFound from "@/components/NoLinksFound";
-import useLocalSettingsStore from "@/store/localSettings";
import getPublicUserData from "@/lib/client/getPublicUserData";
import EditCollectionModal from "@/components/ModalContent/EditCollectionModal";
import EditCollectionSharingModal from "@/components/ModalContent/EditCollectionSharingModal";
@@ -38,8 +37,6 @@ import { Button } from "@/components/ui/button";
export default function Index() {
const { t } = useTranslation();
- const { settings } = useLocalSettingsStore();
-
const router = useRouter();
const { data: collections = [] } = useCollections();
@@ -64,7 +61,7 @@ export default function Index() {
);
}, [router, collections]);
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const [collectionOwner, setCollectionOwner] = useState<
Partial<AccountSettings>
@@ -72,20 +69,20 @@ export default function Index() {
useEffect(() => {
const fetchOwner = async () => {
- if (activeCollection && activeCollection.ownerId !== user.id) {
+ if (activeCollection && activeCollection.ownerId !== user?.id) {
const owner = await getPublicUserData(
activeCollection.ownerId as number
);
setCollectionOwner(owner);
- } else if (activeCollection && activeCollection.ownerId === user.id) {
+ } else if (activeCollection && activeCollection.ownerId === user?.id) {
setCollectionOwner({
- id: user.id as number,
- name: user.name,
- username: user.username as string,
- image: user.image as string,
- archiveAsScreenshot: user.archiveAsScreenshot as boolean,
- archiveAsMonolith: user.archiveAsScreenshot as boolean,
- archiveAsPDF: user.archiveAsPDF as boolean,
+ id: user?.id as number,
+ name: user?.name,
+ username: user?.username as string,
+ image: user?.image as string,
+ archiveAsScreenshot: user?.archiveAsScreenshot as boolean,
+ archiveAsMonolith: user?.archiveAsMonolith as boolean,
+ archiveAsPDF: user?.archiveAsPDF as boolean,
});
}
};
@@ -114,8 +111,8 @@ export default function Index() {
className="p-5 flex gap-3 flex-col"
style={{
backgroundImage: `linear-gradient(${activeCollection?.color}20 0%, ${
- settings.theme === "dark" ? "#262626" : "#f3f4f6"
- } 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
+ user?.theme === "dark" ? "#262626" : "#f3f4f6"
+ } 13rem, ${user?.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
}}
>
{activeCollection && (
diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsx
index 5232f3c4..8d392c53 100644
--- a/apps/web/pages/dashboard.tsx
+++ b/apps/web/pages/dashboard.tsx
@@ -28,7 +28,7 @@ export default function Dashboard() {
...dashboardData
} = useDashboardData();
const { data: tags = [] } = useTags();
- const { data: account = [] } = useUser();
+ const { data: account } = useUser();
const [numberOfLinks, setNumberOfLinks] = useState(0);
@@ -61,7 +61,7 @@ export default function Dashboard() {
}, [account]);
const numberOfLinksToShow = useMemo(() => {
- if (account.dashboardRecentLinks && account.dashboardPinnedLinks) {
+ if (account?.dashboardRecentLinks && account?.dashboardPinnedLinks) {
if (window.innerWidth > 1900) {
return 10;
} else if (window.innerWidth > 1500) {
@@ -76,7 +76,7 @@ export default function Dashboard() {
} else {
return 100;
}
- }, [account.dashboardRecentLinks, account.dashboardPinnedLinks]);
+ }, [account?.dashboardRecentLinks, account?.dashboardPinnedLinks]);
const [newLinkModal, setNewLinkModal] = useState(false);
@@ -158,7 +158,7 @@ export default function Dashboard() {
/>
</div>
- {account.dashboardRecentLinks && (
+ {account?.dashboardRecentLinks && (
<>
<div className="flex justify-between items-center">
<div className="flex gap-2 items-center">
@@ -234,7 +234,7 @@ export default function Dashboard() {
</>
)}
- {account.dashboardPinnedLinks && (
+ {account?.dashboardPinnedLinks && (
<>
<div className="flex justify-between items-center">
<div className="flex gap-2 items-center">
diff --git a/apps/web/pages/member-onboarding.tsx b/apps/web/pages/member-onboarding.tsx
index 8f45a176..10e07a0a 100644
--- a/apps/web/pages/member-onboarding.tsx
+++ b/apps/web/pages/member-onboarding.tsx
@@ -24,7 +24,7 @@ export default function MemberOnboarding() {
name: "",
});
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
const updateUser = useUpdateUser();
async function submit(event: FormEvent<HTMLFormElement>) {
diff --git a/apps/web/pages/public/collections/[id]/index.tsx b/apps/web/pages/public/collections/[id]/index.tsx
index a42d043e..54115f27 100644
--- a/apps/web/pages/public/collections/[id]/index.tsx
+++ b/apps/web/pages/public/collections/[id]/index.tsx
@@ -14,7 +14,6 @@ import ToggleDarkMode from "@/components/ToggleDarkMode";
import getPublicUserData from "@/lib/client/getPublicUserData";
import Image from "next/image";
import Link from "next/link";
-import useLocalSettingsStore from "@/store/localSettings";
import SearchBar from "@/components/SearchBar";
import EditCollectionSharingModal from "@/components/ModalContent/EditCollectionSharingModal";
import { useTranslation } from "next-i18next";
@@ -30,11 +29,12 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
+import { useUser } from "@linkwarden/router/user";
export default function PublicCollections() {
const { t } = useTranslation();
- const { settings } = useLocalSettingsStore();
+ const { data: user } = useUser();
const router = useRouter();
@@ -103,8 +103,8 @@ export default function PublicCollections() {
className="h-96"
style={{
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
- settings.theme === "dark" ? "#262626" : "#f3f4f6"
- } 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
+ user?.theme === "dark" ? "#262626" : "#f3f4f6"
+ } 13rem, ${user?.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
}}
>
{collection && (
diff --git a/apps/web/pages/settings/account.tsx b/apps/web/pages/settings/account.tsx
index 369d23a7..1bb4ad83 100644
--- a/apps/web/pages/settings/account.tsx
+++ b/apps/web/pages/settings/account.tsx
@@ -31,8 +31,8 @@ export default function Account() {
const [submitLoader, setSubmitLoader] = useState(false);
const { data: account } = useUser();
const updateUser = useUpdateUser();
- const [user, setUser] = useState<AccountSettings>(
- account.id
+ const [user, setUser] = useState<any>(
+ account?.id
? account
: ({
// @ts-ignore
@@ -57,7 +57,7 @@ export default function Account() {
const [whitelistedUsersTextbox, setWhiteListedUsersTextbox] = useState("");
useEffect(() => {
- if (!account.id) return;
+ if (!account?.id) return;
setUser({
...account,
@@ -128,7 +128,7 @@ export default function Account() {
}
);
- if (user.locale !== account.locale) {
+ if (user.locale !== account?.locale) {
setTimeout(() => {
location.reload();
}, 1000);
@@ -136,7 +136,7 @@ export default function Account() {
};
useEffect(() => {
- setWhiteListedUsersTextbox(account?.whitelistedUsers?.join(", "));
+ setWhiteListedUsersTextbox(account?.whitelistedUsers?.join(", ") || "");
}, [account]);
const stringToArray = (str: string) => {
@@ -289,7 +289,7 @@ export default function Account() {
<Button
variant="accent"
onClick={() => {
- if (account.email !== user.email) {
+ if (account?.email !== user.email) {
setEmailChangeVerificationModal(true);
} else {
submit();
@@ -353,7 +353,7 @@ export default function Account() {
<EmailChangeVerificationModal
onClose={() => setEmailChangeVerificationModal(false)}
onSubmit={submit}
- oldEmail={account.email || ""}
+ oldEmail={account?.email || ""}
newEmail={user.email || ""}
/>
)}
diff --git a/apps/web/pages/settings/billing.tsx b/apps/web/pages/settings/billing.tsx
index 8f8b90df..28358a47 100644
--- a/apps/web/pages/settings/billing.tsx
+++ b/apps/web/pages/settings/billing.tsx
@@ -39,7 +39,7 @@ export default function Billing() {
const { data: users = [] } = useUsers();
useEffect(() => {
- if (!process.env.NEXT_PUBLIC_STRIPE || account.parentSubscriptionId)
+ if (!process.env.NEXT_PUBLIC_STRIPE || account?.parentSubscriptionId)
router.push("/settings/account");
}, []);
@@ -158,7 +158,7 @@ export default function Billing() {
key={index}
className={clsx(
"group border-b-neutral-content duration-100 w-full relative flex flex-col sm:table-row",
- user.id !== account.id &&
+ user.id !== account?.id &&
"hover:bg-neutral-content hover:bg-opacity-30"
)}
>
@@ -198,7 +198,7 @@ export default function Billing() {
})}
</p>
</td>
- {user.id !== account.id && (
+ {user.id !== account?.id && (
<td className="relative">
<DropdownMenu>
<DropdownMenuTrigger asChild>
diff --git a/apps/web/pages/settings/delete.tsx b/apps/web/pages/settings/delete.tsx
index a6a680b0..44c56fee 100644
--- a/apps/web/pages/settings/delete.tsx
+++ b/apps/web/pages/settings/delete.tsx
@@ -89,7 +89,7 @@ export default function Delete() {
/>
</div>
- {process.env.NEXT_PUBLIC_STRIPE && !user.parentSubscriptionId && (
+ {process.env.NEXT_PUBLIC_STRIPE && !user?.parentSubscriptionId && (
<fieldset className="border rounded-md p-2 border-primary">
<legend className="px-3 py-1 text-sm sm:text-base border rounded-md border-primary">
<b>{t("optional")}</b> <i>{t("feedback_help")}</i>
diff --git a/apps/web/pages/settings/preference.tsx b/apps/web/pages/settings/preference.tsx
index aaa9ca7d..a3d655a8 100644
--- a/apps/web/pages/settings/preference.tsx
+++ b/apps/web/pages/settings/preference.tsx
@@ -6,7 +6,11 @@ import useLocalSettingsStore from "@/store/localSettings";
import { useTranslation } from "next-i18next";
import getServerSideProps from "@/lib/client/getServerSideProps";
import { AiTaggingMethod, LinksRouteTo } from "@linkwarden/prisma/client";
-import { useUpdateUser, useUser } from "@linkwarden/router/user";
+import {
+ useUpdateUser,
+ useUpdateUserPreference,
+ useUser,
+} from "@linkwarden/router/user";
import { useConfig } from "@linkwarden/router/config";
import { useTags, useUpdateArchivalTags } from "@linkwarden/router/tags";
import TagSelection from "@/components/InputSelect/TagSelection";
@@ -23,8 +27,9 @@ import {
export default function Preference() {
const { t } = useTranslation();
const { settings, updateSettings } = useLocalSettingsStore();
+ const updateUserPreference = useUpdateUserPreference();
const [submitLoader, setSubmitLoader] = useState(false);
- const { data: account } = useUser();
+ const { data: account } = useUser() as any;
const { data: tags } = useTags();
const updateArchivalTags = useUpdateArchivalTags();
const {
@@ -223,7 +228,9 @@ export default function Preference() {
? `outline-primary ${activeColor}`
: textColor
}`}
- onClick={() => updateSettings({ theme })}
+ onClick={() =>
+ updateUserPreference.mutate({ theme: theme as any })
+ }
>
<i className={`${icon} text-3xl`}></i>
<p className="ml-2 text-xl">{t(theme)}</p>
diff --git a/apps/web/pages/subscribe.tsx b/apps/web/pages/subscribe.tsx
index ac5fc7e4..dc91058f 100644
--- a/apps/web/pages/subscribe.tsx
+++ b/apps/web/pages/subscribe.tsx
@@ -18,13 +18,13 @@ export default function Subscribe() {
const router = useRouter();
- const { data: user = {} } = useUser();
+ const { data: user } = useUser();
useEffect(() => {
if (
session.status === "authenticated" &&
- user.id &&
- (user?.subscription?.active || user.parentSubscription?.active)
+ user?.id &&
+ (user?.subscription?.active || user?.parentSubscription?.active)
)
router.push("/dashboard");
}, [session.status, user]);
diff --git a/packages/router/user.tsx b/packages/router/user.tsx
index 6d3dbb45..6a3bed9f 100644
--- a/packages/router/user.tsx
+++ b/packages/router/user.tsx
@@ -38,8 +38,16 @@ const useUser = (auth?: MobileAuth) => {
if (!response.ok) throw new Error("Failed to fetch user data.");
const data = (await response.json()).response as Omit<User, "password"> &
- Partial<WhitelistedUser> &
- Partial<Subscription>;
+ Partial<{ subscription: Subscription }> & {
+ parentSubscription: {
+ active: boolean | undefined;
+ user: {
+ email: string | null | undefined;
+ };
+ };
+ } & {
+ whitelistedUsers: string[];
+ };
document.querySelector("html")?.setAttribute("data-theme", data.theme);
@@ -49,8 +57,16 @@ const useUser = (auth?: MobileAuth) => {
? !!userId && status === "authenticated"
: status === "authenticated",
placeholderData: {} as Omit<User, "password"> &
- Partial<WhitelistedUser> &
- Partial<Subscription>,
+ Partial<{ subscription: Subscription }> & {
+ parentSubscription: {
+ active: boolean | undefined;
+ user: {
+ email: string | null | undefined;
+ };
+ };
+ } & {
+ whitelistedUsers: string[];
+ },
});
};
@@ -103,8 +119,16 @@ const useUpdateUserPreference = () => {
if (!response.ok) throw new Error(data.response);
return data.response as Omit<User, "password"> &
- Partial<WhitelistedUser> &
- Partial<Subscription>;
+ Partial<{ subscription: Subscription }> & {
+ parentSubscription: {
+ active: boolean | undefined;
+ user: {
+ email: string | null | undefined;
+ };
+ };
+ } & {
+ whitelistedUsers: string[];
+ };
},
onSuccess: (data) => {
queryClient.setQueryData(["user"], data);