From c2bd6d6b33dc24c4321228add4fedfade93eb014 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 17 Mar 2024 10:15:01 +0000 Subject: refactor: Prepare for pagination by dropping querying bookmarks by id --- apps/mobile/app/dashboard/(tabs)/index.tsx | 4 ++-- apps/mobile/app/dashboard/(tabs)/search.tsx | 2 +- apps/mobile/app/dashboard/archive.tsx | 2 +- apps/mobile/app/dashboard/favourites.tsx | 6 +++-- apps/mobile/app/dashboard/lists/[slug].tsx | 6 +++-- apps/mobile/app/dashboard/tags/[slug].tsx | 6 +++-- apps/mobile/components/bookmarks/BookmarkList.tsx | 18 +++++---------- apps/web/app/dashboard/lists/[listId]/page.tsx | 12 +++++++--- apps/web/app/dashboard/tags/[tagName]/page.tsx | 2 +- .../dashboard/bookmarks/AddToListModal.tsx | 5 ++--- .../components/dashboard/bookmarks/TagsEditor.tsx | 1 + apps/web/components/dashboard/lists/ListView.tsx | 26 ---------------------- 12 files changed, 35 insertions(+), 55 deletions(-) delete mode 100644 apps/web/components/dashboard/lists/ListView.tsx (limited to 'apps') diff --git a/apps/mobile/app/dashboard/(tabs)/index.tsx b/apps/mobile/app/dashboard/(tabs)/index.tsx index 1a17d472..7f70af6b 100644 --- a/apps/mobile/app/dashboard/(tabs)/index.tsx +++ b/apps/mobile/app/dashboard/(tabs)/index.tsx @@ -2,9 +2,9 @@ import { Platform, SafeAreaView, View } from "react-native"; import * as Haptics from "expo-haptics"; import { useRouter } from "expo-router"; import BookmarkList from "@/components/bookmarks/BookmarkList"; +import PageTitle from "@/components/ui/PageTitle"; import { MenuView } from "@react-native-menu/menu"; import { SquarePen } from "lucide-react-native"; -import PageTitle from "@/components/ui/PageTitle"; function HeaderRight() { const router = useRouter(); @@ -49,7 +49,7 @@ export default function Home() { return ( diff --git a/apps/mobile/app/dashboard/(tabs)/search.tsx b/apps/mobile/app/dashboard/(tabs)/search.tsx index 76e9aef9..25fc53d5 100644 --- a/apps/mobile/app/dashboard/(tabs)/search.tsx +++ b/apps/mobile/app/dashboard/(tabs)/search.tsx @@ -21,7 +21,7 @@ export default function Search() { {data && ( b.id)} + query={{ids: data.bookmarks.map((b) => b.id)}} header={ diff --git a/apps/mobile/app/dashboard/archive.tsx b/apps/mobile/app/dashboard/archive.tsx index 5c86c6fc..98a03631 100644 --- a/apps/mobile/app/dashboard/archive.tsx +++ b/apps/mobile/app/dashboard/archive.tsx @@ -5,7 +5,7 @@ import PageTitle from "@/components/ui/PageTitle"; export default function Archive() { return ( - } /> + } /> ); } diff --git a/apps/mobile/app/dashboard/favourites.tsx b/apps/mobile/app/dashboard/favourites.tsx index 6025d514..f62d561e 100644 --- a/apps/mobile/app/dashboard/favourites.tsx +++ b/apps/mobile/app/dashboard/favourites.tsx @@ -6,8 +6,10 @@ export default function Favourites() { return ( } /> diff --git a/apps/mobile/app/dashboard/lists/[slug].tsx b/apps/mobile/app/dashboard/lists/[slug].tsx index 0d1c01dc..8596b49f 100644 --- a/apps/mobile/app/dashboard/lists/[slug].tsx +++ b/apps/mobile/app/dashboard/lists/[slug].tsx @@ -24,8 +24,10 @@ export default function ListView() { {list ? ( } /> diff --git a/apps/mobile/app/dashboard/tags/[slug].tsx b/apps/mobile/app/dashboard/tags/[slug].tsx index 2d37b172..cb6e2ef4 100644 --- a/apps/mobile/app/dashboard/tags/[slug].tsx +++ b/apps/mobile/app/dashboard/tags/[slug].tsx @@ -25,8 +25,10 @@ export default function TagView() { {tag ? ( } /> diff --git a/apps/mobile/components/bookmarks/BookmarkList.tsx b/apps/mobile/components/bookmarks/BookmarkList.tsx index 04a3d922..e7b5e5f2 100644 --- a/apps/mobile/components/bookmarks/BookmarkList.tsx +++ b/apps/mobile/components/bookmarks/BookmarkList.tsx @@ -4,18 +4,16 @@ import Animated, { LinearTransition } from "react-native-reanimated"; import { api } from "@/lib/trpc"; import { useScrollToTop } from "@react-navigation/native"; +import type { ZGetBookmarksRequest } from "@hoarder/trpc/types/bookmarks"; + import FullPageSpinner from "../ui/FullPageSpinner"; import BookmarkCard from "./BookmarkCard"; export default function BookmarkList({ - favourited, - archived, - ids, - header + query, + header, }: { - favourited?: boolean; - archived?: boolean; - ids?: string[]; + query: ZGetBookmarksRequest; header?: React.ReactElement; }) { const apiUtils = api.useUtils(); @@ -23,11 +21,7 @@ export default function BookmarkList({ const flatListRef = useRef(null); useScrollToTop(flatListRef); const { data, isPending, isPlaceholderData } = - api.bookmarks.getBookmarks.useQuery({ - favourited, - archived, - ids, - }); + api.bookmarks.getBookmarks.useQuery(query); useEffect(() => { setRefreshing(isPending || isPlaceholderData); diff --git a/apps/web/app/dashboard/lists/[listId]/page.tsx b/apps/web/app/dashboard/lists/[listId]/page.tsx index 4e35c377..b9a26053 100644 --- a/apps/web/app/dashboard/lists/[listId]/page.tsx +++ b/apps/web/app/dashboard/lists/[listId]/page.tsx @@ -1,6 +1,6 @@ import { notFound, redirect } from "next/navigation"; +import BookmarksGrid from "@/components/dashboard/bookmarks/BookmarksGrid"; import DeleteListButton from "@/components/dashboard/lists/DeleteListButton"; -import ListView from "@/components/dashboard/lists/ListView"; import { api } from "@/server/api/client"; import { getServerAuthSession } from "@/server/auth"; import { TRPCError } from "@trpc/server"; @@ -27,7 +27,10 @@ export default async function ListPage({ throw e; } - const bookmarks = await api.bookmarks.getBookmarks({ ids: list.bookmarks }); + const bookmarks = await api.bookmarks.getBookmarks({ + listId: list.id, + archived: false, + }); return (
@@ -38,7 +41,10 @@ export default async function ListPage({

- + ); } diff --git a/apps/web/app/dashboard/tags/[tagName]/page.tsx b/apps/web/app/dashboard/tags/[tagName]/page.tsx index 0c5c1c1f..dee29c5e 100644 --- a/apps/web/app/dashboard/tags/[tagName]/page.tsx +++ b/apps/web/app/dashboard/tags/[tagName]/page.tsx @@ -28,8 +28,8 @@ export default async function TagPage({ } const query = { - ids: tag.bookmarks, archived: false, + tagId: tag.id, }; const bookmarks = await api.bookmarks.getBookmarks(query); diff --git a/apps/web/components/dashboard/bookmarks/AddToListModal.tsx b/apps/web/components/dashboard/bookmarks/AddToListModal.tsx index 6242aa27..b8cce66d 100644 --- a/apps/web/components/dashboard/bookmarks/AddToListModal.tsx +++ b/apps/web/components/dashboard/bookmarks/AddToListModal.tsx @@ -52,7 +52,6 @@ export default function AddToListModal({ const { data: lists, isPending: isFetchingListsPending } = api.lists.list.useQuery(); - const listInvalidationFunction = api.useUtils().lists.get.invalidate; const bookmarksInvalidationFunction = api.useUtils().bookmarks.getBookmarks.invalidate; @@ -62,8 +61,8 @@ export default function AddToListModal({ toast({ description: "List has been updated!", }); - listInvalidationFunction({ listId: req.listId }); - bookmarksInvalidationFunction(); + setOpen(false); + bookmarksInvalidationFunction({ listId: req.listId }); }, onError: (e) => { if (e.data?.code == "BAD_REQUEST") { diff --git a/apps/web/components/dashboard/bookmarks/TagsEditor.tsx b/apps/web/components/dashboard/bookmarks/TagsEditor.tsx index 8bfbce19..12c0dcd0 100644 --- a/apps/web/components/dashboard/bookmarks/TagsEditor.tsx +++ b/apps/web/components/dashboard/bookmarks/TagsEditor.tsx @@ -75,6 +75,7 @@ export function TagsEditor({ bookmark }: { bookmark: ZBookmark }) { description: "Tags has been updated!", }); bookmarkInvalidationFunction({ bookmarkId: bookmark.id }); + // TODO(bug) Invalidate the tag views as well }, onError: () => { toast({ diff --git a/apps/web/components/dashboard/lists/ListView.tsx b/apps/web/components/dashboard/lists/ListView.tsx deleted file mode 100644 index beeea7f1..00000000 --- a/apps/web/components/dashboard/lists/ListView.tsx +++ /dev/null @@ -1,26 +0,0 @@ -"use client"; - -import BookmarksGrid from "@/components/dashboard/bookmarks/BookmarksGrid"; -import { api } from "@/lib/trpc"; - -import type { ZBookmark } from "@hoarder/trpc/types/bookmarks"; -import type { ZBookmarkListWithBookmarks } from "@hoarder/trpc/types/lists"; - -export default function ListView({ - bookmarks, - list: initialData, -}: { - list: ZBookmarkListWithBookmarks; - bookmarks: ZBookmark[]; -}) { - const { data } = api.lists.get.useQuery( - { listId: initialData.id }, - { - initialData, - }, - ); - - return ( - - ); -} -- cgit v1.2.3-70-g09d2