minor refactoring of learning session manager + swipe in learn
This commit is contained in:
parent
bd370b1849
commit
63a4b09937
4 changed files with 24 additions and 12 deletions
|
@ -34,7 +34,7 @@
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import Component from "vue-class-component";
|
import Component from "vue-class-component";
|
||||||
|
|
||||||
import { Deck, CustomDialogOptions } from "./types";
|
import { Deck, CustomDialogOptions, Event } from "./types";
|
||||||
|
|
||||||
import NavigationBar from "./components/layout/NavigationBar.vue";
|
import NavigationBar from "./components/layout/NavigationBar.vue";
|
||||||
import CustomDialog from "./components/customdialog/CustomDialog.vue";
|
import CustomDialog from "./components/customdialog/CustomDialog.vue";
|
||||||
|
@ -105,12 +105,14 @@ export default class App extends AppProps {
|
||||||
|
|
||||||
swipeLeft() {
|
swipeLeft() {
|
||||||
if (this.$route.name === "Learn") {
|
if (this.$route.name === "Learn") {
|
||||||
|
this.$eventHub.$emit(Event.SWIPE_LEFT_IN_LEARN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.$refs.navbar.hideDrawer();
|
this.$refs.navbar.hideDrawer();
|
||||||
}
|
}
|
||||||
swipeRight() {
|
swipeRight() {
|
||||||
if (this.$route.name === "Learn") {
|
if (this.$route.name === "Learn") {
|
||||||
|
this.$eventHub.$emit(Event.SWIPE_RIGHT_IN_LEARN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.$refs.navbar.showDrawer();
|
this.$refs.navbar.showDrawer();
|
||||||
|
|
|
@ -31,7 +31,7 @@ import Vue from "vue";
|
||||||
import Component from "vue-class-component";
|
import Component from "vue-class-component";
|
||||||
|
|
||||||
import Rating from "./Rating.vue";
|
import Rating from "./Rating.vue";
|
||||||
import { Deck, LearningSessionElement, CardRating } from "../../types";
|
import { Deck, LearningSessionElement, CardRating, Event } from "../../types";
|
||||||
import LearningSessionManager from "../../helpers/learningSessionManager";
|
import LearningSessionManager from "../../helpers/learningSessionManager";
|
||||||
|
|
||||||
import { finishLearningDialog } from "../../helpers/finishLearningDialogHelper";
|
import { finishLearningDialog } from "../../helpers/finishLearningDialogHelper";
|
||||||
|
@ -63,6 +63,15 @@ export default class Learn extends LearnProps {
|
||||||
}
|
}
|
||||||
} as LearningSessionElement;
|
} as LearningSessionElement;
|
||||||
|
|
||||||
|
created () {
|
||||||
|
this.$eventHub.$on(Event.SWIPE_LEFT_IN_LEARN, () => {
|
||||||
|
this.moveToNext();
|
||||||
|
});
|
||||||
|
this.$eventHub.$on(Event.SWIPE_RIGHT_IN_LEARN, () => {
|
||||||
|
this.moveToPrev();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
updateCurLearningElement() {
|
updateCurLearningElement() {
|
||||||
this.curLearningElement = this.learningSessionManager.getCurrentLearningSessionElement();
|
this.curLearningElement = this.learningSessionManager.getCurrentLearningSessionElement();
|
||||||
}
|
}
|
||||||
|
@ -72,7 +81,9 @@ export default class Learn extends LearnProps {
|
||||||
this.$router.replace("/");
|
this.$router.replace("/");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.learningSessionManager = new LearningSessionManager(this.decks);
|
this.learningSessionManager = new LearningSessionManager(
|
||||||
|
this.decks.filter(deck => deck.selected)
|
||||||
|
);
|
||||||
this.updateCurLearningElement();
|
this.updateCurLearningElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Deck, LearningSession, LearningSessionElement } from "@/types";
|
import { Deck, LearningSession, LearningSessionElement } from "@/types";
|
||||||
import Vue from "vue";
|
|
||||||
|
|
||||||
export default class LearningSessionManager {
|
export default class LearningSessionManager {
|
||||||
decks = [] as Deck[];
|
decks = [] as Deck[];
|
||||||
|
@ -8,19 +7,17 @@ export default class LearningSessionManager {
|
||||||
learningSession = {} as LearningSession;
|
learningSession = {} as LearningSession;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
decks: Deck[],
|
selectedDecks: Deck[],
|
||||||
numberOfRecentCardsToIgnoreWhenSelectingNextCard = -1
|
numberOfRecentCardsToIgnoreWhenSelectingNextCard = -1
|
||||||
) {
|
) {
|
||||||
this.decks = decks;
|
this.decks = selectedDecks;
|
||||||
this.numberOfRecentCardsToIgnoreWhenSelectingNextCard = numberOfRecentCardsToIgnoreWhenSelectingNextCard;
|
this.numberOfRecentCardsToIgnoreWhenSelectingNextCard = numberOfRecentCardsToIgnoreWhenSelectingNextCard;
|
||||||
this.cardsToSelectFrom = [];
|
this.cardsToSelectFrom = [];
|
||||||
|
|
||||||
this.decks.forEach((deck) => {
|
this.decks.forEach((deck) => {
|
||||||
if (deck.selected) {
|
|
||||||
deck.cards.forEach((card) => {
|
deck.cards.forEach((card) => {
|
||||||
this.cardsToSelectFrom.push({ deckId: deck.id, cardId: card.id });
|
this.cardsToSelectFrom.push({ deckId: deck.id, cardId: card.id, showAnswer: false, rating: undefined, card: undefined });
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.learningSession = { elements: [], currentElementIndex: 0 };
|
this.learningSession = { elements: [], currentElementIndex: 0 };
|
||||||
this.injectNewCard();
|
this.injectNewCard();
|
||||||
|
@ -86,6 +83,6 @@ export default class LearningSessionManager {
|
||||||
const currentLearningSessionElement = this.learningSession.elements[
|
const currentLearningSessionElement = this.learningSession.elements[
|
||||||
this.learningSession.currentElementIndex
|
this.learningSession.currentElementIndex
|
||||||
];
|
];
|
||||||
Vue.set(currentLearningSessionElement, "showAnswer", true);
|
currentLearningSessionElement.showAnswer = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,8 @@ export enum Event {
|
||||||
QUIT_LEARNING = "quitLearning",
|
QUIT_LEARNING = "quitLearning",
|
||||||
SELECT_ALL_DECKS = "selectAllDecks",
|
SELECT_ALL_DECKS = "selectAllDecks",
|
||||||
DESELECT_ALL_DECKS = "deselectAllDecks",
|
DESELECT_ALL_DECKS = "deselectAllDecks",
|
||||||
|
SWIPE_LEFT_IN_LEARN = "swipeLeftInLearn",
|
||||||
|
SWIPE_RIGHT_IN_LEARN = "swipeRightInLearn",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NavBarConfigItem {
|
export interface NavBarConfigItem {
|
||||||
|
|
Loading…
Reference in a new issue