mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-28 18:54:09 +00:00
## Summary Moves the fetch and post-fetch logic associated with the asset browser into the component and shows a loading state while fetching. To test, use this branch: https://github.com/comfyanonymous/ComfyUI/pull/10045 https://github.com/user-attachments/assets/718974d5-efc7-46a0-bcd6-e82596d4c389 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6189-load-assets-browser-before-fetch-completes-and-show-loading-state-2946d73d365081879d1bd05d86e8c036) by [Unito](https://www.unito.io) --------- Co-authored-by: GitHub Action <action@github.com>
88 lines
2.4 KiB
TypeScript
88 lines
2.4 KiB
TypeScript
import AssetBrowserModal from '@/platform/assets/components/AssetBrowserModal.vue'
|
|
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
|
|
import { useDialogStore } from '@/stores/dialogStore'
|
|
import type { DialogComponentProps } from '@/stores/dialogStore'
|
|
|
|
interface ShowOptions {
|
|
/** ComfyUI node type for context (e.g., 'CheckpointLoaderSimple') */
|
|
nodeType: string
|
|
/** Widget input name (e.g., 'ckpt_name') */
|
|
inputName: string
|
|
/** Current selected asset value */
|
|
currentValue?: string
|
|
onAssetSelected?: (asset: AssetItem) => void
|
|
}
|
|
|
|
interface BrowseOptions {
|
|
/** Asset type tag to filter by (e.g., 'models') */
|
|
assetType: string
|
|
/** Custom modal title (optional) */
|
|
title?: string
|
|
/** Called when asset selected */
|
|
onAssetSelected?: (asset: AssetItem) => void
|
|
}
|
|
|
|
const dialogComponentProps: DialogComponentProps = {
|
|
headless: true,
|
|
modal: true,
|
|
closable: true,
|
|
pt: {
|
|
root: {
|
|
class: 'rounded-2xl overflow-hidden asset-browser-dialog'
|
|
},
|
|
header: {
|
|
class: '!p-0 hidden'
|
|
},
|
|
content: {
|
|
class: '!p-0 !m-0 h-full w-full'
|
|
}
|
|
}
|
|
} as const
|
|
|
|
export const useAssetBrowserDialog = () => {
|
|
const dialogStore = useDialogStore()
|
|
const dialogKey = 'global-asset-browser'
|
|
|
|
async function show(props: ShowOptions) {
|
|
const handleAssetSelected = (asset: AssetItem) => {
|
|
props.onAssetSelected?.(asset)
|
|
dialogStore.closeDialog({ key: dialogKey })
|
|
}
|
|
|
|
dialogStore.showDialog({
|
|
key: dialogKey,
|
|
component: AssetBrowserModal,
|
|
props: {
|
|
nodeType: props.nodeType,
|
|
inputName: props.inputName,
|
|
currentValue: props.currentValue,
|
|
onSelect: handleAssetSelected,
|
|
onClose: () => dialogStore.closeDialog({ key: dialogKey })
|
|
},
|
|
dialogComponentProps
|
|
})
|
|
}
|
|
|
|
async function browse(options: BrowseOptions): Promise<void> {
|
|
const handleAssetSelected = (asset: AssetItem) => {
|
|
options.onAssetSelected?.(asset)
|
|
dialogStore.closeDialog({ key: dialogKey })
|
|
}
|
|
|
|
dialogStore.showDialog({
|
|
key: dialogKey,
|
|
component: AssetBrowserModal,
|
|
props: {
|
|
showLeftPanel: true,
|
|
assetType: options.assetType,
|
|
title: options.title,
|
|
onSelect: handleAssetSelected,
|
|
onClose: () => dialogStore.closeDialog({ key: dialogKey })
|
|
},
|
|
dialogComponentProps
|
|
})
|
|
}
|
|
|
|
return { show, browse }
|
|
}
|