mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +00:00
Add ComfyUI Examples workflows to in-app templates (#2541)
Co-authored-by: jojodecayz <121620462+jojodecayz@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -1,20 +1,48 @@
|
||||
import { groupBy } from 'lodash'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { computed, ref, shallowRef } from 'vue'
|
||||
|
||||
import { CORE_TEMPLATES } from '@/constants/coreTemplates'
|
||||
import { api } from '@/scripts/api'
|
||||
import type {
|
||||
TemplateGroup,
|
||||
WorkflowTemplates
|
||||
} from '@/types/workflowTemplateTypes'
|
||||
|
||||
export const useWorkflowTemplatesStore = defineStore(
|
||||
'workflowTemplates',
|
||||
() => {
|
||||
const items = ref<{
|
||||
[customNodesName: string]: string[]
|
||||
}>({})
|
||||
const customTemplates = shallowRef<{ [moduleName: string]: string[] }>({})
|
||||
const isLoaded = ref(false)
|
||||
const defaultTemplate: WorkflowTemplates = CORE_TEMPLATES[0]
|
||||
|
||||
const groupedTemplates = computed<TemplateGroup[]>(() => {
|
||||
const allTemplates = [
|
||||
...CORE_TEMPLATES,
|
||||
...Object.entries(customTemplates.value).map(
|
||||
([moduleName, templates]) => ({
|
||||
moduleName,
|
||||
title: moduleName,
|
||||
templates: templates.map((name) => ({
|
||||
name,
|
||||
mediaType: 'image',
|
||||
mediaSubtype: 'jpg'
|
||||
}))
|
||||
})
|
||||
)
|
||||
]
|
||||
|
||||
return Object.entries(
|
||||
groupBy(allTemplates, (t) =>
|
||||
t.moduleName === 'default' ? 'ComfyUI Examples' : 'Custom Nodes'
|
||||
)
|
||||
).map(([label, modules]) => ({ label, modules }))
|
||||
})
|
||||
|
||||
async function loadWorkflowTemplates() {
|
||||
try {
|
||||
if (!isLoaded.value) {
|
||||
items.value = await api.getWorkflowTemplates()
|
||||
customTemplates.value = await api.getWorkflowTemplates()
|
||||
isLoaded.value = true
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -23,7 +51,8 @@ export const useWorkflowTemplatesStore = defineStore(
|
||||
}
|
||||
|
||||
return {
|
||||
items,
|
||||
groupedTemplates,
|
||||
defaultTemplate,
|
||||
isLoaded,
|
||||
loadWorkflowTemplates
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user