forked from dyad-sh/dyad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoast.ts
More file actions
81 lines (73 loc) · 1.8 KB
/
Copy pathtoast.ts
File metadata and controls
81 lines (73 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { toast } from "sonner";
/**
* Toast utility functions for consistent notifications across the app
*/
/**
* Show a success toast
* @param message The message to display
*/
export const showSuccess = (message: string) => {
toast.success(message);
};
/**
* Show an error toast
* @param message The error message to display
*/
export const showError = (message: any) => {
toast.error(message.toString());
console.error(message);
};
/**
* Show a warning toast
* @param message The warning message to display
*/
export const showWarning = (message: string) => {
toast.warning(message);
console.warn(message);
};
/**
* Show an info toast
* @param message The info message to display
*/
export const showInfo = (message: string) => {
toast.info(message);
};
/**
* Show a loading toast that can be updated with success/error
* @param loadingMessage The message to show while loading
* @param promise The promise to track
* @param successMessage Optional success message
* @param errorMessage Optional error message
*/
export const showLoading = <T>(
loadingMessage: string,
promise: Promise<T>,
successMessage?: string,
errorMessage?: string,
) => {
return toast.promise(promise, {
loading: loadingMessage,
success: () => successMessage || "Operation completed successfully",
error: (err) => errorMessage || `Error: ${err.message || "Unknown error"}`,
});
};
export const showExtraFilesToast = ({
files,
error,
}: {
files: string[];
error?: string;
}) => {
if (error) {
showError(
`Error committing files ${files.join(", ")} changed outside of Dyad: ${error}`,
);
} else {
showWarning(
`Files changed outside of Dyad have automatically been committed:
\n\n${files.join("\n")}`,
);
}
};
// Re-export for direct use
export { toast };