refactor: switched to sonner from shadcn toast

This commit is contained in:
2025-08-11 12:38:44 +05:30
parent 8b32824bb9
commit 5908579c2f
6 changed files with 76 additions and 139 deletions

View File

@@ -1,6 +1,5 @@
import { ThemeProvider } from "@/providers/themeProvider"; import { ThemeProvider } from "@/providers/themeProvider";
import { TooltipProvider } from "@/components/ui/tooltip"; import { TooltipProvider } from "@/components/ui/tooltip";
import { Toaster } from "@/components/ui/toaster";
import { AppContext } from "@/providers/appContextProvider"; import { AppContext } from "@/providers/appContextProvider";
import { DownloadState } from "@/types/download"; import { DownloadState } from "@/types/download";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
@@ -25,11 +24,10 @@ import { useNavigate } from "react-router-dom";
import { platform } from "@tauri-apps/plugin-os"; import { platform } from "@tauri-apps/plugin-os";
import { useMacOsRegisterer } from "@/helpers/use-macos-registerer"; import { useMacOsRegisterer } from "@/helpers/use-macos-registerer";
import useAppUpdater from "@/helpers/use-app-updater"; import useAppUpdater from "@/helpers/use-app-updater";
import { useToast } from "@/hooks/use-toast"; import { Toaster as Sonner } from "@/components/ui/sonner";
import { toast } from "sonner";
export default function App({ children }: { children: React.ReactNode }) { export default function App({ children }: { children: React.ReactNode }) {
const { toast } = useToast();
const { data: downloadStates, isSuccess: isSuccessFetchingDownloadStates } = useFetchAllDownloadStates(); const { data: downloadStates, isSuccess: isSuccessFetchingDownloadStates } = useFetchAllDownloadStates();
const { data: settings, isSuccess: isSuccessFetchingSettings } = useFetchAllSettings(); const { data: settings, isSuccess: isSuccessFetchingSettings } = useFetchAllSettings();
const { data: kvPairs, isSuccess: isSuccessFetchingKvPairs } = useFetchAllkVPairs(); const { data: kvPairs, isSuccess: isSuccessFetchingKvPairs } = useFetchAllkVPairs();
@@ -180,10 +178,8 @@ export default function App({ children }: { children: React.ReactNode }) {
let videoMetadata = await fetchVideoMetadata(url, selectedFormat, isPlaylist && playlistIndex && typeof playlistIndex === 'string' ? playlistIndex : undefined); let videoMetadata = await fetchVideoMetadata(url, selectedFormat, isPlaylist && playlistIndex && typeof playlistIndex === 'string' ? playlistIndex : undefined);
if (!videoMetadata) { if (!videoMetadata) {
console.error('Failed to fetch video metadata'); console.error('Failed to fetch video metadata');
toast({ toast.error("Download Failed", {
title: 'Download Failed', description: "yt-dlp failed to fetch video metadata. Please try again later.",
description: 'yt-dlp failed to fetch video metadata. Please try again later.',
variant: 'destructive',
}); });
return; return;
} }
@@ -865,10 +861,8 @@ export default function App({ children }: { children: React.ReactNode }) {
// show a toast and pause the download when yt-dlp exits unexpectedly // show a toast and pause the download when yt-dlp exits unexpectedly
useEffect(() => { useEffect(() => {
if (isErrored && !isErrorExpected) { if (isErrored && !isErrorExpected) {
toast({ toast.error("Download Failed", {
title: "Download Failed",
description: "yt-dlp exited unexpectedly. Please try again later", description: "yt-dlp exited unexpectedly. Please try again later",
variant: "destructive",
}); });
if (erroredDownloadId) { if (erroredDownloadId) {
downloadStatusUpdater.mutate({ download_id: erroredDownloadId, download_status: 'paused' }, { downloadStatusUpdater.mutate({ download_id: erroredDownloadId, download_status: 'paused' }, {
@@ -904,7 +898,7 @@ export default function App({ children }: { children: React.ReactNode }) {
<ThemeProvider defaultTheme={APP_THEME || "system"} storageKey="vite-ui-theme"> <ThemeProvider defaultTheme={APP_THEME || "system"} storageKey="vite-ui-theme">
<TooltipProvider delayDuration={1000}> <TooltipProvider delayDuration={1000}>
{children} {children}
<Toaster /> <Sonner closeButton />
</TooltipProvider> </TooltipProvider>
</ThemeProvider> </ThemeProvider>
</AppContext.Provider> </AppContext.Provider>

View File

@@ -15,6 +15,12 @@ const Toaster = ({ ...props }: ToasterProps) => {
"--normal-border": "var(--border)", "--normal-border": "var(--border)",
} as React.CSSProperties } as React.CSSProperties
} }
toastOptions={{
classNames: {
toast: "group",
icon: "group-data-[type=error]:!text-red-500 group-data-[type=success]:!text-green-500 group-data-[type=warning]:!text-amber-500 group-data-[type=info]:!text-sky-500",
},
}}
{...props} {...props}
/> />
) )

View File

@@ -1,11 +1,10 @@
import { useToast } from "@/hooks/use-toast"; import { toast } from "sonner";
import { useResetSettings, useSaveSettingsKey } from "@/services/mutations"; import { useResetSettings, useSaveSettingsKey } from "@/services/mutations";
import { useSettingsPageStatesStore } from "@/services/store"; import { useSettingsPageStatesStore } from "@/services/store";
import { useQueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
export function useSettings() { export function useSettings() {
const { toast } = useToast();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const setSettingsKey = useSettingsPageStatesStore(state => state.setSettingsKey); const setSettingsKey = useSettingsPageStatesStore(state => state.setSettingsKey);
const resetSettingsState = useSettingsPageStatesStore(state => state.resetSettings); const resetSettingsState = useSettingsPageStatesStore(state => state.resetSettings);
@@ -22,10 +21,8 @@ export function useSettings() {
onError: (error) => { onError: (error) => {
console.error("Error saving settings key:", error); console.error("Error saving settings key:", error);
queryClient.invalidateQueries({ queryKey: ["settings"] }); queryClient.invalidateQueries({ queryKey: ["settings"] });
toast({ toast.error("Failed to update settings", {
title: "Failed to update settings",
description: `Failed to update ${key}`, description: `Failed to update ${key}`,
variant: "destructive",
}); });
} }
}); });
@@ -39,26 +36,21 @@ export function useSettings() {
resetSettingsState(); resetSettingsState();
console.log("Settings reset successfully"); console.log("Settings reset successfully");
queryClient.invalidateQueries({ queryKey: ["settings"] }); queryClient.invalidateQueries({ queryKey: ["settings"] });
toast({ toast.success("Settings reset successfully", {
title: "Settings reset successfully",
description: "All settings have been reset to default.", description: "All settings have been reset to default.",
}); });
} catch (error) { } catch (error) {
console.error("Error resetting settings:", error); console.error("Error resetting settings:", error);
toast({ toast.error("Failed to reset settings", {
title: "Failed to reset settings",
description: "Failed to reset settings to default.", description: "Failed to reset settings to default.",
variant: "destructive",
}); });
return; return;
} }
}, },
onError: (error) => { onError: (error) => {
console.error("Error resetting settings:", error); console.error("Error resetting settings:", error);
toast({ toast.error("Failed to reset settings", {
title: "Failed to reset settings",
description: "Failed to reset settings to default.", description: "Failed to reset settings to default.",
variant: "destructive",
}); });
} }
}); });

View File

@@ -5,7 +5,7 @@ import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { useToast } from "@/hooks/use-toast"; import { toast } from "sonner";
import { useAppContext } from "@/providers/appContextProvider"; import { useAppContext } from "@/providers/appContextProvider";
import { useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useSettingsPageStatesStore } from "@/services/store"; import { useCurrentVideoMetadataStore, useDownloaderPageStatesStore, useSettingsPageStatesStore } from "@/services/store";
import { determineFileType, fileFormatFilter, formatBitrate, formatDurationString, formatFileSize, formatReleaseDate, formatYtStyleCount, isObjEmpty, sortByBitrate } from "@/utils"; import { determineFileType, fileFormatFilter, formatBitrate, formatDurationString, formatFileSize, formatReleaseDate, formatYtStyleCount, isObjEmpty, sortByBitrate } from "@/utils";
@@ -35,7 +35,6 @@ const searchFormSchema = z.object({
export default function DownloaderPage() { export default function DownloaderPage() {
const { fetchVideoMetadata, startDownload } = useAppContext(); const { fetchVideoMetadata, startDownload } = useAppContext();
const { toast } = useToast();
const videoUrl = useCurrentVideoMetadataStore((state) => state.videoUrl); const videoUrl = useCurrentVideoMetadataStore((state) => state.videoUrl);
const videoMetadata = useCurrentVideoMetadataStore((state) => state.videoMetadata); const videoMetadata = useCurrentVideoMetadataStore((state) => state.videoMetadata);
@@ -226,10 +225,8 @@ export default function DownloaderPage() {
if (!metadata || (metadata._type !== 'video' && metadata._type !== 'playlist') || (metadata && metadata._type === 'video' && metadata.formats.length <= 0) || (metadata && metadata._type === 'playlist' && metadata.entries.length <= 0)) { if (!metadata || (metadata._type !== 'video' && metadata._type !== 'playlist') || (metadata && metadata._type === 'video' && metadata.formats.length <= 0) || (metadata && metadata._type === 'playlist' && metadata.entries.length <= 0)) {
const showSearchError = useCurrentVideoMetadataStore.getState().showSearchError; const showSearchError = useCurrentVideoMetadataStore.getState().showSearchError;
if (showSearchError) { if (showSearchError) {
toast({ toast.error("Oops! No results found", {
title: 'Oops! No results found', description: "The provided URL does not contain any downloadable content or you are not connected to the internet. Please check the URL, your network connection and try again.",
description: 'The provided URL does not contain any downloadable content or you are not connected to the internet. Please check the URL, your network connection and try again.',
variant: "destructive"
}); });
} }
} }
@@ -307,20 +304,16 @@ export default function DownloaderPage() {
// If URL is invalid, just reset the flag // If URL is invalid, just reset the flag
setAutoSubmitSearch(false); setAutoSubmitSearch(false);
setRequestedUrl(''); setRequestedUrl('');
toast({ toast.error("Invalid URL", {
title: 'Invalid URL', description: "The provided URL is not valid.",
description: 'The provided URL is not valid.',
variant: "destructive"
}); });
} }
} else { } else {
// If metadata is loading, just reset the flag // If metadata is loading, just reset the flag
setAutoSubmitSearch(false); setAutoSubmitSearch(false);
setRequestedUrl(''); setRequestedUrl('');
toast({ toast.info("Search in progress", {
title: 'Search in progress', description: "There's a search in progress, Please try again later.",
description: 'Search in progress, try again later.',
variant: "destructive"
}); });
} }
} else { } else {
@@ -941,10 +934,8 @@ export default function DownloaderPage() {
// }); // });
} catch (error) { } catch (error) {
console.error('Download failed to start:', error); console.error('Download failed to start:', error);
toast({ toast.error("Failed to Start Download", {
title: 'Failed to Start Download', description: "There was an error initiating the download."
description: 'There was an error initiating the download.',
variant: "destructive"
}); });
} finally { } finally {
setIsStartingDownload(false); setIsStartingDownload(false);

View File

@@ -4,7 +4,7 @@ import { AspectRatio } from "@/components/ui/aspect-ratio";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Progress } from "@/components/ui/progress"; import { Progress } from "@/components/ui/progress";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { useToast } from "@/hooks/use-toast"; import { toast } from "sonner";
import { useAppContext } from "@/providers/appContextProvider"; import { useAppContext } from "@/providers/appContextProvider";
import { useDownloadActionStatesStore, useDownloadStatesStore, useLibraryPageStatesStore } from "@/services/store"; import { useDownloadActionStatesStore, useDownloadStatesStore, useLibraryPageStatesStore } from "@/services/store";
import { formatBitrate, formatCodec, formatDurationString, formatFileSize, formatSecToTimeString, formatSpeed } from "@/utils"; import { formatBitrate, formatCodec, formatDurationString, formatFileSize, formatSecToTimeString, formatSpeed } from "@/utils";
@@ -21,7 +21,6 @@ import Heading from "@/components/heading";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Badge } from "@/components/ui/badge"; import { Badge } from "@/components/ui/badge";
export default function LibraryPage() { export default function LibraryPage() {
const activeTab = useLibraryPageStatesStore(state => state.activeTab); const activeTab = useLibraryPageStatesStore(state => state.activeTab);
const setActiveTab = useLibraryPageStatesStore(state => state.setActiveTab); const setActiveTab = useLibraryPageStatesStore(state => state.setActiveTab);
@@ -34,7 +33,6 @@ export default function LibraryPage() {
const setIsDeleteFileChecked = useDownloadActionStatesStore(state => state.setIsDeleteFileChecked); const setIsDeleteFileChecked = useDownloadActionStatesStore(state => state.setIsDeleteFileChecked);
const { pauseDownload, resumeDownload, cancelDownload } = useAppContext() const { pauseDownload, resumeDownload, cancelDownload } = useAppContext()
const { toast } = useToast();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const downloadStateDeleter = useDeleteDownloadState(); const downloadStateDeleter = useDeleteDownloadState();
@@ -49,24 +47,19 @@ export default function LibraryPage() {
if (filePath && await fs.exists(filePath)) { if (filePath && await fs.exists(filePath)) {
try { try {
await invoke('open_file_with_app', { filePath: filePath, appName: app }).then(() => { await invoke('open_file_with_app', { filePath: filePath, appName: app }).then(() => {
toast({ toast.info("Opening file", {
title: 'Opening file',
description: `Opening the file with ${app ? app : 'default app'}.`, description: `Opening the file with ${app ? app : 'default app'}.`,
}) })
}); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast({ toast.error("Failed to open file", {
title: 'Failed to open file', description: "An error occurred while trying to open the file.",
description: 'An error occurred while trying to open the file.',
variant: "destructive"
}) })
} }
} else { } else {
toast({ toast.info("File unavailable", {
title: 'File unavailable', description: "The file you are trying to open does not exist.",
description: 'The file you are trying to open does not exist.',
variant: "destructive"
}) })
} }
} }
@@ -88,18 +81,15 @@ export default function LibraryPage() {
onSuccess: (data) => { onSuccess: (data) => {
console.log("Download State deleted successfully:", data); console.log("Download State deleted successfully:", data);
queryClient.invalidateQueries({ queryKey: ['download-states'] }); queryClient.invalidateQueries({ queryKey: ['download-states'] });
toast({ toast.success("Removed from downloads", {
title: 'Removed from downloads', description: "The download has been removed successfully.",
description: 'The download has been removed successfully.', });
})
}, },
onError: (error) => { onError: (error) => {
console.error("Failed to delete download state:", error); console.error("Failed to delete download state:", error);
toast({ toast.error("Failed to remove download", {
title: 'Failed to remove download', description: "An error occurred while trying to remove the download.",
description: 'An error occurred while trying to remove the download.', });
variant: "destructive"
})
} }
}) })
} }
@@ -112,26 +102,21 @@ export default function LibraryPage() {
await pauseDownload(state); await pauseDownload(state);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast({ toast.error("Failed to stop download", {
title: 'Failed to stop download',
description: `An error occurred while trying to stop the download for ${state.title}.`, description: `An error occurred while trying to stop the download for ${state.title}.`,
variant: "destructive"
}); });
} finally { } finally {
setIsPausingDownload(state.download_id, false); setIsPausingDownload(state.download_id, false);
} }
} }
if (ongoingDownloads.length === 0) { if (ongoingDownloads.length === 0) {
toast({ toast.success("Stopped ongoing downloads", {
title: 'Stopped ongoing downloads', description: "All ongoing downloads have been stopped successfully.",
description: 'All ongoing downloads have been stopped successfully.',
}); });
} }
} else { } else {
toast({ toast.info("No ongoing downloads", {
title: 'No ongoing downloads', description: "There are no ongoing downloads to stop.",
description: 'There are no ongoing downloads to stop.',
variant: "destructive"
}); });
} }
} }
@@ -374,16 +359,13 @@ export default function LibraryPage() {
setIsResumingDownload(state.download_id, true); setIsResumingDownload(state.download_id, true);
try { try {
await resumeDownload(state) await resumeDownload(state)
// toast({ // toast.success("Resumed Download", {
// title: 'Resumed Download', // description: "Download resumed, it will re-start shortly.",
// description: 'Download resumed, it will re-start shortly.',
// }) // })
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast({ toast.error("Failed to Resume Download", {
title: 'Failed to Resume Download', description: "An error occurred while trying to resume the download.",
description: 'An error occurred while trying to resume the download.',
variant: "destructive"
}) })
} finally { } finally {
setIsResumingDownload(state.download_id, false); setIsResumingDownload(state.download_id, false);
@@ -411,16 +393,13 @@ export default function LibraryPage() {
setIsPausingDownload(state.download_id, true); setIsPausingDownload(state.download_id, true);
try { try {
await pauseDownload(state) await pauseDownload(state)
// toast({ // toast.success("Paused Download", {
// title: 'Paused Download', // description: "Download paused successfully.",
// description: 'Download paused successfully.',
// }) // })
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast({ toast.error("Failed to Pause Download", {
title: 'Failed to Pause Download', description: "An error occurred while trying to pause the download."
description: 'An error occurred while trying to pause the download.',
variant: "destructive"
}) })
} finally { } finally {
setIsPausingDownload(state.download_id, false); setIsPausingDownload(state.download_id, false);
@@ -448,16 +427,13 @@ export default function LibraryPage() {
setIsCancelingDownload(state.download_id, true); setIsCancelingDownload(state.download_id, true);
try { try {
await cancelDownload(state) await cancelDownload(state)
toast({ toast.success("Canceled Download", {
title: 'Canceled Download', description: "Download canceled successfully.",
description: 'Download canceled successfully.',
}) })
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast({ toast.error("Failed to Cancel Download", {
title: 'Failed to Cancel Download', description: "An error occurred while trying to cancel the download.",
description: 'An error occurred while trying to cancel the download.',
variant: "destructive"
}) })
} finally { } finally {
setIsCancelingDownload(state.download_id, false); setIsCancelingDownload(state.download_id, false);

View File

@@ -6,7 +6,7 @@ import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrig
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { useToast } from "@/hooks/use-toast"; import { toast } from "sonner";
import { ArrowDownToLine, ArrowRight, BrushCleaning, EthernetPort, ExternalLink, FileVideo, Folder, FolderOpen, Info, Loader2, LucideIcon, Monitor, Moon, Radio, RotateCcw, RotateCw, Sun, Terminal, WandSparkles, Wifi, Wrench } from "lucide-react"; import { ArrowDownToLine, ArrowRight, BrushCleaning, EthernetPort, ExternalLink, FileVideo, Folder, FolderOpen, Info, Loader2, LucideIcon, Monitor, Moon, Radio, RotateCcw, RotateCw, Sun, Terminal, WandSparkles, Wifi, Wrench } from "lucide-react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { useEffect } from "react"; import { useEffect } from "react";
@@ -65,7 +65,6 @@ const rateLimitSchema = z.object({
}); });
export default function SettingsPage() { export default function SettingsPage() {
const { toast } = useToast();
const { setTheme } = useTheme(); const { setTheme } = useTheme();
const activeTab = useSettingsPageStatesStore(state => state.activeTab); const activeTab = useSettingsPageStatesStore(state => state.activeTab);
@@ -123,17 +122,14 @@ export default function SettingsPage() {
const openLink = async (url: string, app: string | null) => { const openLink = async (url: string, app: string | null) => {
try { try {
await invoke('open_file_with_app', { filePath: url, appName: app }).then(() => { await invoke('open_file_with_app', { filePath: url, appName: app }).then(() => {
toast({ toast.info("Opening link", {
title: 'Opening Link',
description: `Opening link with ${app ? app : 'default app'}.`, description: `Opening link with ${app ? app : 'default app'}.`,
}) })
}); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
toast({ toast.error("Failed to open link", {
title: 'Failed to open link', description: "An error occurred while trying to open the link.",
description: 'An error occurred while trying to open the link.',
variant: "destructive"
}) })
} }
} }
@@ -148,20 +144,16 @@ export default function SettingsPage() {
await fs.remove(filePath); await fs.remove(filePath);
} }
} }
toast({ toast.success("Temporary Downloads Cleaned", {
title: "Temporary Downloads Cleaned",
description: "All temporary downloads have been successfully cleaned up.", description: "All temporary downloads have been successfully cleaned up.",
}); });
} catch (e) { } catch (e) {
toast({ toast.error("Temporary Downloads Cleanup Failed", {
title: "Temporary Downloads Cleanup Failed",
description: "An error occurred while trying to clean up temporary downloads. Please try again.", description: "An error occurred while trying to clean up temporary downloads. Please try again.",
variant: "destructive",
}); });
} }
} else { } else {
toast({ toast.info("No Temporary Downloads", {
title: "No Temporary Downloads",
description: "There are no temporary downloads to clean up.", description: "There are no temporary downloads to clean up.",
}); });
} }
@@ -180,16 +172,13 @@ export default function SettingsPage() {
function handleProxyUrlSubmit(values: z.infer<typeof proxyUrlSchema>) { function handleProxyUrlSubmit(values: z.infer<typeof proxyUrlSchema>) {
try { try {
saveSettingsKey('proxy_url', values.url); saveSettingsKey('proxy_url', values.url);
toast({ toast.success("Proxy URL updated", {
title: "Proxy URL updated",
description: `Proxy URL changed to ${values.url}`, description: `Proxy URL changed to ${values.url}`,
}); });
} catch (error) { } catch (error) {
console.error("Error changing proxy URL:", error); console.error("Error changing proxy URL:", error);
toast({ toast.error("Failed to change proxy URL", {
title: "Failed to change proxy URL", description: "An error occurred while trying to change the proxy URL. Please try again.",
description: "Please try again.",
variant: "destructive",
}); });
} }
} }
@@ -207,16 +196,13 @@ export default function SettingsPage() {
function handleRateLimitSubmit(values: z.infer<typeof rateLimitSchema>) { function handleRateLimitSubmit(values: z.infer<typeof rateLimitSchema>) {
try { try {
saveSettingsKey('rate_limit', values.rate_limit); saveSettingsKey('rate_limit', values.rate_limit);
toast({ toast.success("Rate Limit updated", {
title: "Rate Limit updated",
description: `Rate Limit changed to ${values.rate_limit} bytes/s`, description: `Rate Limit changed to ${values.rate_limit} bytes/s`,
}); });
} catch (error) { } catch (error) {
console.error("Error changing rate limit:", error); console.error("Error changing rate limit:", error);
toast({ toast.error("Failed to change rate limit", {
title: "Failed to change rate limit", description: "An error occurred while trying to change the rate limit. Please try again.",
description: "Please try again.",
variant: "destructive",
}); });
} }
} }
@@ -245,16 +231,13 @@ export default function SettingsPage() {
} }
}); });
saveSettingsKey('websocket_port', updatedConfig.port); saveSettingsKey('websocket_port', updatedConfig.port);
toast({ toast.success("Websocket port updated", {
title: "Websocket port updated",
description: `Websocket port changed to ${values.port}`, description: `Websocket port changed to ${values.port}`,
}); });
} catch (error) { } catch (error) {
console.error("Error changing websocket port:", error); console.error("Error changing websocket port:", error);
toast({ toast.error("Failed to change websocket port", {
title: "Failed to change websocket port", description: "An error occurred while trying to change the websocket port. Please try again.",
description: "Please try again.",
variant: "destructive",
}); });
} finally { } finally {
setIsChangingWebSocketPort(false); setIsChangingWebSocketPort(false);
@@ -492,10 +475,8 @@ export default function SettingsPage() {
} }
} catch (error) { } catch (error) {
console.error("Error selecting folder:", error); console.error("Error selecting folder:", error);
toast({ toast.error("Failed to select folder", {
title: "Failed to select folder", description: "An error occurred while trying to select the download folder. Please try again.",
description: "Please try again.",
variant: "destructive",
}); });
} }
}} }}
@@ -739,16 +720,13 @@ export default function SettingsPage() {
setIsRestartingWebSocketServer(true); setIsRestartingWebSocketServer(true);
try { try {
await invoke("restart_websocket_server"); await invoke("restart_websocket_server");
toast({ toast.success("Websocket server restarted", {
title: "Websocket server restarted",
description: "Websocket server restarted successfully.", description: "Websocket server restarted successfully.",
}); });
} catch (error) { } catch (error) {
console.error("Error restarting websocket server:", error); console.error("Error restarting websocket server:", error);
toast({ toast.error("Failed to restart websocket server", {
title: "Failed to restart websocket server", description: "An error occurred while trying to restart the websocket server. Please try again.",
description: "Please try again.",
variant: "destructive",
}); });
} finally { } finally {
setIsRestartingWebSocketServer(false); setIsRestartingWebSocketServer(false);