Line data Source code
1 : import WorkflowTemplateSelectorDialog from '@/platform/workflow/templates/components/WorkflowTemplateSelectorDialog.vue'
2 : import { useTelemetry } from '@comfyorg/telemetry'
3 : import type { TemplateLibraryMetadata } from '@comfyorg/telemetry/types'
4 : import { useDialogService } from '@/services/dialogService'
5 : import { useNewUserService } from '@/services/useNewUserService'
6 : import { useDialogStore } from '@/stores/dialogStore'
7 :
8 2355 : const DIALOG_KEY = 'global-workflow-template-selector'
9 2355 : const POPULAR_CATEGORY_ID = 'popular'
10 :
11 2355 : export const useWorkflowTemplateSelectorDialog = () => {
12 10195 : const dialogService = useDialogService()
13 10195 : const dialogStore = useDialogStore()
14 10195 : const newUserService = useNewUserService()
15 :
16 8 : function hide() {
17 8 : dialogStore.closeDialog({ key: DIALOG_KEY })
18 : }
19 :
20 26 : function show(
21 : source: TemplateLibraryMetadata['source'] = 'command',
22 : options?: { initialCategory?: string; afterClose?: () => void }
23 : ) {
24 26 : useTelemetry()?.trackTemplateLibraryOpened({ source })
25 :
26 26 : const initialCategory =
27 : options?.initialCategory ??
28 : (newUserService.isNewUser() ? POPULAR_CATEGORY_ID : 'all')
29 :
30 26 : dialogService.showLayoutDialog({
31 : key: DIALOG_KEY,
32 : component: WorkflowTemplateSelectorDialog,
33 : props: {
34 : onClose: () => {
35 8 : hide()
36 8 : options?.afterClose?.()
37 : },
38 : initialCategory
39 : }
40 : })
41 : }
42 :
43 10195 : return {
44 : show,
45 : hide
46 : }
47 : }
|