fix link unreachable error not handled properly
This commit is contained in:
@@ -4,7 +4,7 @@ import { useEffect } from "react"
|
|||||||
|
|
||||||
enum ApiErrorCode {
|
enum ApiErrorCode {
|
||||||
BadRequestBody = "BadRequestBody",
|
BadRequestBody = "BadRequestBody",
|
||||||
WebsiteUnreachable = "WebsiteUnreachable",
|
LinkUnreachable = "LinkUnreachable",
|
||||||
UnsupportedWebsite = "UnsupportedWebsite",
|
UnsupportedWebsite = "UnsupportedWebsite",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -339,7 +339,15 @@ function BookmarkTagList({ bookmark }: { bookmark: Bookmark }) {
|
|||||||
case "pending":
|
case "pending":
|
||||||
return <LoadingSpinner />
|
return <LoadingSpinner />
|
||||||
case "success":
|
case "success":
|
||||||
return <p className="my-2 text-sm">{tags.map((tag) => `#${tag.name}`).join(" ")}</p>
|
return (
|
||||||
|
<div className="flex flex-row flex-wrap space-x-2">
|
||||||
|
{tags.map((tag) => (
|
||||||
|
<Link key={tag.id} to={`/bookmarks?tags=${tag.name}`}>
|
||||||
|
#{tag.name}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
case "error":
|
case "error":
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ function AddBookmarkDialog() {
|
|||||||
const getTags = useAtomCallback(
|
const getTags = useAtomCallback(
|
||||||
useCallback((get) => {
|
useCallback((get) => {
|
||||||
const value = get(tagsInputValueAtom)
|
const value = get(tagsInputValueAtom)
|
||||||
return value.split(" ")
|
return value.trim().split(" ")
|
||||||
}, []),
|
}, []),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ function AddBookmarkDialog() {
|
|||||||
await createBookmarkMutation.mutateAsync({ url, tags: getTags(), force: isWebsiteUnreachable })
|
await createBookmarkMutation.mutateAsync({ url, tags: getTags(), force: isWebsiteUnreachable })
|
||||||
setActiveDialog(ActiveDialog.None)
|
setActiveDialog(ActiveDialog.None)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof BadRequestError && error.code === ApiErrorCode.WebsiteUnreachable) {
|
if (error instanceof BadRequestError && error.code === ApiErrorCode.LinkUnreachable) {
|
||||||
setIsWebsiteUnreachable(true)
|
setIsWebsiteUnreachable(true)
|
||||||
} else {
|
} else {
|
||||||
setIsWebsiteUnreachable(false)
|
setIsWebsiteUnreachable(false)
|
||||||
|
@@ -35,9 +35,12 @@ function BookmarkListPane() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function BookmarkListContainer() {
|
function BookmarkListContainer() {
|
||||||
const { data: bookmarks, status } = useAuthenticatedQuery(["bookmarks"], () =>
|
const searchParams = Route.useSearch()
|
||||||
fetchApi("/bookmarks").then((res) => res.json()),
|
const { data: bookmarks, status } = useAuthenticatedQuery(["bookmarks"], () => {
|
||||||
)
|
const params = new URLSearchParams(searchParams)
|
||||||
|
console.log("params", params)
|
||||||
|
return fetchApi(params.size > 0 ? `/bookmarks?${params.toString()}` : "/bookmarks").then((res) => res.json())
|
||||||
|
})
|
||||||
const handleBookmarkListItemAction = useBookmarkPageStore((state) => state.handleBookmarkListItemAction)
|
const handleBookmarkListItemAction = useBookmarkPageStore((state) => state.handleBookmarkListItemAction)
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
|
Reference in New Issue
Block a user