Initial commit: AI chat assistant with workflow chat, workspace, and profile tabs
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
69
composables/useWorkspace.uts
Normal file
69
composables/useWorkspace.uts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user