@@ -92,9 +91,8 @@ const ImageImpl: FC
= ({
click: () => {
if (props.src) {
navigator.clipboard.writeText(props.src)
- toast({
+ toast("Address copied to clipboard.", {
duration: 1000,
- description: "Address copied to clipboard.",
})
}
},
diff --git a/src/renderer/src/components/ui/sonner.tsx b/src/renderer/src/components/ui/sonner.tsx
new file mode 100644
index 000000000..cb948ef68
--- /dev/null
+++ b/src/renderer/src/components/ui/sonner.tsx
@@ -0,0 +1,26 @@
+import { useDark } from "@renderer/hooks/useDark"
+import { Toaster as Sonner } from "sonner"
+
+type ToasterProps = React.ComponentProps
+
+const Toaster = ({ ...props }: ToasterProps) => {
+ const { theme } = useDark()
+
+ return (
+
+ )
+}
+
+export { Toaster }
diff --git a/src/renderer/src/components/ui/toast.tsx b/src/renderer/src/components/ui/toast.tsx
deleted file mode 100644
index 56d51c4d8..000000000
--- a/src/renderer/src/components/ui/toast.tsx
+++ /dev/null
@@ -1,125 +0,0 @@
-import * as ToastPrimitives from "@radix-ui/react-toast"
-import { cn } from "@renderer/lib/utils"
-import type { VariantProps } from "class-variance-authority"
-import { cva } from "class-variance-authority"
-import { X } from "lucide-react"
-import * as React from "react"
-
-const ToastProvider = ToastPrimitives.Provider
-
-const ToastViewport = React.forwardRef<
- React.ElementRef,
- React.ComponentPropsWithoutRef
->(({ className, ...props }, ref) => (
-
-))
-ToastViewport.displayName = ToastPrimitives.Viewport.displayName
-
-const toastVariants = cva(
- "group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
- {
- variants: {
- variant: {
- default: "border bg-background text-foreground",
- destructive:
- "destructive group border-destructive bg-destructive text-destructive-foreground",
- },
- },
- defaultVariants: {
- variant: "default",
- },
- },
-)
-
-const Toast = React.forwardRef<
- React.ElementRef,
- React.ComponentPropsWithoutRef &
- VariantProps
->(({ className, variant, ...props }, ref) => (
-
-))
-Toast.displayName = ToastPrimitives.Root.displayName
-
-const ToastAction = React.forwardRef<
- React.ElementRef,
- React.ComponentPropsWithoutRef
->(({ className, ...props }, ref) => (
-
-))
-ToastAction.displayName = ToastPrimitives.Action.displayName
-
-const ToastClose = React.forwardRef<
- React.ElementRef,
- React.ComponentPropsWithoutRef
->(({ className, ...props }, ref) => (
-
-
-
-))
-ToastClose.displayName = ToastPrimitives.Close.displayName
-
-const ToastTitle = React.forwardRef<
- React.ElementRef,
- React.ComponentPropsWithoutRef
->(({ className, ...props }, ref) => (
-
-))
-ToastTitle.displayName = ToastPrimitives.Title.displayName
-
-const ToastDescription = React.forwardRef<
- React.ElementRef,
- React.ComponentPropsWithoutRef
->(({ className, ...props }, ref) => (
-
-))
-ToastDescription.displayName = ToastPrimitives.Description.displayName
-
-type ToastProps = React.ComponentPropsWithoutRef
-
-type ToastActionElement = React.ReactElement
-
-export {
- Toast,
- ToastAction,
- type ToastActionElement,
- ToastClose,
- ToastDescription,
- type ToastProps,
- ToastProvider,
- ToastTitle,
- ToastViewport,
-}
diff --git a/src/renderer/src/components/ui/toaster.tsx b/src/renderer/src/components/ui/toaster.tsx
deleted file mode 100644
index abd489572..000000000
--- a/src/renderer/src/components/ui/toaster.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import {
- Toast,
- ToastClose,
- ToastDescription,
- ToastProvider,
- ToastTitle,
- ToastViewport,
-} from "@renderer/components/ui/toast"
-import { useToast } from "@renderer/components/ui/use-toast"
-
-export function Toaster() {
- const { toasts } = useToast()
-
- return (
-
- {toasts.map(({ id, title, description, action, ...props }) => (
-
-
- {title && {title}}
- {description && (
- {description}
- )}
-
- {action}
-
-
- ))}
-
-
- )
-}
diff --git a/src/renderer/src/components/ui/use-toast.ts b/src/renderer/src/components/ui/use-toast.ts
deleted file mode 100644
index c26cfa80b..000000000
--- a/src/renderer/src/components/ui/use-toast.ts
+++ /dev/null
@@ -1,194 +0,0 @@
-// Inspired by react-hot-toast library
-import type {
- ToastActionElement,
- ToastProps,
-} from "@renderer/components/ui/toast"
-import * as React from "react"
-
-const TOAST_LIMIT = 1
-const TOAST_REMOVE_DELAY = 1_000_000
-
-type ToasterToast = ToastProps & {
- id: string
- title?: React.ReactNode
- description?: React.ReactNode
- action?: ToastActionElement
-}
-
-const actionTypes = {
- ADD_TOAST: "ADD_TOAST",
- UPDATE_TOAST: "UPDATE_TOAST",
- DISMISS_TOAST: "DISMISS_TOAST",
- REMOVE_TOAST: "REMOVE_TOAST",
-} as const
-
-let count = 0
-
-function genId() {
- count = (count + 1) % Number.MAX_SAFE_INTEGER
- return count.toString()
-}
-
-type ActionType = typeof actionTypes
-
-type Action =
- | {
- type: ActionType["ADD_TOAST"]
- toast: ToasterToast
- }
- | {
- type: ActionType["UPDATE_TOAST"]
- toast: Partial
- }
- | {
- type: ActionType["DISMISS_TOAST"]
- toastId?: ToasterToast["id"]
- }
- | {
- type: ActionType["REMOVE_TOAST"]
- toastId?: ToasterToast["id"]
- }
-
-interface State {
- toasts: ToasterToast[]
-}
-
-const toastTimeouts = new Map>()
-
-const addToRemoveQueue = (toastId: string) => {
- if (toastTimeouts.has(toastId)) {
- return
- }
-
- const timeout = setTimeout(() => {
- toastTimeouts.delete(toastId)
- dispatch({
- type: "REMOVE_TOAST",
- toastId,
- })
- }, TOAST_REMOVE_DELAY)
-
- toastTimeouts.set(toastId, timeout)
-}
-
-export const reducer = (state: State, action: Action): State => {
- switch (action.type) {
- case "ADD_TOAST": {
- return {
- ...state,
- toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
- }
- }
-
- case "UPDATE_TOAST": {
- return {
- ...state,
- toasts: state.toasts.map((t) =>
- t.id === action.toast.id ? { ...t, ...action.toast } : t,
- ),
- }
- }
-
- case "DISMISS_TOAST": {
- const { toastId } = action
-
- // ! Side effects ! - This could be extracted into a dismissToast() action,
- // but I'll keep it here for simplicity
- if (toastId) {
- addToRemoveQueue(toastId)
- } else {
- for (const toast of state.toasts) {
- addToRemoveQueue(toast.id)
- }
- }
-
- return {
- ...state,
- toasts: state.toasts.map((t) =>
- t.id === toastId || toastId === undefined ?
- {
- ...t,
- open: false,
- } :
- t,
- ),
- }
- }
- case "REMOVE_TOAST": {
- if (action.toastId === undefined) {
- return {
- ...state,
- toasts: [],
- }
- }
- return {
- ...state,
- toasts: state.toasts.filter((t) => t.id !== action.toastId),
- }
- }
- }
-}
-
-const listeners: Array<(state: State) => void> = []
-
-let memoryState: State = { toasts: [] }
-
-function dispatch(action: Action) {
- memoryState = reducer(memoryState, action)
- for (const listener of listeners) {
- listener(memoryState)
- }
-}
-
-type Toast = Omit
-
-function toast({ ...props }: Toast) {
- const id = genId()
-
- const update = (props: ToasterToast) =>
- dispatch({
- type: "UPDATE_TOAST",
- toast: { ...props, id },
- })
- const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id })
-
- dispatch({
- type: "ADD_TOAST",
- toast: {
- ...props,
- id,
- open: true,
- onOpenChange: (open) => {
- if (!open) dismiss()
- },
- },
- })
-
- return {
- id,
- dismiss,
- update,
- }
-}
-
-function useToast() {
- const [state, setState] = React.useState(memoryState)
-
- React.useEffect(() => {
- listeners.push(setState)
- return () => {
- const index = listeners.indexOf(setState)
- if (index > -1) {
- listeners.splice(index, 1)
- }
- }
- }, [state])
-
- return {
- ...state,
- toast,
- dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
- }
-}
-
-export { toast, useToast }
diff --git a/src/renderer/src/hooks/useDark.ts b/src/renderer/src/hooks/useDark.ts
index 50bdeeae7..e31964b1e 100644
--- a/src/renderer/src/hooks/useDark.ts
+++ b/src/renderer/src/hooks/useDark.ts
@@ -4,9 +4,7 @@ import { atomDark } from "jotai-dark"
const isDarkAtom = atomDark({
storageKey: "theme",
disableTransition: true,
- applyDarkMode(isDark) {
- document.documentElement.dataset.theme = isDark ? "dark" : "light"
- },
+ mode: "data-theme",
})
export function useDark() {
diff --git a/src/renderer/src/hooks/useEntryActions.tsx b/src/renderer/src/hooks/useEntryActions.tsx
index b54755382..9070da7e0 100644
--- a/src/renderer/src/hooks/useEntryActions.tsx
+++ b/src/renderer/src/hooks/useEntryActions.tsx
@@ -1,4 +1,3 @@
-import { useToast } from "@renderer/components/ui/use-toast"
import { apiClient } from "@renderer/lib/api-fetch"
import { client } from "@renderer/lib/client"
import type { EntryModel } from "@renderer/models"
@@ -6,6 +5,7 @@ import { entryActions } from "@renderer/store/entry"
import { useMutation, useQuery } from "@tanstack/react-query"
import type { FetchError } from "ofetch"
import { ofetch } from "ofetch"
+import { toast } from "sonner"
export const useEntryActions = ({
view,
@@ -44,9 +44,8 @@ export const useEntryActions = ({
})
},
onSuccess: () => {
- toast({
+ toast("Collected.", {
duration: 1000,
- description: "Collected.",
})
},
})
@@ -65,9 +64,8 @@ export const useEntryActions = ({
})
},
onSuccess: () => {
- toast({
+ toast("Uncollected.", {
duration: 1000,
- description: "Uncollected.",
})
},
})
@@ -100,8 +98,6 @@ export const useEntryActions = ({
},
})
- const { toast } = useToast()
-
if (!entry?.entries.url || view === undefined) return { items: [] }
const items = [
@@ -128,9 +124,8 @@ export const useEntryActions = ({
onClick: () => {
if (!entry.entries.url) return
navigator.clipboard.writeText(entry.entries.url)
- toast({
+ toast("Link copied to clipboard.", {
duration: 1000,
- description: "Link copied to clipboard.",
})
},
},
@@ -155,14 +150,12 @@ export const useEntryActions = ({
images: entry.entries.images,
})
if (response?.status === "success") {
- toast({
+ toast("Saved to Eagle.", {
duration: 3000,
- description: "Saved to Eagle.",
})
} else {
- toast({
+ toast("Failed to save to Eagle.", {
duration: 3000,
- description: "Failed to save to Eagle.",
})
}
},
diff --git a/src/renderer/src/pages/add/index.tsx b/src/renderer/src/pages/add/index.tsx
index 54ad7bef5..428a82d4d 100644
--- a/src/renderer/src/pages/add/index.tsx
+++ b/src/renderer/src/pages/add/index.tsx
@@ -20,7 +20,6 @@ import {
SelectValue,
} from "@renderer/components/ui/select"
import { Switch } from "@renderer/components/ui/switch"
-import { useToast } from "@renderer/components/ui/use-toast"
import { useBizQuery } from "@renderer/hooks/useBizQuery"
import { apiClient } from "@renderer/lib/api-fetch"
import { client } from "@renderer/lib/client"
@@ -32,6 +31,7 @@ import { useFeed } from "@renderer/queries/feed"
import { useMutation } from "@tanstack/react-query"
import { useEffect } from "react"
import { useForm } from "react-hook-form"
+import { toast } from "sonner"
import { z } from "zod"
const formSchema = z.object({
@@ -68,7 +68,6 @@ export function Component() {
}
}, [feed.data?.subscription])
- const { toast } = useToast()
const followMutation = useMutation({
mutationFn: async (values: z.infer) => {
const body = {
@@ -103,10 +102,12 @@ export function Component() {
client?.invalidateQuery(
Queries.feed.byId({ id: feed.data?.feed.id }).key,
)
- toast({
- duration: 1000,
- description: isSubscribed ? "🎉 Updated." : "🎉 Followed.",
- })
+ toast(
+ isSubscribed ? "🎉 Updated." : "🎉 Followed.",
+ {
+ duration: 1000,
+ },
+ )
if (!isSubscribed) {
window.close()
diff --git a/src/renderer/src/pages/settings/profile.tsx b/src/renderer/src/pages/settings/profile.tsx
index c415150b5..24eaa6cf9 100644
--- a/src/renderer/src/pages/settings/profile.tsx
+++ b/src/renderer/src/pages/settings/profile.tsx
@@ -12,10 +12,10 @@ import {
FormMessage,
} from "@renderer/components/ui/form"
import { Input } from "@renderer/components/ui/input"
-import { useToast } from "@renderer/components/ui/use-toast"
import { apiClient } from "@renderer/lib/api-fetch"
import { useMutation } from "@tanstack/react-query"
import { useForm } from "react-hook-form"
+import { toast } from "sonner"
import { z } from "zod"
const formSchema = z.object({
@@ -36,17 +36,14 @@ export function Component() {
},
})
- const { toast } = useToast()
-
const updateMutation = useMutation({
mutationFn: async (values: z.infer) =>
apiClient["auth-app"]["update-account"].$patch({
json: values,
}),
onSuccess: () => {
- toast({
+ toast("Profile updated.", {
duration: 3000,
- description: "Profile updated.",
})
},
})
diff --git a/src/renderer/src/providers/root-providers.tsx b/src/renderer/src/providers/root-providers.tsx
index 3e417be03..9c611e990 100644
--- a/src/renderer/src/providers/root-providers.tsx
+++ b/src/renderer/src/providers/root-providers.tsx
@@ -1,6 +1,6 @@
import { SessionProvider } from "@hono/auth-js/react"
import { ModalStackProvider } from "@renderer/components/ui/modal"
-import { Toaster } from "@renderer/components/ui/toaster"
+import { Toaster } from "@renderer/components/ui/sonner"
import { TooltipProvider } from "@renderer/components/ui/tooltip"
import { jotaiStore } from "@renderer/lib/jotai"
import { queryClient } from "@renderer/lib/query-client"