From fb1869ca7a9d4abd6ad812a36f2a3e397e05fb6d Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Tue, 10 Sep 2024 00:09:33 -0400 Subject: [PATCH] fix dashboard bug --- .../LinkViews/LinkComponents/LinkActions.tsx | 14 +++-- .../LinkViews/LinkComponents/LinkList.tsx | 7 ++- components/ViewDropdown.tsx | 56 ++++++++++--------- hooks/store/dashboardData.tsx | 7 +-- .../dashboard/getDashboardDataV2.ts | 4 +- pages/dashboard.tsx | 32 +++++------ 6 files changed, 65 insertions(+), 55 deletions(-) diff --git a/components/LinkViews/LinkComponents/LinkActions.tsx b/components/LinkViews/LinkComponents/LinkActions.tsx index 65ebf59..2076932 100644 --- a/components/LinkViews/LinkComponents/LinkActions.tsx +++ b/components/LinkViews/LinkComponents/LinkActions.tsx @@ -12,14 +12,16 @@ import { useDeleteLink, useGetLink, useUpdateLink } from "@/hooks/store/links"; import toast from "react-hot-toast"; import LinkModal from "@/components/ModalContent/LinkModal"; import { useRouter } from "next/router"; +import clsx from "clsx"; type Props = { link: LinkIncludingShortenedCollectionAndTags; collection: CollectionIncludingMembersAndLinkCount; className?: string; + btnStyle?: string; }; -export default function LinkActions({ link, className }: Props) { +export default function LinkActions({ link, className, btnStyle }: Props) { const { t } = useTranslation(); const permissions = usePermissions(link.collection.id as number); @@ -85,13 +87,17 @@ export default function LinkActions({ link, className }: Props) { <> {isPublicRoute ? (
setLinkModal(true)} > -
+
@@ -105,7 +111,7 @@ export default function LinkActions({ link, className }: Props) { tabIndex={0} role="button" onMouseDown={dropdownTriggerer} - className="btn btn-sm btn-square text-neutral" + className={clsx("btn btn-sm btn-square text-neutral", btnStyle)} >
diff --git a/components/LinkViews/LinkComponents/LinkList.tsx b/components/LinkViews/LinkComponents/LinkList.tsx index 4433fdc..da301b4 100644 --- a/components/LinkViews/LinkComponents/LinkList.tsx +++ b/components/LinkViews/LinkComponents/LinkList.tsx @@ -93,7 +93,7 @@ export default function LinkCardCompact({ link, editMode }: Props) { return ( <>
@@ -137,7 +137,10 @@ export default function LinkCardCompact({ link, editMode }: Props) {
diff --git a/components/ViewDropdown.tsx b/components/ViewDropdown.tsx index eaa5bdb..ce2a368 100644 --- a/components/ViewDropdown.tsx +++ b/components/ViewDropdown.tsx @@ -114,32 +114,36 @@ export default function ViewDropdown({ viewMode, setViewMode }: Props) { ))} -

- {t("columns")}:{" "} - {settings.columns === 0 ? t("default") : settings.columns} -

-
- onColumnsChange(e)} - className="range range-xs range-primary" - step="1" - /> -
- | - | - | - | - | - | - | - | - | -
-
+ {settings.viewMode !== ViewMode.List && ( + <> +

+ {t("columns")}:{" "} + {settings.columns === 0 ? t("default") : settings.columns} +

+
+ onColumnsChange(e)} + className="range range-xs range-primary" + step="1" + /> +
+ | + | + | + | + | + | + | + | + | +
+
+ + )} ); diff --git a/hooks/store/dashboardData.tsx b/hooks/store/dashboardData.tsx index d808ffd..bea733a 100644 --- a/hooks/store/dashboardData.tsx +++ b/hooks/store/dashboardData.tsx @@ -1,4 +1,3 @@ -import { LinkIncludingShortenedCollectionAndTags } from "@/types/global"; import { useQuery } from "@tanstack/react-query"; import { useSession } from "next-auth/react"; @@ -7,11 +6,11 @@ const useDashboardData = () => { return useQuery({ queryKey: ["dashboardData"], - queryFn: async (): Promise => { - const response = await fetch("/api/v1/dashboard"); + queryFn: async () => { + const response = await fetch("/api/v2/dashboard"); const data = await response.json(); - return data.response; + return data.data; }, enabled: status === "authenticated", }); diff --git a/lib/api/controllers/dashboard/getDashboardDataV2.ts b/lib/api/controllers/dashboard/getDashboardDataV2.ts index fa952c5..0f93ec6 100644 --- a/lib/api/controllers/dashboard/getDashboardDataV2.ts +++ b/lib/api/controllers/dashboard/getDashboardDataV2.ts @@ -48,7 +48,7 @@ export default async function getDashboardData( }); const pinnedLinks = await prisma.link.findMany({ - take: 10, + take: 16, where: { AND: [ { @@ -80,7 +80,7 @@ export default async function getDashboardData( }); const recentlyAddedLinks = await prisma.link.findMany({ - take: 10, + take: 16, where: { collection: { OR: [ diff --git a/pages/dashboard.tsx b/pages/dashboard.tsx index 0bdb525..eaebd34 100644 --- a/pages/dashboard.tsx +++ b/pages/dashboard.tsx @@ -16,17 +16,21 @@ import { useCollections } from "@/hooks/store/collections"; import { useTags } from "@/hooks/store/tags"; import { useDashboardData } from "@/hooks/store/dashboardData"; import Links from "@/components/LinkViews/Links"; +import useLocalSettingsStore from "@/store/localSettings"; export default function Dashboard() { const { t } = useTranslation(); const { data: collections = [] } = useCollections(); - const dashboardData = useDashboardData(); + const { data: { links = [] } = { links: [] }, ...dashboardData } = + useDashboardData(); const { data: tags = [] } = useTags(); const [numberOfLinks, setNumberOfLinks] = useState(0); const [showLinks, setShowLinks] = useState(3); + const { settings } = useLocalSettingsStore(); + useEffect(() => { setNumberOfLinks( collections.reduce( @@ -52,8 +56,10 @@ export default function Dashboard() { const { width } = useWindowDimensions(); useEffect(() => { - handleNumberOfLinksToShow(); - }, [width]); + settings.columns === 0 + ? handleNumberOfLinksToShow() + : setShowLinks(settings.columns); + }, [width, settings.columns]); const importBookmarks = async ( e: React.ChangeEvent, @@ -160,10 +166,7 @@ export default function Dashboard() {
@@ -175,14 +178,9 @@ export default function Dashboard() { useData={dashboardData} />
- ) : dashboardData.data && - dashboardData.data[0] && - !dashboardData.isLoading ? ( + ) : links && links[0] && !dashboardData.isLoading ? (
- +
) : (
@@ -317,11 +315,11 @@ export default function Dashboard() { useData={dashboardData} />
- ) : dashboardData.data?.some((e) => e.pinnedBy && e.pinnedBy[0]) ? ( + ) : links?.some((e: any) => e.pinnedBy && e.pinnedBy[0]) ? (
e.pinnedBy && e.pinnedBy[0]) + links={links + .filter((e: any) => e.pinnedBy && e.pinnedBy[0]) .slice(0, showLinks)} layout={viewMode} />