15 lines
911 B
TypeScript
15 lines
911 B
TypeScript
import { defineStore } from 'pinia'
|
|
import { reactive } from 'vue'
|
|
import type { TaskType } from '../types'
|
|
export interface Draft { prompt: string; negative_prompt: string; parameters: Record<string, any>; imageAssetId: string | null; count: number; scheduledAt: string | null }
|
|
export const useDraftsStore = defineStore('drafts', () => {
|
|
const drafts = reactive<Record<string, Draft>>({})
|
|
function forTask(type: TaskType, defaults: Record<string, any> = {}) {
|
|
if (!drafts[type]) drafts[type] = { prompt: '', negative_prompt: '', parameters: { ...defaults }, imageAssetId: null, count: 1, scheduledAt: null }
|
|
for (const [key, value] of Object.entries(defaults)) if (drafts[type]!.parameters[key] === undefined) drafts[type]!.parameters[key] = value
|
|
return drafts[type]!
|
|
}
|
|
function clear() { for (const key of Object.keys(drafts)) delete drafts[key] }
|
|
return { drafts, forTask, clear }
|
|
})
|