mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-09 17:52:30 +08:00
Show success toast after saving diagram (#484)
* Add success toast after saving diagram * fix: correct save toast placement * Changes made: 1. Added i18n support 2. Fixed the issue where the save toast was running only once * fix: show toast after download completes, not when dialog opens Move toast from handleDrawioSave (dialog open) to saveDiagramToFile (after download). Also restore the duplicate-save guard that was removed. --------- Co-authored-by: Biki Kalita <86558912+Biki-dev@users.noreply.github.com> Co-authored-by: dayuan.jiang <jdy.toh@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import type React from "react"
|
||||
import { createContext, useContext, useEffect, useRef, useState } from "react"
|
||||
import type { DrawIoEmbedRef } from "react-drawio"
|
||||
import { toast } from "sonner"
|
||||
import type { ExportFormat } from "@/components/save-dialog"
|
||||
import { getApiEndpoint } from "@/lib/base-path"
|
||||
import {
|
||||
@@ -27,6 +28,7 @@ interface DiagramContextType {
|
||||
filename: string,
|
||||
format: ExportFormat,
|
||||
sessionId?: string,
|
||||
successMessage?: string,
|
||||
) => void
|
||||
getThumbnailSvg: () => Promise<string | null>
|
||||
isDrawioReady: boolean
|
||||
@@ -236,6 +238,7 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
|
||||
filename: string,
|
||||
format: ExportFormat,
|
||||
sessionId?: string,
|
||||
successMessage?: string,
|
||||
) => {
|
||||
if (!drawioRef.current) {
|
||||
console.warn("Draw.io editor not ready")
|
||||
@@ -297,6 +300,14 @@ export function DiagramProvider({ children }: { children: React.ReactNode }) {
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
|
||||
// Show success toast after download is initiated
|
||||
if (successMessage) {
|
||||
toast.success(successMessage, {
|
||||
position: "bottom-left",
|
||||
duration: 2500,
|
||||
})
|
||||
}
|
||||
|
||||
// Delay URL revocation to ensure download completes
|
||||
if (!url.startsWith("data:")) {
|
||||
setTimeout(() => URL.revokeObjectURL(url), 100)
|
||||
|
||||
Reference in New Issue
Block a user