@nakamura-123/pages 1.1.26 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,8 +49,16 @@ const InputNav = ({ question }) => {
49
49
  const realm = (0, react_2.useRealm)();
50
50
  const Input = InputDB.find((data) => data.inputId === inputId);
51
51
  const mode = (0, quizHook_1.useGetMode)();
52
+ // DBの保存をstoreに読み込んだ時だけDBに書き戻す(未読み込みで書くと既存の保存が消える)
53
+ const isLoadedRef = (0, react_1.useRef)(false);
54
+ // TabAnimeViewのkeyで問題ごとに作り直されるため、turnはマウント時の値で固定してよい
55
+ const turn = (0, react_redux_1.useSelector)((state) => state.quiz.currentInfo.state.turn);
56
+ const draft = (0, react_redux_1.useSelector)((state) => state.quiz.currentInfo.inputDrafts[turn]);
52
57
  // storeのセーブデータを取得
53
58
  const saveDatas = (0, react_redux_1.useSelector)((state) => state.quiz.currentInfo.input);
59
+ // 後片付け(クリーンアップ)で最新のバッファを読むため
60
+ const saveDatasRef = (0, react_1.useRef)(saveDatas);
61
+ saveDatasRef.current = saveDatas;
54
62
  // カウンターの情報を取得
55
63
  const inputSize = (Input === null || Input === void 0 ? void 0 : Input.size) || "lg";
56
64
  const limitCnt = lib_1.maxTextLimitInfo[inputSize];
@@ -60,8 +68,25 @@ const InputNav = ({ question }) => {
60
68
  if (Input) {
61
69
  const firstText = (0, InputFnc_1.createBaseText)(Input.baseText);
62
70
  dispatch({ type: "quiz/setFirstInput", payload: firstText });
71
+ // 回答前の問題に戻ってきた場合は、書きかけを回答タブに復元する
72
+ if (mode === "quiz" && draft !== undefined) {
73
+ dispatch({
74
+ type: "quiz/changeInputText",
75
+ payload: { index: 0, text: draft },
76
+ });
77
+ dispatch({
78
+ type: "quiz/tapInputSave",
79
+ payload: { index: 0, isSave: true },
80
+ });
81
+ }
63
82
  }
64
83
  return () => {
84
+ if (!isLoadedRef.current) {
85
+ const answer = saveDatasRef.current[0];
86
+ const text = (answer === null || answer === void 0 ? void 0 : answer.isSave) ? answer.saveText : null;
87
+ dispatch({ type: "quiz/setInputDraft", payload: { turn, text } });
88
+ return;
89
+ }
65
90
  dispatch(db_1.InputModel.saveStoreInput({ realm, inputId }));
66
91
  };
67
92
  }, []);
@@ -71,6 +96,7 @@ const InputNav = ({ question }) => {
71
96
  Input === null || Input === void 0 ? void 0 : Input.saveInputs.forEach((data) => {
72
97
  dispatch({ type: "quiz/addInput", payload: data });
73
98
  });
99
+ isLoadedRef.current = true;
74
100
  }, [mode]);
75
101
  const text = ((_b = saveDatas[index]) === null || _b === void 0 ? void 0 : _b.saveText) || "";
76
102
  const isSave = ((_c = saveDatas[index]) === null || _c === void 0 ? void 0 : _c.isSave) || false;