Spaces:
Sleeping
Sleeping
File size: 8,088 Bytes
68f7925 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | // import { create } from 'zustand';
// interface StoreState {
// fvInfos: object | null;
// ownUrl: string;
// ownImage: string | null;
// ownImageBase64: string | null;
// ownImageName: string;
// competitionUrls: string[];
// absentImage: string | null;
// mainRadio: string;
// submittedSecondRadio: 'url' | 'upload';
// submittedOwnUrl: string;
// submittedOwnImage: string | null;
// setSubmittedSecondRadio: (val: 'url' | 'upload') => void;
// setSubmittedOwnUrl: (url: string) => void;
// setSubmittedOwnImage: (img: string | null) => void;
// setFvInfos: (infos: object | null) => void;
// setMainRadio: (val: string) => void;
// setAbsentImage: (img: string | null) => void;
// setOwnUrl: (url: string) => void;
// setOwnImage: (image: string | null) => void;
// setOwnImageBase64: (image: string | null) => void;
// setOwnImageName: (name: string) => void;
// setCompetitionUrls: (urls: string[]) => void;
// }
// export const useInputStore = create<StoreState>((set) => ({
// fvInfos: null,
// ownUrl: '',
// ownImage: null,
// absentImage: null,
// ownImageBase64: null,
// ownImageName: '',
// competitionUrls: [],
// mainRadio: 'exist',
// submittedSecondRadio: 'url',
// submittedOwnUrl: '',
// submittedOwnImage: null,
// setSubmittedSecondRadio: (val) => set({ submittedSecondRadio: val }),
// setSubmittedOwnUrl: (url) => set({ submittedOwnUrl: url }),
// setSubmittedOwnImage: (img) => set({ submittedOwnImage: img }),
// setFvInfos: (infos) => set({ fvInfos: infos }),
// setMainRadio: (radio) => set({ mainRadio: radio }),
// setAbsentImage: (img) => set({ absentImage: img }),
// setOwnUrl: (url: string) => set(() => ({ ownUrl: url })),
// setOwnImage: (img) => set({ ownImage: img }),
// setOwnImageBase64: (image: string | null) => set(() => ({ ownImageBase64: image })),
// setOwnImageName: (name) => set({ ownImageName: name }),
// setCompetitionUrls: (urls: string[]) => set(() => ({ competitionUrls: urls })),
// }));
import { create } from 'zustand';
interface SectionVisibility {
[key: string]: {
visible: boolean;
order: number;
};
}
interface InputFormData {
ownUrl: string;
urlText: string[];
ownImage: string;
ownImageName: string;
user_email: string;
}
interface StoreState {
ownUrl: string;
competitionUrls: string[];
purpose: string;
fvInfos: Record<string, unknown> | null;
cnInfo: Record<string, unknown> | null;
scoreDict: object | null;
inputFormData: InputFormData | null;
ownImage: string | null;
ownImageBase64: string | null;
ownImageName: string;
absentImage: string | null;
mainRadio: string;
submittedSecondRadio: 'url' | 'upload';
submittedOwnUrl: string;
submittedOwnImage: string | null;
ownFile: File | null;
// 最終的に選択されたモーメント(改善案生成APIに送信される実際のデータ)
selectedMoments: string[];
// refresh-moments画面の状態管理
refreshMomentsDefaultMoments: { text: string; value: boolean }[]; // デフォルトの方向性選択肢
refreshMomentsCheckedMoments: Record<string, boolean>; // AI提案モーメントのチェック状態(UI表示用)
refreshMomentsFreeInputs: { text: string; value: boolean }[]; // フリー入力の選択肢
// セクション管理の状態(タブごとに保存)
sectionVisibilities: Record<string, SectionVisibility>;
// 画像バリデーションエラー(check_url APIレスポンス後に設定される)
checkUrlFvErrors: string[];
setOwnFile: (ownFile: File | null) => void;
setSubmittedSecondRadio: (val: 'url' | 'upload') => void;
setSubmittedOwnUrl: (url: string) => void;
setSubmittedOwnImage: (img: string | null) => void;
setFvInfos: (infos: Record<string, unknown> | null) => void;
setCnInfo: (infos: Record<string, unknown> | null) => void;
setScoreDict: (dict: object | null) => void;
setInputFormData: (data: InputFormData | null) => void;
setPurpose: (purpose: string) => void;
setMainRadio: (val: string) => void;
setAbsentImage: (img: string | null) => void;
setOwnUrl: (url: string) => void;
setOwnImage: (image: string | null) => void;
setOwnImageBase64: (image: string | null) => void;
setOwnImageName: (name: string) => void;
setCompetitionUrls: (urls: string[]) => void;
setSelectedMoments: (selectedMoments: string[]) => void;
// refresh-moments画面の状態管理メソッド
setRefreshMomentsDefaultMoments: (moments: { text: string; value: boolean }[]) => void;
setRefreshMomentsCheckedMoments: (moments: Record<string, boolean>) => void;
setRefreshMomentsFreeInputs: (inputs: { text: string; value: boolean }[]) => void;
// セクション管理メソッド
setSectionVisibility: (tabName: string, visibility: SectionVisibility) => void;
getSectionVisibility: (tabName: string) => SectionVisibility | undefined;
// 画像バリデーションエラー管理メソッド
setCheckUrlFvErrors: (errors: string[]) => void;
}
export const useInputStore = create<StoreState>((set, get) => ({
ownUrl: '',
competitionUrls: [],
purpose: '',
fvInfos: null,
cnInfo: null,
scoreDict: null,
inputFormData: null,
ownImage: null,
ownImageBase64: null,
ownImageName: '',
absentImage: null,
mainRadio: 'exist',
submittedSecondRadio: 'url',
submittedOwnUrl: '',
submittedOwnImage: null,
ownFile: null,
selectedMoments: [],
// refresh-moments画面の初期状態
refreshMomentsDefaultMoments: [
{
text: '購買前(まだ商品について詳しくないが、商品の情報収集を実施している状態)',
value: false,
},
{
text: '比較検討中(他社と比較をして迷い、決め手を探している状態)',
value: false,
},
{
text: '購買検討中(ある程度購入意欲は高いが、最後の決め手を探してる)',
value: false,
},
],
refreshMomentsCheckedMoments: {},
refreshMomentsFreeInputs: [
{ text: '', value: false },
{ text: '', value: false },
{ text: '', value: false },
],
// セクション管理の初期状態
sectionVisibilities: {},
// 画像バリデーションエラーの初期状態
checkUrlFvErrors: [],
setOwnFile: (ownFile) => set({ ownFile }),
setSubmittedSecondRadio: (val) => set({ submittedSecondRadio: val }),
setSubmittedOwnUrl: (url) => set({ submittedOwnUrl: url }),
setSubmittedOwnImage: (img) => set({ submittedOwnImage: img }),
setFvInfos: (infos) => set({ fvInfos: infos }),
setCnInfo: (infos) => set({ cnInfo: infos }),
setScoreDict: (dict) => set({ scoreDict: dict }),
setInputFormData: (data) => set({ inputFormData: data }),
setPurpose: (purpose) => set({ purpose }),
setMainRadio: (radio) => set({ mainRadio: radio }),
setAbsentImage: (img) => set({ absentImage: img }),
setOwnUrl: (url: string) => set(() => ({ ownUrl: url })),
setOwnImage: (img) => set({ ownImage: img }),
setOwnImageBase64: (image: string | null) => set(() => ({ ownImageBase64: image })),
setOwnImageName: (name) => set({ ownImageName: name }),
setCompetitionUrls: (urls: string[]) => set(() => ({ competitionUrls: urls })),
setSelectedMoments: (selectedMoments) => set({ selectedMoments }),
// refresh-moments画面の状態管理メソッド
setRefreshMomentsDefaultMoments: (moments) => set({ refreshMomentsDefaultMoments: moments }),
setRefreshMomentsCheckedMoments: (moments) => set({ refreshMomentsCheckedMoments: moments }),
setRefreshMomentsFreeInputs: (inputs) => set({ refreshMomentsFreeInputs: inputs }),
// セクション管理メソッド
setSectionVisibility: (tabName, visibility) =>
set((state) => ({
sectionVisibilities: {
...state.sectionVisibilities,
[tabName]: visibility,
},
})),
getSectionVisibility: (tabName: string) => {
return get().sectionVisibilities[tabName];
},
// 画像バリデーションエラー管理メソッド
setCheckUrlFvErrors: (errors: string[]) => set({ checkUrlFvErrors: errors }),
}));
|