<commit_before>/**
 * RtK Kanji flashcard review.
 *
 * Options:
 *
 *   fcr_options   Options to setup uiFlashcardReview
 *   end_url       Url to redirect to at the end of the review
 *
 */
// @ts-check

import $$, { DomJS, asHtmlElement, domGetById, hasClass } from "@lib/dom";
import AjaxDialog from "@old/ajaxdialog";
import DictLookupDialog from "@old/components/DictLookupDialog";
import EditFlashcardDialog from "@old/components/EditFlashcardDialog";
import EditStoryDialog from "@old/components/EditStoryDialog";
import FlashcardReview, { FCRATE } from "@app/review/FlashcardReview";
import ReviewPage from "@app/review/ReviewPage";

/** @typedef {{end_url: string, editstory_url: string}} TReviewProps */

export default class KanjiReview {
  /** @type {TReviewProps} */
  options;

  /** @type {FlashcardReview} */
  oReview;

  /** @type {DomJS<Element>}*/
  $elStats;
  /** @type {HTMLElement} */
  elProgressBar;

  /** @type {DictLookupDialog?} */
  dictDialog = null;

  /** @type {EditFlashcardDialog?} */
  oEditFlashcard = null;
  /** @type {TUcsId} */
  oEditFlashcardId = 0;

  /** @type {EditStoryDialog?} */
  editStoryDialog = null;

  /** @type {number[]} */
  deletedCards = [];

  /**
   *
   * @param {TReviewOptions} fcrOptions ... options for FlashcardReview instance
   * @param {TReviewProps} props ... props for Vue component (TBD refactor)
   */
  constructor(fcrOptions, props) {
    this.options = props;

    fcrOptions.events = {
      onEndReview: this.onEndReview,
      onFlashcardCreate: this.onFlashcardCreate,
      onFlashcardDestroy: this.onFlashcardDestroy,
      onFlashcardState: this.onFlashcardState,
      onFlashcardUndo: this.onFlashcardUndo,
    };
    fcrOptions.scope = this;

    this.oReview = new FlashcardReview(fcrOptions);

    this.reviewPage = new ReviewPage(this.onAction.bind(this));

    this.reviewPage.addShortcutKey("f", "flip");
    this.reviewPage.addShortcutKey(" ", "flip");
    this.reviewPage.addShortcutKey(96, "flip"); // NUMPAD_0

    this.reviewPage.addShortcutKey("n", "no");
    this.reviewPage.addShortcutKey("g", "again");
    this.reviewPage.addShortcutKey("h", "hard");
    this.reviewPage.addShortcutKey("y", "yes");
    this.reviewPage.addShortcutKey("e", "easy");

    // added number keys to answer with just left hand
    this.reviewPage.addShortcutKey("1", "no");
    this.reviewPage.addShortcutKey("2", "hard");
    this.reviewPage.addShortcutKey("3", "yes");
    this.reviewPage.addShortcutKey("4", "easy");

    // same for numpad keys
    this.reviewPage.addShortcutKey(97, "no"); // NUMPAD_1
    this.reviewPage.addShortcutKey(98, "hard"); // NUMPAD_2
    this.reviewPage.addShortcutKey(99, "yes"); // NUMPDA_3
    this.reviewPage.addShortcutKey(100, "easy"); // NUMPAD_4

    this.reviewPage.addShortcutKey("u", "undo");
    this.reviewPage.addShortcutKey("s", "story");
    this.reviewPage.addShortcutKey("d", "dict");

    // skip flashcard (110 = comma)
    this.reviewPage.addShortcutKey("k", "skip");
    this.reviewPage.addShortcutKey(110, "skip"); // NUMPAD_DECIMAL<commit_msg>Use "a" key shortcut for Again rating (instead of "g")<commit_after>/**
 * RtK Kanji flashcard review.
 *
 * Options:
 *
 *   fcr_options   Options to setup uiFlashcardReview
 *   end_url       Url to redirect to at the end of the review
 *
 */
// @ts-check

import $$, { DomJS, asHtmlElement, domGetById, hasClass } from "@lib/dom";
import AjaxDialog from "@old/ajaxdialog";
import DictLookupDialog from "@old/components/DictLookupDialog";
import EditFlashcardDialog from "@old/components/EditFlashcardDialog";
import EditStoryDialog from "@old/components/EditStoryDialog";
import FlashcardReview, { FCRATE } from "@app/review/FlashcardReview";
import ReviewPage from "@app/review/ReviewPage";

/** @typedef {{end_url: string, editstory_url: string}} TReviewProps */

export default class KanjiReview {
  /** @type {TReviewProps} */
  options;

  /** @type {FlashcardReview} */
  oReview;

  /** @type {DomJS<Element>}*/
  $elStats;
  /** @type {HTMLElement} */
  elProgressBar;

  /** @type {DictLookupDialog?} */
  dictDialog = null;

  /** @type {EditFlashcardDialog?} */
  oEditFlashcard = null;
  /** @type {TUcsId} */
  oEditFlashcardId = 0;

  /** @type {EditStoryDialog?} */
  editStoryDialog = null;

  /** @type {number[]} */
  deletedCards = [];

  /**
   *
   * @param {TReviewOptions} fcrOptions ... options for FlashcardReview instance
   * @param {TReviewProps} props ... props for Vue component (TBD refactor)
   */
  constructor(fcrOptions, props) {
    this.options = props;

    fcrOptions.events = {
      onEndReview: this.onEndReview,
      onFlashcardCreate: this.onFlashcardCreate,
      onFlashcardDestroy: this.onFlashcardDestroy,
      onFlashcardState: this.onFlashcardState,
      onFlashcardUndo: this.onFlashcardUndo,
    };
    fcrOptions.scope = this;

    this.oReview = new FlashcardReview(fcrOptions);

    this.reviewPage = new ReviewPage(this.onAction.bind(this));

    this.reviewPage.addShortcutKey("f", "flip");
    this.reviewPage.addShortcutKey(" ", "flip");
    this.reviewPage.addShortcutKey(96, "flip"); // NUMPAD_0

    this.reviewPage.addShortcutKey("n", "no");
    this.reviewPage.addShortcutKey("a", "again");
    this.reviewPage.addShortcutKey("h", "hard");
    this.reviewPage.addShortcutKey("y", "yes");
    this.reviewPage.addShortcutKey("e", "easy");

    // added number keys to answer with just left hand
    this.reviewPage.addShortcutKey("1", "no");
    this.reviewPage.addShortcutKey("2", "hard");
    this.reviewPage.addShortcutKey("3", "yes");
    this.reviewPage.addShortcutKey("4", "easy");

    // same for numpad keys
    this.reviewPage.addShortcutKey(97, "no"); // NUMPAD_1
    this.reviewPage.addShortcutKey(98, "hard"); // NUMPAD_2
    this.reviewPage.addShortcutKey(99, "yes"); // NUMPDA_3
    this.reviewPage.addShortcutKey(100, "easy"); // NUMPAD_4

    this.reviewPage.addShortcutKey("u", "undo");
    this.reviewPage.addShortcutKey("s", "story");
    this.reviewPage.addShortcutKey("d", "dict");

    // skip flashcard (110 = comma)
    this.reviewPage.addShortcutKey("k", "skip");
    this.reviewPage.addShortcutKey(110, "skip"); // NUMPAD_DECIMAL
{'fraction_non_alphanumeric': 0.15144192041243756, 'fraction_numerical': 0.008699855002416627, 'mean_word_length': 3.934817170111288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '918384', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2046, 'n_words': 408}