arch-design-agent-skill-das.../frontend/src/modules/graph/composables/useGraph.ts
2026-03-23 17:17:52 +00:00

41 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { GraphView, GraphNode, ScanResult } from '@/shared/types/api'
import * as graphApi from '../api'
export const useGraphStore = defineStore('graph', () => {
const graphView = ref<GraphView | null>(null)
const selectedNode = ref<GraphNode | null>(null)
const scanResult = ref<ScanResult | null>(null)
const loading = ref(false)
async function loadGraph(projectId: string) {
loading.value = true
try {
scanResult.value = await graphApi.triggerScan(projectId)
graphView.value = await graphApi.getGraph(projectId)
} finally {
loading.value = false
}
}
function selectNode(node: GraphNode | null) {
selectedNode.value = node
}
async function loadNeighbors(projectId: string, nodeId: string) {
loading.value = true
try {
graphView.value = await graphApi.getNodeNeighbors(projectId, nodeId)
} finally {
loading.value = false
}
}
function clearSelection() {
selectedNode.value = null
}
return { graphView, selectedNode, scanResult, loading, loadGraph, selectNode, loadNeighbors, clearSelection }
})