70 lines
1.6 KiB
Plaintext
70 lines
1.6 KiB
Plaintext
/**
|
|
* useWorkspace — Workspace items management
|
|
*
|
|
* Manages workspace items generated from AI workflow responses.
|
|
* Items are persisted and filterable by workflow type.
|
|
*/
|
|
|
|
import type { WorkspaceItem, WorkflowId } from '@/types/index'
|
|
import { STORAGE_KEYS } from '@/constants/index'
|
|
import { useStorage } from './useStorage'
|
|
|
|
export function useWorkspace() {
|
|
const { loadValue, saveValue } = useStorage()
|
|
|
|
const workspaceItems = ref<WorkspaceItem[]>(
|
|
loadValue<WorkspaceItem[]>(STORAGE_KEYS.WORKSPACE, [])
|
|
)
|
|
|
|
function persist(): void {
|
|
saveValue(STORAGE_KEYS.WORKSPACE, workspaceItems.value)
|
|
}
|
|
|
|
/**
|
|
* Add a new workspace item.
|
|
*/
|
|
function addWorkspaceItem(item: WorkspaceItem): void {
|
|
workspaceItems.value.unshift(item)
|
|
persist()
|
|
}
|
|
|
|
/**
|
|
* Remove a workspace item by ID.
|
|
*/
|
|
function removeWorkspaceItem(id: string): void {
|
|
workspaceItems.value = workspaceItems.value.filter((item) => item.id !== id)
|
|
persist()
|
|
}
|
|
|
|
/**
|
|
* Get workspace items filtered by workflow type.
|
|
*/
|
|
function getItemsByWorkflow(workflowId: WorkflowId): WorkspaceItem[] {
|
|
return workspaceItems.value.filter((item) => item.workflowId === workflowId)
|
|
}
|
|
|
|
/**
|
|
* Get workspace item by ID.
|
|
*/
|
|
function getItemById(id: string): WorkspaceItem | undefined {
|
|
return workspaceItems.value.find((item) => item.id === id)
|
|
}
|
|
|
|
/**
|
|
* Clear all workspace items.
|
|
*/
|
|
function clearAll(): void {
|
|
workspaceItems.value = []
|
|
persist()
|
|
}
|
|
|
|
return {
|
|
workspaceItems,
|
|
addWorkspaceItem,
|
|
removeWorkspaceItem,
|
|
getItemsByWorkflow,
|
|
getItemById,
|
|
clearAll,
|
|
}
|
|
}
|