@nakamura-123/pages 1.3.4 → 1.3.6

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.
@@ -10,8 +10,10 @@ const db_1 = require("@nakamura-123/db");
10
10
  const common_1 = require("@nakamura-123/common");
11
11
  const tagFncD_1 = require("../../functions/tagFncD");
12
12
  const TagBadge5s = ({}) => {
13
- const TagDB = (0, react_2.useQuery)(db_1.TagSchema);
14
- const tagLegels = TagDB.map((tag) => tag.level);
13
+ // Tagを直接数えると、同じinputIdを共有する記述問題が重複して数えられてしまう。
14
+ // Question経由にして、他の画面と同じ基準(dedup後の問題数)に揃える。
15
+ const QuestionDB = (0, react_2.useQuery)(db_1.DQuestionSchema);
16
+ const tagLegels = (0, tagFncD_1.getAllTagLevels)(QuestionDB);
15
17
  const tag5Infos = (0, tagFncD_1.countTagsByLevel)(tagLegels);
16
18
  return (<react_native_1.View style={styles.container}>
17
19
  {tag5Infos.map((tag, i) => (<common_1.Badge key={i} name={String(tag.cnt)} icon={"tag"} circleColor={tag.color} style={styles.badge}/>))}
@@ -54,10 +54,25 @@ const getMiniTestQuestions = (QuestionDB, subjectType, key, cnt, outOfYearRange)
54
54
  exports.getMiniTestQuestions = getMiniTestQuestions;
55
55
  // 模擬試験の開始(Randam)
56
56
  const getTestQuestions = (QuestionDB, cnt) => {
57
- // シャッフルしてから必要な数だけ抽出
57
+ var _a;
58
+ // 同じinputIdは1問しか採れないため、先にcnt個だけ抜くと数が足りなくなる。
59
+ // 全インデックスをシャッフルして、cnt問そろうまで拾っていく。
58
60
  const totalCnt = QuestionDB.length;
59
- const numArray = lib_1.utilFnc.createArrayBasedOnCnt(cnt, totalCnt);
60
- const randomItems = Array.from(numArray).map((index) => QuestionDB[index]);
61
+ const shuffledIdx = lib_1.utilFnc.shuffleList(Array.from({ length: totalCnt }, (_, i) => i));
62
+ const randomItems = [];
63
+ const usedInputIds = new Set();
64
+ for (const index of shuffledIdx) {
65
+ if (randomItems.length >= cnt)
66
+ break;
67
+ const question = QuestionDB[index];
68
+ const inputId = (_a = question.input) === null || _a === void 0 ? void 0 : _a.inputId;
69
+ if (inputId) {
70
+ if (usedInputIds.has(inputId))
71
+ continue;
72
+ usedInputIds.add(inputId);
73
+ }
74
+ randomItems.push(question);
75
+ }
61
76
  randomItems.sort((a, b) => a.num - b.num);
62
77
  const formatted = (0, questionFormatD_1.formatQuestions)(randomItems);
63
78
  const filttered = (0, questionFilterD_1.commonFilter)(formatted, cnt, false);
@@ -69,6 +69,9 @@ const replaceOldTagData = (realm, yearIdTrans) => __awaiter(void 0, void 0, void
69
69
  return;
70
70
  const realmInfos = stores_1.oldStorage.formatOldMarkData(markData, yearIdTrans);
71
71
  db_1.TagModel.updateOldTags(realm, realmInfos);
72
+ // updateOldTagsはyearId+numで直接書くので伝播しない。
73
+ // 次回起動まで放置すると、移行した付箋が伝播で下位レベルに上書きされるため、ここで揃えておく。
74
+ db_1.TagModel.alignTagsByInputId(realm);
72
75
  });
73
76
  // 40. DailyLogデータの読み込み
74
77
  const addOldDailyLogData = (realm) => __awaiter(void 0, void 0, void 0, function* () {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commonFilter = exports.filterByTags = exports.filterByOutOfUnitRange = exports.filterByOutOfYearRange = exports.getSubYearQuestions = exports.getYearQuestions = exports.getSubUnitQuestions = exports.getUnitQuestions = void 0;
4
4
  const lib_1 = require("@nakamura-123/lib");
5
+ const types_1 = require("@nakamura-123/types");
5
6
  const filters = {
6
7
  unit: "unitId == $0 && subUnitId == $1",
7
8
  unitTop: "unitId == $0",
@@ -58,13 +59,29 @@ const filterByTags = (questions, startCfg) => {
58
59
  };
59
60
  exports.filterByTags = filterByTags;
60
61
  // 12_シャッフル
61
- // 13_問題数の設定
62
+ // 13_同じinputIdの重複を除外
63
+ // 14_問題数の設定
62
64
  const commonFilter = (questions, quizCnt, isShuffle) => {
63
65
  // 12_シャッフル
64
66
  let returnList = questions;
65
67
  if (isShuffle)
66
68
  returnList = lib_1.utilFnc.shuffleList(questions);
67
- // 13_問題数の設定
69
+ // 13_同じinputIdの重複を除外
70
+ returnList = dedupeByInputId(returnList);
71
+ // 14_問題数の設定
68
72
  return returnList.slice(0, quizCnt);
69
73
  };
70
74
  exports.commonFilter = commonFilter;
75
+ // 同じinputIdの記述問題はInputレコード(保存テキスト)を共有する=同じ問題なので、1問だけ残す。
76
+ // シャッフルの後に呼ぶことで、残る1問が毎回ちがう年度になる。
77
+ const dedupeByInputId = (questions) => {
78
+ const seen = new Set();
79
+ return questions.filter((question) => {
80
+ if (!types_1.qGard.isDQInStoreInput(question))
81
+ return true;
82
+ if (seen.has(question.inputId))
83
+ return false;
84
+ seen.add(question.inputId);
85
+ return true;
86
+ });
87
+ };
@@ -1,6 +1,7 @@
1
1
  import { ColorKeys } from "@nakamura-123/lib";
2
2
  import { QSelected, Lib } from "@nakamura-123/types";
3
3
  import { QRD, TagInfo } from "../types/filterType";
4
+ export declare const getAllTagLevels: (QuestionDB: QRD) => Lib.LevelNames[];
4
5
  export declare function getCategoryTagLevelCntsD(QuestionDB: QRD, category: number, type: "unit" | "year", outOfYearRange?: number[] | undefined): Lib.LevelNames[];
5
6
  export declare function getUnitSubTagLevelCnts(QuestionDB: QRD, unitId: number, subUnitId: number, outOfYearRange?: number[]): string[];
6
7
  export declare function getYearSubTagLevelCnts(QuestionDB: QRD, year: number, key: number): string[];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // helpers.ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getBootTagLevelCnts = exports.getSubTagLevelCnts = void 0;
4
+ exports.getBootTagLevelCnts = exports.getSubTagLevelCnts = exports.getAllTagLevels = void 0;
5
5
  exports.getCategoryTagLevelCntsD = getCategoryTagLevelCntsD;
6
6
  exports.getUnitSubTagLevelCnts = getUnitSubTagLevelCnts;
7
7
  exports.getYearSubTagLevelCnts = getYearSubTagLevelCnts;
@@ -11,6 +11,29 @@ exports.getCategoryRate = getCategoryRate;
11
11
  exports.countTagsByLevelSelected = countTagsByLevelSelected;
12
12
  const lib_1 = require("@nakamura-123/lib");
13
13
  const questionFilterD_1 = require("./questionFilterD");
14
+ // 00_Tagのレベルを配列にする。同じinputIdの記述問題は同じ問題なので1問として数える。
15
+ // (配列の長さがそのまま「問題数」として表示されるため、ここで除外しないと出題数と食い違う)
16
+ const toTagLevels = (questions) => {
17
+ const seen = new Set();
18
+ const levels = [];
19
+ questions.forEach((question) => {
20
+ var _a;
21
+ const inputId = (_a = question.input) === null || _a === void 0 ? void 0 : _a.inputId;
22
+ if (inputId) {
23
+ if (seen.has(inputId))
24
+ return;
25
+ seen.add(inputId);
26
+ }
27
+ if (question.tag)
28
+ levels.push(question.tag.level);
29
+ });
30
+ return levels;
31
+ };
32
+ // 00_全問題のTagのレベルを取得(成績ページの全体バッジ用)
33
+ const getAllTagLevels = (QuestionDB) => {
34
+ return toTagLevels(QuestionDB);
35
+ };
36
+ exports.getAllTagLevels = getAllTagLevels;
14
37
  // 01_大単元のTagのレベルを取得
15
38
  function getCategoryTagLevelCntsD(QuestionDB, category, type, outOfYearRange) {
16
39
  let returnQuestions = QuestionDB;
@@ -21,7 +44,7 @@ function getCategoryTagLevelCntsD(QuestionDB, category, type, outOfYearRange) {
21
44
  type === "unit"
22
45
  ? (0, questionFilterD_1.getUnitQuestions)(returnQuestions, category)
23
46
  : (0, questionFilterD_1.getYearQuestions)(returnQuestions, category);
24
- return returnQuestions.map((question) => question.tag.level);
47
+ return toTagLevels(returnQuestions);
25
48
  }
26
49
  // 02_Unitの小単元のTagのレベルを取得
27
50
  function getUnitSubTagLevelCnts(QuestionDB, unitId, subUnitId, outOfYearRange) {
@@ -30,11 +53,11 @@ function getUnitSubTagLevelCnts(QuestionDB, unitId, subUnitId, outOfYearRange) {
30
53
  returnQuestions = (0, questionFilterD_1.filterByOutOfYearRange)(QuestionDB, outOfYearRange);
31
54
  }
32
55
  returnQuestions = (0, questionFilterD_1.getSubUnitQuestions)(returnQuestions, unitId, subUnitId);
33
- return returnQuestions.map((question) => question.tag.level);
56
+ return toTagLevels(returnQuestions);
34
57
  }
35
58
  // 03_Yearの小単元のTagのレベルを取得
36
59
  function getYearSubTagLevelCnts(QuestionDB, year, key) {
37
- return (0, questionFilterD_1.getSubYearQuestions)(QuestionDB, year, key).map((question) => question.tag.level);
60
+ return toTagLevels((0, questionFilterD_1.getSubYearQuestions)(QuestionDB, year, key));
38
61
  }
39
62
  // 11_5Tagのレベルを取得。Unit(大・小単元) 、Year(大・小単元) どちらでも可。
40
63
  const getSubTagLevelCnts = (QuestionDB, selected, outOfYearRange) => {
@@ -56,21 +79,21 @@ exports.getSubTagLevelCnts = getSubTagLevelCnts;
56
79
  const helperUnitTags = (filteredQuestions, selected) => {
57
80
  const { category, lesson } = selected;
58
81
  if (lesson.key === 0)
59
- return (0, questionFilterD_1.getUnitQuestions)(filteredQuestions, category).map((question) => question.tag.level);
60
- return (0, questionFilterD_1.getSubUnitQuestions)(filteredQuestions, category, lesson.key).map((question) => question.tag.level);
82
+ return toTagLevels((0, questionFilterD_1.getUnitQuestions)(filteredQuestions, category));
83
+ return toTagLevels((0, questionFilterD_1.getSubUnitQuestions)(filteredQuestions, category, lesson.key));
61
84
  };
62
85
  // 13_11のヘルパー(試験別の5種のタグをカウント)
63
86
  const helperYearTags = (filteredQuestions, selected) => {
64
87
  const { category, lesson } = selected;
65
88
  if (lesson.key === 0)
66
- return (0, questionFilterD_1.getYearQuestions)(filteredQuestions, category).map((question) => question.tag.level);
67
- return (0, questionFilterD_1.getSubYearQuestions)(filteredQuestions, category, lesson.key).map((question) => question.tag.level);
89
+ return toTagLevels((0, questionFilterD_1.getYearQuestions)(filteredQuestions, category));
90
+ return toTagLevels((0, questionFilterD_1.getSubYearQuestions)(filteredQuestions, category, lesson.key));
68
91
  };
69
92
  // 14_5Tagのレベルの数を取得。集中特訓モード用に、試験大範囲・単元大範囲のフィルタをかけます
70
93
  const getBootTagLevelCnts = (QuestionDB, outOfUnitRange, outOfYearRange) => {
71
94
  let filteredQuestions = (0, questionFilterD_1.filterByOutOfYearRange)(QuestionDB, outOfYearRange);
72
95
  filteredQuestions = (0, questionFilterD_1.filterByOutOfUnitRange)(filteredQuestions, outOfUnitRange);
73
- return filteredQuestions.map((question) => question.tag.level);
96
+ return toTagLevels(filteredQuestions);
74
97
  };
75
98
  exports.getBootTagLevelCnts = getBootTagLevelCnts;
76
99
  // 21_赤付箋の割合を取得
@@ -3,6 +3,7 @@ interface InputBoxProps {
3
3
  index: number;
4
4
  text: string;
5
5
  baseText: string;
6
+ isSave: boolean;
6
7
  }
7
8
  declare const InputBox: React.FC<InputBoxProps>;
8
9
  export default InputBox;
@@ -1,43 +1,20 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
- const react_1 = __importStar(require("react"));
6
+ const react_1 = __importDefault(require("react"));
27
7
  const react_native_1 = require("react-native");
28
8
  const react_redux_1 = require("react-redux");
29
9
  const common_1 = require("@nakamura-123/common");
30
10
  const lib_1 = require("@nakamura-123/lib");
31
- const InputBox = ({ index, text, baseText }) => {
11
+ const InputBox = ({ index, text, baseText, isSave, }) => {
32
12
  var _a;
33
13
  const dispatch = (0, react_redux_1.useDispatch)();
34
- // 書き込みを始めたら、保存に切り替える
35
- const [isWrited, setIsWrited] = (0, react_1.useState)(false);
36
14
  const onChangeText = (text) => {
37
- if (text !== baseText && !isWrited) {
15
+ // 書き込んだらセーブに切り替える。破棄した後に書き直したときも戻す
16
+ if (!isSave && text !== baseText)
38
17
  dispatch({ type: "quiz/tapInputSave", payload: { index, isSave: true } });
39
- setIsWrited(true);
40
- }
41
18
  dispatch({ type: "quiz/changeInputText", payload: { index, text } });
42
19
  };
43
20
  const fsize = (0, react_redux_1.useSelector)((state) => state.quizCfg.inQuizOption.fsize);
@@ -13,10 +13,9 @@ const createBaseText = (baseTexts) => {
13
13
  return baseText;
14
14
  };
15
15
  exports.createBaseText = createBaseText;
16
- // タブの文字を作成
16
+ // タブの文字を作成(保存の数だけ作らないと「閉」タブが押せなくなる)
17
17
  const createTabTexts = (length) => {
18
- const baseTexts = ["回答", "保存1", "保存2", "保存3", "保存4", "保存5"];
19
- const resultTexts = baseTexts.slice(0, length); // 必要な長さだけスライス
20
- return [...resultTexts, "閉"]; // "閉" を追加して新しい配列を返す
18
+ const texts = Array.from({ length }, (_, i) => i === 0 ? "回答" : `保存${i}`);
19
+ return [...texts, "閉"]; // "閉" を追加して新しい配列を返す
21
20
  };
22
21
  exports.createTabTexts = createTabTexts;
@@ -3,6 +3,7 @@ type Props = {
3
3
  saveDatas: {
4
4
  isSave: boolean;
5
5
  }[];
6
+ isBeforeAnswer: boolean;
6
7
  };
7
8
  declare const InputWarning: React.FC<Props>;
8
9
  export default InputWarning;
@@ -28,8 +28,8 @@ const react_native_1 = require("react-native");
28
28
  const common_1 = require("@nakamura-123/common");
29
29
  const MODAL_TITLE = "保存データが2つを超えています";
30
30
  const MODAL_MSG = " 保存データの数は2つまでにしてください。これを超えると、動作不良などの原因となります。\n\n 不要なデータは、下のボタンから破棄を選択するようにしてください。";
31
- const InputWarning = ({ saveDatas }) => {
32
- const saveDataCnt = saveDatas.filter((data) => data.isSave).length;
31
+ const InputWarning = ({ saveDatas, isBeforeAnswer }) => {
32
+ const saveDataCnt = saveDatas.filter((data, i) => data.isSave && !(isBeforeAnswer && i === 0)).length;
33
33
  const [warnnigMsg, setWarnnigMsg] = (0, react_1.useState)("");
34
34
  const [isVisible, setIsVisible] = (0, react_1.useState)(false);
35
35
  const [isModalShown, setIsModalShown] = (0, react_1.useState)(false); // モーダル表示済みフラグ
@@ -43,69 +43,86 @@ const InputWarnning_1 = __importDefault(require("./Input/InputWarnning"));
43
43
  const InputNav = ({ question }) => {
44
44
  var _a, _b, _c;
45
45
  const dispatch = (0, react_redux_1.useDispatch)();
46
+ // 後片付け(クリーンアップ)では、レンダー時の値ではなくその時点のstoreを読む
47
+ const store = (0, react_redux_1.useStore)();
46
48
  const [index, setIndex] = react_1.default.useState(0);
47
49
  const inputId = question.inputId;
48
50
  const InputDB = (0, react_2.useQuery)(db_1.InputSchema);
49
51
  const realm = (0, react_2.useRealm)();
50
52
  const Input = InputDB.find((data) => data.inputId === inputId);
53
+ const hasInput = !!Input;
51
54
  const mode = (0, quizHook_1.useGetMode)();
52
55
  // DBの保存をstoreに読み込んだ時だけDBに書き戻す(未読み込みで書くと既存の保存が消える)
53
56
  const isLoadedRef = (0, react_1.useRef)(false);
54
- // TabAnimeViewのkeyで問題ごとに作り直されるため、turnはマウント時の値で固定してよい
57
+ // PageContainerWrap.tsxのTabAnimeViewがkey={turn}で問題ごとに作り直すため、turnはマウント時の値で固定してよい
55
58
  const turn = (0, react_redux_1.useSelector)((state) => state.quiz.currentInfo.state.turn);
56
59
  const draft = (0, react_redux_1.useSelector)((state) => state.quiz.currentInfo.inputDrafts[turn]);
57
60
  // storeのセーブデータを取得
58
61
  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;
62
62
  // カウンターの情報を取得
63
63
  const inputSize = (Input === null || Input === void 0 ? void 0 : Input.size) || "lg";
64
64
  const limitCnt = lib_1.maxTextLimitInfo[inputSize];
65
65
  const currentCnt = ((_a = saveDatas[index]) === null || _a === void 0 ? void 0 : _a.saveText.length) || 0;
66
66
  const baseText = Input ? (0, InputFnc_1.createBaseText)(Input.baseText) : "";
67
+ // DBの保存データを読み込む。Inputが後から見つかる場合もあるので、読み込めるまで試す
67
68
  (0, react_1.useEffect)(() => {
68
- if (Input) {
69
- const firstText = (0, InputFnc_1.createBaseText)(Input.baseText);
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
- }
69
+ if (!Input || isLoadedRef.current)
70
+ return;
71
+ const firstText = (0, InputFnc_1.createBaseText)(Input.baseText);
72
+ dispatch({ type: "quiz/setFirstInput", payload: firstText });
73
+ Input.saveInputs.forEach((data) => {
74
+ dispatch({ type: "quiz/addInput", payload: data });
75
+ });
76
+ isLoadedRef.current = true;
77
+ // 回答前の問題に戻ってきた場合は、書きかけを回答タブに復元する
78
+ if (mode === "quiz" && draft !== undefined) {
79
+ dispatch({
80
+ type: "quiz/changeInputText",
81
+ payload: { index: 0, text: draft },
82
+ });
83
+ dispatch({
84
+ type: "quiz/tapInputSave",
85
+ payload: { index: 0, isSave: true },
86
+ });
82
87
  }
88
+ }, [inputId, hasInput]);
89
+ // 画面を離れるときの後片付け
90
+ (0, react_1.useEffect)(() => {
83
91
  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 } });
92
+ var _a, _b;
93
+ // 読み込めていないときはstoreが前の問題のままなので触らない(DBを空で上書きしない)
94
+ if (!isLoadedRef.current)
95
+ return;
96
+ const { quiz } = store.getState();
97
+ const input = quiz.currentInfo.input;
98
+ const isAnswered = ((_a = quiz.quizList[turn]) === null || _a === void 0 ? void 0 : _a.isCorrected) !== undefined;
99
+ // 未回答なら回答欄の書きかけを退避して戻ったときに復元する。回答済みなら書きかけは役目を終えるので消す
100
+ const answer = input[0];
101
+ const draftText = !isAnswered && (answer === null || answer === void 0 ? void 0 : answer.isSave) ? answer.saveText : null;
102
+ dispatch({ type: "quiz/setInputDraft", payload: { turn, text: draftText } });
103
+ const targets = isAnswered ? input : input.slice(1);
104
+ const saveInputs = targets
105
+ .filter((data) => data.isSave)
106
+ .map((data) => data.saveText);
107
+ // 中身が変わっていないなら書き込まない
108
+ const before = ((_b = db_1.InputModel.getInput(realm, inputId)) === null || _b === void 0 ? void 0 : _b.saveInputs) || [];
109
+ const isSame = before.length === saveInputs.length &&
110
+ before.every((text, i) => text === saveInputs[i]);
111
+ if (isSame)
88
112
  return;
89
- }
90
- dispatch(db_1.InputModel.saveStoreInput({ realm, inputId }));
113
+ db_1.InputModel.updateSaveText(realm, [{ id: inputId, saveInputs }]);
91
114
  };
92
115
  }, []);
93
- (0, react_1.useEffect)(() => {
94
- if (mode === "quiz")
95
- return;
96
- Input === null || Input === void 0 ? void 0 : Input.saveInputs.forEach((data) => {
97
- dispatch({ type: "quiz/addInput", payload: data });
98
- });
99
- isLoadedRef.current = true;
100
- }, [mode]);
101
116
  const text = ((_b = saveDatas[index]) === null || _b === void 0 ? void 0 : _b.saveText) || "";
102
117
  const isSave = ((_c = saveDatas[index]) === null || _c === void 0 ? void 0 : _c.isSave) || false;
103
118
  const isCloseSelect = index === saveDatas.length;
104
119
  return (<react_native_1.View style={styles.container}>
105
- <InputWarnning_1.default saveDatas={saveDatas}/>
120
+ <InputWarnning_1.default saveDatas={saveDatas} isBeforeAnswer={mode === "quiz"}/>
106
121
  <InputTab_1.default selectedIndex={index} setIndex={setIndex}/>
107
- {!isCloseSelect && (<>
108
- <InputBox_1.default index={index} text={text} baseText={baseText}/>
122
+ {!isCloseSelect && (
123
+ // keyを付けないとタブを切り替えてもInputBoxが作り直されず、書き込み判定が持ち越される
124
+ <>
125
+ <InputBox_1.default key={index} index={index} text={text} baseText={baseText} isSave={isSave}/>
109
126
  <react_native_1.View style={styles.bottomBox}>
110
127
  <InputSaveSelector_1.default isSave={isSave} index={index}/>
111
128
  <InputCounter_1.default count={currentCnt} limit={limitCnt}/>
@@ -22,13 +22,28 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
25
37
  Object.defineProperty(exports, "__esModule", { value: true });
26
38
  const react_1 = __importStar(require("react"));
27
39
  const react_native_1 = require("react-native");
28
40
  const react_redux_1 = require("react-redux");
29
41
  const Animatable = __importStar(require("react-native-animatable"));
42
+ const realm_1 = __importDefault(require("realm"));
43
+ const react_2 = require("@realm/react");
30
44
  const common_1 = require("@nakamura-123/common");
31
45
  const stores_1 = require("@nakamura-123/stores");
46
+ const db_1 = require("@nakamura-123/db");
32
47
  const { loadQuizFromStorage } = stores_1.saveStorage;
33
48
  const QuizSaveData = ({ navigation, saveKey }) => {
34
49
  const dispatch = (0, react_redux_1.useDispatch)();
@@ -36,9 +51,47 @@ const QuizSaveData = ({ navigation, saveKey }) => {
36
51
  const isExistedSaveData = (0, react_redux_1.useSelector)((state) => state.score.isSave[saveKey]);
37
52
  const lessonTitle = (0, react_redux_1.useSelector)((state) => state.quiz.selected.lesson.title);
38
53
  const turn = (0, react_redux_1.useSelector)((state) => state.quiz.currentInfo.state.turn);
54
+ const realm = (0, react_2.useRealm)();
55
+ const quizList = (0, react_redux_1.useSelector)((state) => state.quiz.quizList);
56
+ // 復元が終わってから同期を1回だけ走らせるためのトリガー。
57
+ // quizListの変化で走らせると、クイズ中に付箋を変えるたびに無駄な読み直しが起きる。
58
+ const [syncTrigger, setSyncTrigger] = (0, react_1.useState)(0);
39
59
  (0, react_1.useEffect)(() => {
40
- dispatch(loadQuizFromStorage(saveKey));
60
+ let isMounted = true;
61
+ (() => __awaiter(void 0, void 0, void 0, function* () {
62
+ yield dispatch(loadQuizFromStorage(saveKey));
63
+ if (isMounted)
64
+ setSyncTrigger((n) => n + 1);
65
+ }))();
66
+ return () => {
67
+ isMounted = false;
68
+ };
41
69
  }, []);
70
+ // 復元したquizListの付箋はセーブ時点のスナップショット。
71
+ // 中断中に他モードで付箋を変えた場合や、同じinputIdの問題がリスト内に複数残っている
72
+ // 古いセーブデータの場合にズレるので、DBの最新値へ差し替える。
73
+ (0, react_1.useEffect)(() => {
74
+ if (syncTrigger === 0)
75
+ return;
76
+ if (quizList.length === 0)
77
+ return;
78
+ let changedCnt = 0;
79
+ const levels = quizList.map((question) => {
80
+ var _a;
81
+ if (question.system !== "drill")
82
+ return null;
83
+ const { tagObjectId } = question;
84
+ if (!tagObjectId)
85
+ return null;
86
+ const tag = realm.objectForPrimaryKey(db_1.TagSchema, new realm_1.default.BSON.ObjectId(tagObjectId));
87
+ const level = (_a = tag === null || tag === void 0 ? void 0 : tag.level) !== null && _a !== void 0 ? _a : null;
88
+ if (level && level !== question.tag)
89
+ changedCnt++;
90
+ return level;
91
+ });
92
+ if (changedCnt > 0)
93
+ dispatch(stores_1.quizAction.syncTagLevels(levels));
94
+ }, [syncTrigger]);
42
95
  if (!isExistedSaveData)
43
96
  return null;
44
97
  const title = t("quiz.continue.title");