forked from hoarder-app/hoarder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Extract the bookmark polling logic into a separate shared c…
…omponent
- Loading branch information
1 parent
546139e
commit 6928800
Showing
5 changed files
with
75 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { api } from "@/lib/trpc"; | ||
|
||
import type { ZBookmark } from "@hoarder/shared/types/bookmarks"; | ||
import { isBookmarkStillLoading } from "@hoarder/shared-react/utils/bookmarkUtils"; | ||
|
||
import AssetCard from "./AssetCard"; | ||
import LinkCard from "./LinkCard"; | ||
import TextCard from "./TextCard"; | ||
|
||
export default function BookmarkCard({ | ||
bookmark: initialData, | ||
className, | ||
}: { | ||
bookmark: ZBookmark; | ||
className?: string; | ||
}) { | ||
const { data: bookmark } = api.bookmarks.getBookmark.useQuery( | ||
{ | ||
bookmarkId: initialData.id, | ||
}, | ||
{ | ||
initialData, | ||
refetchInterval: (query) => { | ||
const data = query.state.data; | ||
if (!data) { | ||
return false; | ||
} | ||
if (isBookmarkStillLoading(data)) { | ||
return 1000; | ||
} | ||
return false; | ||
}, | ||
}, | ||
); | ||
|
||
switch (bookmark.content.type) { | ||
case "link": | ||
return ( | ||
<LinkCard | ||
className={className} | ||
bookmark={{ ...bookmark, content: bookmark.content }} | ||
/> | ||
); | ||
case "text": | ||
return ( | ||
<TextCard | ||
className={className} | ||
bookmark={{ ...bookmark, content: bookmark.content }} | ||
/> | ||
); | ||
case "asset": | ||
return ( | ||
<AssetCard | ||
className={className} | ||
bookmark={{ ...bookmark, content: bookmark.content }} | ||
/> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters