All files / src/lib notify.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 6/6
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                    24x     47x   5x       17x       1x       1x             1x      
import toast from "react-hot-toast";
 
/**
 * Thin wrapper around react-hot-toast with built-in deduplication.
 *
 * Dedup mechanism: uses a deterministic toast ID derived from the message,
 * so calling notify.success("Saved") twice rapidly shows only one toast.
 */
 
function toastId(message: string): string {
	return `notify-${message}`;
}
 
export const notify = {
	success(message: string) {
		toast.success(message, { id: toastId(message) });
	},
 
	error(message: string) {
		toast.error(message, { id: toastId(message) });
	},
 
	warning(message: string) {
		toast(message, { id: toastId(message), icon: "\u26A0\uFE0F" });
	},
 
	info(message: string) {
		toast(message, { id: toastId(message), icon: "\u2139\uFE0F" });
	},
 
	promise<T>(
		promise: Promise<T>,
		msgs: { loading: string; success: string; error: string },
	) {
		return toast.promise(promise, msgs);
	},
};