41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import type { EditableFile, ImpactResult } from '@/shared/types/api'
|
|
import * as editorApi from '../api'
|
|
|
|
export const useEditorStore = defineStore('editor', () => {
|
|
const currentFile = ref<EditableFile | null>(null)
|
|
const impactResult = ref<ImpactResult | null>(null)
|
|
const saving = ref(false)
|
|
const error = ref<string | null>(null)
|
|
|
|
async function loadFile(projectId: string, path: string) {
|
|
try {
|
|
currentFile.value = await editorApi.getFile(projectId, path)
|
|
} catch (e: any) {
|
|
error.value = e.message
|
|
}
|
|
}
|
|
|
|
async function saveFile(projectId: string, path: string, content: string) {
|
|
saving.value = true
|
|
try {
|
|
await editorApi.saveFile(projectId, path, content)
|
|
} catch (e: any) {
|
|
error.value = e.message
|
|
} finally {
|
|
saving.value = false
|
|
}
|
|
}
|
|
|
|
async function analyzeImpact(projectId: string, path: string) {
|
|
try {
|
|
impactResult.value = await editorApi.getFileImpact(projectId, path)
|
|
} catch (e: any) {
|
|
error.value = e.message
|
|
}
|
|
}
|
|
|
|
return { currentFile, impactResult, saving, error, loadFile, saveFile, analyzeImpact }
|
|
})
|