From 185238a18fa0ce856d3c1da48a457d5f2af15f8d Mon Sep 17 00:00:00 2001
From: Rene Fischer
Date: Sat, 22 Aug 2020 22:25:35 +0200
Subject: [PATCH] rework maxCardCount
maxCardCount is now a global variable
it can be updated simply by changing the number
it can also be disabled via a button
---
src/App.vue | 16 +++++--
src/components/learn/Learn.vue | 9 ++--
src/components/settings/MaxCardCountCard.vue | 42 +++++++++++++------
src/components/settings/Settings.vue | 10 ++++-
src/helpers/eventListener.ts | 13 ++++--
src/helpers/maxCardCountLocalStorageHelper.ts | 26 ------------
src/helpers/updateMaxCardCount.ts | 11 +++++
src/types/index.ts | 1 +
src/views/Learn.vue | 4 +-
src/views/Settings.vue | 10 ++++-
10 files changed, 88 insertions(+), 54 deletions(-)
delete mode 100644 src/helpers/maxCardCountLocalStorageHelper.ts
create mode 100644 src/helpers/updateMaxCardCount.ts
diff --git a/src/App.vue b/src/App.vue
index 0e22d19..7d21b89 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -10,7 +10,11 @@
:decks="decks"
:numberOfSelectedDecks="numberOfSelectedDecks"
>
-
+
{{ snackbar.text }}
@@ -60,8 +64,10 @@ const AppProps = Vue.extend({
})
export default class App extends AppProps {
propertiesToSyncWithLocalStorage = [
- { key: "decks", defaultValue: [] }
+ { key: "decks", defaultValue: [] },
+ { key: "maxCardCount", defaultValue: "" }
] as SyncItem[];
+ maxCardCount = "";
decks = [] as Deck[];
snackbar = {
text: "",
@@ -96,7 +102,11 @@ export default class App extends AppProps {
mounted() {
readFromLocalStorage(this);
this.setSelectedStatusForAllDecks(false);
- continueCurrentLearningSessionIfPresent(this.$eventHub, this.$router, this.decks);
+ continueCurrentLearningSessionIfPresent(
+ this.$eventHub,
+ this.$router,
+ this.decks
+ );
}
get numberOfSelectedDecks() {
diff --git a/src/components/learn/Learn.vue b/src/components/learn/Learn.vue
index da6a9b3..a5d94eb 100644
--- a/src/components/learn/Learn.vue
+++ b/src/components/learn/Learn.vue
@@ -46,12 +46,12 @@ import {
saveLearningSessionManagerDataToLocalStorage,
getLearningSessionManagerDataFromLocalStorage
} from "../../helpers/learningSessionStorageHelper";
-import { getMaxCardCount } from "../../helpers/maxCardCountLocalStorageHelper";
const LearnProps = Vue.extend({
props: {
decks: { type: Array as () => Deck[] },
- numberOfSelectedDecks: Number
+ numberOfSelectedDecks: Number,
+ maxCardCount: String
}
});
@@ -62,7 +62,6 @@ const LearnProps = Vue.extend({
})
export default class Learn extends LearnProps {
numberOfStarsInRating = 5;
- maxCardCount = getMaxCardCount();
learningSessionManager = new LearningSessionManager([]);
isLearningSessionFinishedAndComponentWillBeDestroyedSoon = false;
curLearningElement = {
@@ -142,10 +141,10 @@ export default class Learn extends LearnProps {
(this.learningSessionManager.learningSession.currentElementIndex ===
this.learningSessionManager.learningSession.elements.length - 1 &&
this.learningSessionManager.cardsToSelectFrom.length === 0) ||
- (this.maxCardCount === 0
+ (this.maxCardCount === "0"
? false
: this.learningSessionManager.learningSession.currentElementIndex ===
- this.maxCardCount - 1);
+ parseInt(this.maxCardCount) - 1);
return endOfSession;
}
diff --git a/src/components/settings/MaxCardCountCard.vue b/src/components/settings/MaxCardCountCard.vue
index f2e04c3..f0bd7eb 100644
--- a/src/components/settings/MaxCardCountCard.vue
+++ b/src/components/settings/MaxCardCountCard.vue
@@ -4,7 +4,7 @@
Max Card Count
- Define the number of cards that will be in each learning session.
+ Limit the number of cards that will be in each learning session.
If the given deck(s) has(have) less cards it will default to the number of cards in the given deck(s). The value "0" stands for every card in the given deck(s).
-
+ >If the given deck(s) has(have) less cards it will default to the number of cards in the given deck(s).
+
- Update Maximum Cards
+ Deactivate Limit
@@ -29,18 +29,36 @@
import Vue from "vue";
import Component from "vue-class-component";
-import {
- getMaxCardCount,
- setMaxCardCount
-} from "../../helpers/maxCardCountLocalStorageHelper";
+import { Event } from '../../types';
+
+const MaxCardCountProps = Vue.extend({
+ props: {
+ maxCardCount: String
+ }
+});
@Component
-export default class MaxCardCount extends Vue {
+export default class MaxCardCount extends MaxCardCountProps {
+ noLimitString = "Currently no limit";
+ defaultLabel = "Maximum Cards";
showHelpText = false;
- maxCardCount: number | null = getMaxCardCount();
- updateMaxCardCount() {
- setMaxCardCount(this, this.maxCardCount);
+ get label() {
+ return this.maxCardCount === "0" || null
+ ? this.noLimitString
+ : this.defaultLabel;
+ }
+
+ get curMaxCardCount() {
+ return this.maxCardCount === "0" || null ? null : this.maxCardCount;
+ }
+
+ set curMaxCardCount(newValue) {
+ this.$eventHub.$emit(Event.UPDATE_MAX_CARD_COUNT, newValue);
+ }
+
+ deactivateMaxCardCount() {
+ this.$eventHub.$emit(Event.UPDATE_MAX_CARD_COUNT, "0");
}
}
diff --git a/src/components/settings/Settings.vue b/src/components/settings/Settings.vue
index d3e3fa8..6b25594 100644
--- a/src/components/settings/Settings.vue
+++ b/src/components/settings/Settings.vue
@@ -2,7 +2,7 @@
-
+
@@ -16,13 +16,19 @@ import Component from "vue-class-component";
import MaxCardCount from "./MaxCardCountCard.vue";
import ClearLocalStorage from "./ClearLocalStorage.vue";
+const SettingProps = Vue.extend({
+ props: {
+ maxCardCount: String
+ }
+});
+
@Component({
components: {
MaxCardCount,
ClearLocalStorage
}
})
-export default class Settings extends Vue {}
+export default class Settings extends SettingProps {}