refactor: replace Toast with Sonner
This commit is contained in:
@@ -8,7 +8,7 @@ import type {
|
||||
WorkspaceBoundApi,
|
||||
} from "~/services/api";
|
||||
|
||||
import { useUiStore } from "./uiStore";
|
||||
import { toast } from "sonner";
|
||||
|
||||
// 缓存的会话类型(多 iframe 共存方案)
|
||||
type CachedSession = {
|
||||
@@ -173,7 +173,9 @@ export function pushToast(
|
||||
tone: "success" | "error" | "info",
|
||||
message: string,
|
||||
): void {
|
||||
useUiStore.getState().pushToast({ tone, message });
|
||||
if (tone === "error") toast.error(message);
|
||||
else if (tone === "info") toast.info(message);
|
||||
else toast.success(message);
|
||||
}
|
||||
|
||||
export async function sha256Hex(
|
||||
|
||||
@@ -7,12 +7,6 @@ import type {
|
||||
Visibility,
|
||||
} from "../../../services/api";
|
||||
|
||||
export type ToastTone = "success" | "error" | "info";
|
||||
export type ToastState = {
|
||||
tone: ToastTone;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type NewScriptForm = {
|
||||
name: string;
|
||||
scriptType: ScriptType;
|
||||
@@ -66,7 +60,6 @@ export const initialCreateForm: NewScriptForm = {
|
||||
};
|
||||
|
||||
type UiState = {
|
||||
toast: ToastState | null;
|
||||
createDialog: {
|
||||
open: boolean;
|
||||
creating: boolean;
|
||||
@@ -79,10 +72,6 @@ type UiState = {
|
||||
publish: PublishDialogState;
|
||||
dataResourceDialog: DataResourceDialogState;
|
||||
|
||||
// toast
|
||||
pushToast: (toast: ToastState) => void;
|
||||
dismissToast: () => void;
|
||||
|
||||
// create dialog
|
||||
openCreateDialog: (parentPath?: string, scriptType?: ScriptType) => void;
|
||||
closeCreateDialog: () => void;
|
||||
@@ -129,7 +118,6 @@ type UiState = {
|
||||
};
|
||||
|
||||
export const useUiStore = create<UiState>((set) => ({
|
||||
toast: null,
|
||||
createDialog: {
|
||||
open: false,
|
||||
creating: false,
|
||||
@@ -165,9 +153,6 @@ export const useUiStore = create<UiState>((set) => ({
|
||||
targetPath: "",
|
||||
},
|
||||
|
||||
pushToast: (toast) => set({ toast }),
|
||||
dismissToast: () => set({ toast: null }),
|
||||
|
||||
openCreateDialog: (parentPath = "", scriptType = "notebook") =>
|
||||
set((state) => ({
|
||||
contextMenu: null,
|
||||
|
||||
Reference in New Issue
Block a user