Spaces:
Sleeping
Sleeping
| import { type ThemeByMomentStrategy } from '@/schema/gradio-proxy/theme-by-moment'; | |
| import { type SwotDataWithScores, type SwotDataWithoutSummary, type SwotTable } from '@/schema/pox'; | |
| import { | |
| DownloadData, | |
| InputData, | |
| MomentResult, | |
| OwnCategoryScores, | |
| ResultData, | |
| ScoreTotal, | |
| SummaryBaseData, | |
| SummaryData, | |
| UrlCategoryScores, | |
| UrlMapping, | |
| } from '@/types/api'; | |
| import { create } from 'zustand'; | |
| interface StoreState { | |
| tempImages: string[]; | |
| setTempImages: (tempImages: string[]) => void; | |
| downloadData: DownloadData | null; | |
| setDownloadData: (downloadData: DownloadData | null) => void; | |
| scoreDict: ResultData | null; | |
| setScoreDict: (scoreDict: ResultData | null) => void; | |
| commonDict: InputData | null; | |
| setCommonDict: (commonDict: InputData | null) => void; | |
| scoreTotal: ScoreTotal | null; | |
| setScoreTotal: (scoreTotal: ScoreTotal | null) => void; | |
| urlCategoryScores: UrlCategoryScores | null; | |
| setUrlCategoryScores: (urlCategoryScores: UrlCategoryScores | null) => void; | |
| ownCategoryScores: OwnCategoryScores | null; | |
| setOwnCategoryScores: (ownCategoryScores: OwnCategoryScores | null) => void; | |
| summaryData: SummaryData | null; | |
| setSummaryData: (summaryData: SummaryData | null) => void; | |
| summaryBaseData: SummaryBaseData | null; | |
| setSummaryBaseData: (summaryBaseData: SummaryBaseData | null) => void; | |
| swotData75: SwotDataWithScores | null; | |
| setSwotData75: (swotData: SwotDataWithScores | null) => void; | |
| swotData78: SwotDataWithoutSummary | null; | |
| setSwotData78: (swotData: SwotDataWithoutSummary | null) => void; | |
| swotData79: string | null; | |
| setSwotData79: (swotData: string | null) => void; | |
| swotTable: SwotTable | null; | |
| setSwotTable: (swotTable: SwotTable | null) => void; | |
| urlMapping: UrlMapping[] | null; | |
| setUrlMapping: (urlMapping: UrlMapping[] | null) => void; | |
| showPercentage: boolean; | |
| setShowPercentage: (showPercentage: boolean) => void; | |
| momentResult: MomentResult | null; | |
| setMomentResult: (momentResult: MomentResult | null) => void; | |
| ownFile: File | null; | |
| setOwnFile: (ownFile: File | null) => void; | |
| strategyXMoment: ThemeByMomentStrategy | null; | |
| setStrategyXMoment: (strategyXMoment: ThemeByMomentStrategy | null) => void; | |
| // 画像生成バッチIDの管理 | |
| activeImageBatchIds: Map<string, string>; | |
| setImageBatchId: (key: string, batchId: string) => void; | |
| removeImageBatchId: (key: string) => void; | |
| clearImageBatchIds: () => void; | |
| // FV生成の重複実行防止 | |
| proposalTabsExecuted: boolean; | |
| setProposalTabsExecuted: (executed: boolean) => void; | |
| resetProposalTabsExecution: () => void; | |
| // contentHashと完了済みbatchIdの関係管理 | |
| completedBatchesBySelection: Map<string, Set<string>>; | |
| markBatchCompleted: (contentHash: string, batchId: string) => void; | |
| isBatchCompleted: (contentHash: string, batchId: string) => boolean; | |
| clearCompletedBatches: () => void; | |
| // 分析前実行のAPI結果キャッシュをクリア(リトライ時は使い回すためのキャッシュ) | |
| clearPreAnalysisCache: () => void; | |
| } | |
| export const useResultStore = create<StoreState>((set, get) => ({ | |
| tempImages: [] as string[], | |
| setTempImages: (tempImages: string[]) => set({ tempImages }), | |
| downloadData: null, | |
| setDownloadData: (downloadData) => set({ downloadData }), | |
| scoreDict: null, | |
| setScoreDict: (scoreDict) => set({ scoreDict }), | |
| commonDict: null, | |
| setCommonDict: (commonDict) => set({ commonDict }), | |
| scoreTotal: null, | |
| setScoreTotal: (scoreTotal) => set({ scoreTotal }), | |
| urlCategoryScores: null, | |
| setUrlCategoryScores: (urlCategoryScores) => set({ urlCategoryScores }), | |
| ownCategoryScores: null, | |
| setOwnCategoryScores: (ownCategoryScores) => set({ ownCategoryScores }), | |
| summaryData: null, | |
| setSummaryData: (summaryData) => set({ summaryData }), | |
| summaryBaseData: null, | |
| setSummaryBaseData: (summaryBaseData) => set({ summaryBaseData }), | |
| swotData75: null, | |
| setSwotData75: (swotData) => set({ swotData75: swotData }), | |
| swotData78: null, | |
| setSwotData78: (swotData) => set({ swotData78: swotData }), | |
| swotData79: null, | |
| setSwotData79: (swotData) => set({ swotData79: swotData }), | |
| swotTable: null, | |
| setSwotTable: (swotTable) => set({ swotTable }), | |
| urlMapping: null, | |
| setUrlMapping: (urlMapping) => set({ urlMapping }), | |
| showPercentage: true, | |
| setShowPercentage: (showPercentage) => set({ showPercentage }), | |
| momentResult: null, | |
| setMomentResult: (momentResult) => set({ momentResult }), | |
| ownFile: null, | |
| setOwnFile: (ownFile) => set({ ownFile }), | |
| strategyXMoment: null, | |
| setStrategyXMoment: (strategyXMoment) => set({ strategyXMoment }), | |
| // 画像生成バッチIDの管理 | |
| activeImageBatchIds: new Map<string, string>(), | |
| setImageBatchId: (key: string, batchId: string) => | |
| set((state) => { | |
| const newMap = new Map(state.activeImageBatchIds); | |
| newMap.set(key, batchId); | |
| return { activeImageBatchIds: newMap }; | |
| }), | |
| removeImageBatchId: (key: string) => | |
| set((state) => { | |
| const newMap = new Map(state.activeImageBatchIds); | |
| newMap.delete(key); | |
| return { activeImageBatchIds: newMap }; | |
| }), | |
| clearImageBatchIds: () => set({ activeImageBatchIds: new Map<string, string>() }), | |
| // FV生成の重複実行防止 | |
| proposalTabsExecuted: false, | |
| setProposalTabsExecuted: (executed: boolean) => set({ proposalTabsExecuted: executed }), | |
| resetProposalTabsExecution: () => set({ proposalTabsExecuted: false }), | |
| // contentHashと完了済みbatchIdの関係管理 | |
| completedBatchesBySelection: new Map<string, Set<string>>(), | |
| markBatchCompleted: (contentHash: string, batchId: string) => { | |
| set((state) => { | |
| const newMap = new Map(state.completedBatchesBySelection); | |
| if (!newMap.has(contentHash)) { | |
| newMap.set(contentHash, new Set<string>()); | |
| } | |
| newMap.get(contentHash)!.add(batchId); | |
| return { completedBatchesBySelection: newMap }; | |
| }); | |
| }, | |
| isBatchCompleted: (contentHash: string, batchId: string) => { | |
| const state = get(); | |
| const completedSet = state.completedBatchesBySelection.get(contentHash); | |
| const isCompleted = completedSet ? completedSet.has(batchId) : false; | |
| return isCompleted; | |
| }, | |
| clearCompletedBatches: () => set({ completedBatchesBySelection: new Map<string, Set<string>>() }), | |
| // 分析前実行のAPI結果キャッシュをクリア(リトライ時は使い回すためのキャッシュ) | |
| clearPreAnalysisCache: () => | |
| set({ | |
| downloadData: null, | |
| scoreDict: null, | |
| commonDict: null, | |
| scoreTotal: null, | |
| urlCategoryScores: null, | |
| ownCategoryScores: null, | |
| summaryData: null, | |
| summaryBaseData: null, | |
| swotData75: null, | |
| swotData78: null, | |
| swotData79: null, | |
| swotTable: null, | |
| }), | |
| })); | |