[Refactor] Convert dialogService to composable (#2058)

This commit is contained in:
Chenlei Hu
2024-12-26 00:26:01 -05:00
committed by GitHub
parent 4e554503c0
commit f69e88bf41
8 changed files with 176 additions and 171 deletions

View File

@@ -1,7 +1,7 @@
import { downloadBlob } from '@/scripts/utils'
import { useSettingStore } from '@/stores/settingStore'
import { useWorkflowStore, ComfyWorkflow } from '@/stores/workflowStore'
import { showConfirmationDialog, showPromptDialog } from './dialogService'
import { useDialogService } from './dialogService'
import { app } from '@/scripts/app'
import { useWorkspaceStore } from '@/stores/workspaceStore'
import { LGraphCanvas } from '@comfyorg/litegraph'
@@ -16,10 +16,11 @@ export const useWorkflowService = () => {
const settingStore = useSettingStore()
const workflowStore = useWorkflowStore()
const toastStore = useToastStore()
const dialogService = useDialogService()
async function getFilename(defaultName: string): Promise<string | null> {
if (settingStore.get('Comfy.PromptFilename')) {
let filename = await showPromptDialog({
let filename = await dialogService.showPromptDialog({
title: t('workflowService.exportWorkflow'),
message: t('workflowService.enterFilename') + ':',
defaultValue: defaultName
@@ -57,7 +58,7 @@ export const useWorkflowService = () => {
* @param workflow The workflow to save
*/
const saveWorkflowAs = async (workflow: ComfyWorkflow) => {
const newFilename = await showPromptDialog({
const newFilename = await dialogService.showPromptDialog({
title: t('workflowService.saveWorkflow'),
message: t('workflowService.enterFilename') + ':',
defaultValue: workflow.filename
@@ -69,7 +70,7 @@ export const useWorkflowService = () => {
const existingWorkflow = workflowStore.getWorkflowByPath(newPath)
if (existingWorkflow && !existingWorkflow.isTemporary) {
const res = await showConfirmationDialog({
const res = await dialogService.showConfirmationDialog({
title: t('sideToolbar.workflowTab.confirmOverwriteTitle'),
type: 'overwrite',
message: t('sideToolbar.workflowTab.confirmOverwrite'),
@@ -178,7 +179,7 @@ export const useWorkflowService = () => {
}
if (workflow.isModified && options.warnIfUnsaved) {
const confirmed = await showConfirmationDialog({
const confirmed = await dialogService.showConfirmationDialog({
title: t('sideToolbar.workflowTab.dirtyCloseTitle'),
type: 'dirtyClose',
message: t('sideToolbar.workflowTab.dirtyClose'),
@@ -222,7 +223,7 @@ export const useWorkflowService = () => {
let confirmed: boolean | null = bypassConfirm || silent
if (!confirmed) {
confirmed = await showConfirmationDialog({
confirmed = await dialogService.showConfirmationDialog({
title: t('sideToolbar.workflowTab.confirmDeleteTitle'),
type: 'delete',
message: t('sideToolbar.workflowTab.confirmDelete'),