Extract error handling with toast message as hook (#825)

This commit is contained in:
Chenlei Hu
2024-09-14 11:25:08 +09:00
committed by GitHub
parent c98ea5ba01
commit ebdcd92977
4 changed files with 78 additions and 35 deletions

View File

@@ -36,12 +36,12 @@ import type {
TreeExplorerNode
} from '@/types/treeExplorerTypes'
import type { TreeNode } from 'primevue/treenode'
import { useToast } from 'primevue/usetoast'
import { computed, nextTick, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useTreeExpansion } from '@/hooks/treeHooks'
import { app } from '@/scripts/app'
import { findNodeByKey } from '@/utils/treeUtil'
import { useErrorHandling } from '@/hooks/errorHooks'
import { useI18n } from 'vue-i18n'
const props = defineProps<{
filteredNodeDefs: ComfyNodeDefImpl[]
@@ -182,22 +182,13 @@ defineExpose({
addNewBookmarkFolder
})
const toast = useToast()
const { t } = useI18n()
const handleRename = (node: TreeNode, newName: string) => {
if (node.data && node.data.isDummyFolder) {
try {
const handleRename = useErrorHandling().wrapWithErrorHandling(
(node: TreeNode, newName: string) => {
if (node.data && node.data.isDummyFolder) {
nodeBookmarkStore.renameBookmarkFolder(node.data, newName)
} catch (e) {
toast.add({
severity: 'error',
summary: t('error'),
detail: e.message,
life: 3000
})
}
}
}
)
const showCustomizationDialog = ref(false)
const initialIcon = ref(nodeBookmarkStore.defaultBookmarkIcon)
@@ -212,6 +203,7 @@ const updateCustomization = (icon: string, color: string) => {
}
}
const { t } = useI18n()
const extraMenuItems = computed(
() => (menuTargetNode: RenderedTreeExplorerNode<ComfyNodeDefImpl>) => [
{