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