44 lines
1.2 KiB
Plaintext
44 lines
1.2 KiB
Plaintext
/**
|
|
* useWorkflow — Current workflow selection state
|
|
*
|
|
* Manages which workflow is active (general, code, document, data, creative).
|
|
* The selection is persisted so it survives app restarts.
|
|
*/
|
|
|
|
import type { WorkflowId, WorkflowDef } from '@/types/index'
|
|
import { WORKFLOWS, STORAGE_KEYS } from '@/constants/index'
|
|
import { useStorage } from './useStorage'
|
|
|
|
export function useWorkflow() {
|
|
const { loadValue, saveValue } = useStorage()
|
|
|
|
// Initialize from storage, fallback to 'general'
|
|
const activeWorkflowId = ref<WorkflowId>(
|
|
loadValue<WorkflowId>(STORAGE_KEYS.ACTIVE_WORKFLOW_ID, 'general')
|
|
)
|
|
|
|
// All available workflows (static)
|
|
const workflows: WorkflowDef[] = WORKFLOWS
|
|
|
|
// Computed: the currently active workflow definition
|
|
const activeWorkflow = computed<WorkflowDef>(() => {
|
|
const found = workflows.find((w) => w.id === activeWorkflowId.value)
|
|
return found ?? workflows[0]
|
|
})
|
|
|
|
/**
|
|
* Select a workflow and persist the choice.
|
|
*/
|
|
function selectWorkflow(id: WorkflowId): void {
|
|
activeWorkflowId.value = id
|
|
saveValue(STORAGE_KEYS.ACTIVE_WORKFLOW_ID, id)
|
|
}
|
|
|
|
return {
|
|
activeWorkflowId,
|
|
workflows,
|
|
activeWorkflow,
|
|
selectWorkflow,
|
|
}
|
|
}
|