Skip to content

Commit

Permalink
✨ feat: Add Toaster component for notifications and enhance error han…
Browse files Browse the repository at this point in the history
…dling in bookmark deletion
  • Loading branch information
vaayne committed Dec 31, 2024
1 parent c75d016 commit 1b390fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions web/src/lib/apis/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const fetcher = async <T>(url: string, init?: RequestInit): Promise<T> => {

throw error;
}

if (response.status === 204) {
return {} as T;
}

const data = await response.json();
return data.data;
};
Expand Down
2 changes: 2 additions & 0 deletions web/src/pages/app-basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type ReactNode, StrictMode } from "react";
import "../index.css";

import { ThemeProvider } from "@/components/theme-provider";
import { Toaster } from "@/components/ui/toaster";
import { NuqsAdapter } from "nuqs/adapters/react";
import { SWRConfig } from "swr";
import fetcher from "../lib/apis/fetcher";
Expand All @@ -18,6 +19,7 @@ export default function App({ children }: { children: ReactNode }) {
}}
>
<NuqsAdapter>{children}</NuqsAdapter>
<Toaster />
</SWRConfig>
</ThemeProvider>
</StrictMode>
Expand Down
4 changes: 3 additions & 1 deletion web/src/pages/bookmark-detail-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "@/components/ui/sidebar";
import { useToast } from "@/hooks/use-toast";
import { useBookmark, useBookmarkMutations } from "@/lib/apis/bookmarks";
import { ROUTES } from "@/lib/router";
import { useState } from "react";

export default function BookmarkDetailPage({ id }: { id: string }) {
Expand Down Expand Up @@ -67,10 +68,11 @@ export default function BookmarkDetailPage({ id }: { id: string }) {
title: "Success",
description: "Bookmark deleted successfully",
});
window.location.href = ROUTES.BOOKMARKS;
} catch (error) {
toast({
title: "Error",
description: "Failed to delete bookmark",
description: `Failed to delete bookmark ${error instanceof Error ? error.message : 'Unknown error'}`,
variant: "destructive",
});
} finally {
Expand Down

0 comments on commit 1b390fd

Please sign in to comment.