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
This commit is contained in:
parent
71524a155e
commit
185238a18f
10 changed files with 88 additions and 54 deletions
16
src/App.vue
16
src/App.vue
|
@ -10,7 +10,11 @@
|
||||||
:decks="decks"
|
:decks="decks"
|
||||||
:numberOfSelectedDecks="numberOfSelectedDecks"
|
:numberOfSelectedDecks="numberOfSelectedDecks"
|
||||||
></NavigationBar>
|
></NavigationBar>
|
||||||
<router-view :decks="decks" :numberOfSelectedDecks="numberOfSelectedDecks" />
|
<router-view
|
||||||
|
:decks="decks"
|
||||||
|
:numberOfSelectedDecks="numberOfSelectedDecks"
|
||||||
|
:maxCardCount="maxCardCount"
|
||||||
|
/>
|
||||||
<v-snackbar app v-model="snackbar.snackbar" :timeout="snackbar.timeout">
|
<v-snackbar app v-model="snackbar.snackbar" :timeout="snackbar.timeout">
|
||||||
{{ snackbar.text }}
|
{{ snackbar.text }}
|
||||||
<template v-slot:action="{ attrs }">
|
<template v-slot:action="{ attrs }">
|
||||||
|
@ -60,8 +64,10 @@ const AppProps = Vue.extend({
|
||||||
})
|
})
|
||||||
export default class App extends AppProps {
|
export default class App extends AppProps {
|
||||||
propertiesToSyncWithLocalStorage = [
|
propertiesToSyncWithLocalStorage = [
|
||||||
{ key: "decks", defaultValue: [] }
|
{ key: "decks", defaultValue: [] },
|
||||||
|
{ key: "maxCardCount", defaultValue: "" }
|
||||||
] as SyncItem[];
|
] as SyncItem[];
|
||||||
|
maxCardCount = "";
|
||||||
decks = [] as Deck[];
|
decks = [] as Deck[];
|
||||||
snackbar = {
|
snackbar = {
|
||||||
text: "",
|
text: "",
|
||||||
|
@ -96,7 +102,11 @@ export default class App extends AppProps {
|
||||||
mounted() {
|
mounted() {
|
||||||
readFromLocalStorage(this);
|
readFromLocalStorage(this);
|
||||||
this.setSelectedStatusForAllDecks(false);
|
this.setSelectedStatusForAllDecks(false);
|
||||||
continueCurrentLearningSessionIfPresent(this.$eventHub, this.$router, this.decks);
|
continueCurrentLearningSessionIfPresent(
|
||||||
|
this.$eventHub,
|
||||||
|
this.$router,
|
||||||
|
this.decks
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get numberOfSelectedDecks() {
|
get numberOfSelectedDecks() {
|
||||||
|
|
|
@ -46,12 +46,12 @@ import {
|
||||||
saveLearningSessionManagerDataToLocalStorage,
|
saveLearningSessionManagerDataToLocalStorage,
|
||||||
getLearningSessionManagerDataFromLocalStorage
|
getLearningSessionManagerDataFromLocalStorage
|
||||||
} from "../../helpers/learningSessionStorageHelper";
|
} from "../../helpers/learningSessionStorageHelper";
|
||||||
import { getMaxCardCount } from "../../helpers/maxCardCountLocalStorageHelper";
|
|
||||||
|
|
||||||
const LearnProps = Vue.extend({
|
const LearnProps = Vue.extend({
|
||||||
props: {
|
props: {
|
||||||
decks: { type: Array as () => Deck[] },
|
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 {
|
export default class Learn extends LearnProps {
|
||||||
numberOfStarsInRating = 5;
|
numberOfStarsInRating = 5;
|
||||||
maxCardCount = getMaxCardCount();
|
|
||||||
learningSessionManager = new LearningSessionManager([]);
|
learningSessionManager = new LearningSessionManager([]);
|
||||||
isLearningSessionFinishedAndComponentWillBeDestroyedSoon = false;
|
isLearningSessionFinishedAndComponentWillBeDestroyedSoon = false;
|
||||||
curLearningElement = {
|
curLearningElement = {
|
||||||
|
@ -142,10 +141,10 @@ export default class Learn extends LearnProps {
|
||||||
(this.learningSessionManager.learningSession.currentElementIndex ===
|
(this.learningSessionManager.learningSession.currentElementIndex ===
|
||||||
this.learningSessionManager.learningSession.elements.length - 1 &&
|
this.learningSessionManager.learningSession.elements.length - 1 &&
|
||||||
this.learningSessionManager.cardsToSelectFrom.length === 0) ||
|
this.learningSessionManager.cardsToSelectFrom.length === 0) ||
|
||||||
(this.maxCardCount === 0
|
(this.maxCardCount === "0"
|
||||||
? false
|
? false
|
||||||
: this.learningSessionManager.learningSession.currentElementIndex ===
|
: this.learningSessionManager.learningSession.currentElementIndex ===
|
||||||
this.maxCardCount - 1);
|
parseInt(this.maxCardCount) - 1);
|
||||||
return endOfSession;
|
return endOfSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<v-card-title>Max Card Count</v-card-title>
|
<v-card-title>Max Card Count</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<p>
|
<p>
|
||||||
Define the number of cards that will be in each learning session.
|
Limit the number of cards that will be in each learning session.
|
||||||
<v-icon
|
<v-icon
|
||||||
size="1em"
|
size="1em"
|
||||||
@click="showHelpText = !showHelpText"
|
@click="showHelpText = !showHelpText"
|
||||||
|
@ -14,12 +14,12 @@
|
||||||
<p
|
<p
|
||||||
class="description"
|
class="description"
|
||||||
v-show="showHelpText"
|
v-show="showHelpText"
|
||||||
>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).</p>
|
>If the given deck(s) has(have) less cards it will default to the number of cards in the given deck(s).</p>
|
||||||
<v-text-field v-model="maxCardCount" type="number" min="0" label="Maximum Cards" outlined></v-text-field>
|
<v-text-field v-model="curMaxCardCount" type="number" min="1" :label="label" outlined></v-text-field>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions class="button-padding">
|
<v-card-actions class="button-padding">
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<v-btn color="indigo" @click="updateMaxCardCount" right>Update Maximum Cards</v-btn>
|
<v-btn color="red" @click="deactivateMaxCardCount" right>Deactivate Limit</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
|
@ -29,18 +29,36 @@
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
import Component from "vue-class-component";
|
import Component from "vue-class-component";
|
||||||
|
|
||||||
import {
|
import { Event } from '../../types';
|
||||||
getMaxCardCount,
|
|
||||||
setMaxCardCount
|
const MaxCardCountProps = Vue.extend({
|
||||||
} from "../../helpers/maxCardCountLocalStorageHelper";
|
props: {
|
||||||
|
maxCardCount: String
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class MaxCardCount extends Vue {
|
export default class MaxCardCount extends MaxCardCountProps {
|
||||||
|
noLimitString = "Currently no limit";
|
||||||
|
defaultLabel = "Maximum Cards";
|
||||||
showHelpText = false;
|
showHelpText = false;
|
||||||
maxCardCount: number | null = getMaxCardCount();
|
|
||||||
|
|
||||||
updateMaxCardCount() {
|
get label() {
|
||||||
setMaxCardCount(this, this.maxCardCount);
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div>
|
<div>
|
||||||
<v-container fluid>
|
<v-container fluid>
|
||||||
<v-row>
|
<v-row>
|
||||||
<MaxCardCount />
|
<MaxCardCount :maxCardCount="maxCardCount" />
|
||||||
<ClearLocalStorage />
|
<ClearLocalStorage />
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-container>
|
</v-container>
|
||||||
|
@ -16,13 +16,19 @@ import Component from "vue-class-component";
|
||||||
import MaxCardCount from "./MaxCardCountCard.vue";
|
import MaxCardCount from "./MaxCardCountCard.vue";
|
||||||
import ClearLocalStorage from "./ClearLocalStorage.vue";
|
import ClearLocalStorage from "./ClearLocalStorage.vue";
|
||||||
|
|
||||||
|
const SettingProps = Vue.extend({
|
||||||
|
props: {
|
||||||
|
maxCardCount: String
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
MaxCardCount,
|
MaxCardCount,
|
||||||
ClearLocalStorage
|
ClearLocalStorage
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default class Settings extends Vue {}
|
export default class Settings extends SettingProps {}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
import { clearLocalStorage } from "./localStorageHelper";
|
import { clearLocalStorage } from "./localStorageHelper";
|
||||||
import { addDecksFromJSON, addDecksFromFile } from "./addDecksHelper";
|
import { addDecksFromJSON, addDecksFromFile } from "./addDecksHelper";
|
||||||
import { showSnackbar } from "./snackbarHelper";
|
import { showSnackbar } from "./snackbarHelper";
|
||||||
|
import { updateMaxCardCount } from "./updateMaxCardCount";
|
||||||
|
|
||||||
export function registerEventListenerForMainApp(context: any) {
|
export function registerEventListenerForMainApp(context: any) {
|
||||||
context.$eventHub.$on(Event.DELETE_SELECTED_DECKS, () => {
|
context.$eventHub.$on(Event.DELETE_SELECTED_DECKS, () => {
|
||||||
|
@ -22,9 +23,12 @@ export function registerEventListenerForMainApp(context: any) {
|
||||||
context.$eventHub.$on(Event.ADD_DECKS_FROM_FILE, (fileContent: string) => {
|
context.$eventHub.$on(Event.ADD_DECKS_FROM_FILE, (fileContent: string) => {
|
||||||
addDecksFromFile(context, fileContent);
|
addDecksFromFile(context, fileContent);
|
||||||
});
|
});
|
||||||
context.$eventHub.$on(Event.ADD_DECKS_FROM_JSON, (fileContent: FFCFile, url?: string) => {
|
context.$eventHub.$on(
|
||||||
addDecksFromJSON(context, fileContent, url);
|
Event.ADD_DECKS_FROM_JSON,
|
||||||
});
|
(fileContent: FFCFile, url?: string) => {
|
||||||
|
addDecksFromJSON(context, fileContent, url);
|
||||||
|
}
|
||||||
|
);
|
||||||
context.$eventHub.$on(Event.SNACKBAR_EVENT, (message: string) => {
|
context.$eventHub.$on(Event.SNACKBAR_EVENT, (message: string) => {
|
||||||
showSnackbar(context, message);
|
showSnackbar(context, message);
|
||||||
});
|
});
|
||||||
|
@ -43,4 +47,7 @@ export function registerEventListenerForMainApp(context: any) {
|
||||||
}
|
}
|
||||||
context.$router.replace("/");
|
context.$router.replace("/");
|
||||||
});
|
});
|
||||||
|
context.$eventHub.$on(Event.UPDATE_MAX_CARD_COUNT, (newValue: string) => {
|
||||||
|
updateMaxCardCount(context, newValue);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
import { get, set } from "./localStorageHelper";
|
|
||||||
import { Event } from "../types";
|
|
||||||
|
|
||||||
export function getMaxCardCount() {
|
|
||||||
const maxCardCount = parseInt(get("maxCardCount"));
|
|
||||||
if (isNaN(maxCardCount)) {
|
|
||||||
const defaultValue = 0;
|
|
||||||
set("maxCardCount", defaultValue.toString());
|
|
||||||
|
|
||||||
return defaultValue;
|
|
||||||
} else {
|
|
||||||
return maxCardCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setMaxCardCount(context: any, maxCardCount: number) {
|
|
||||||
try {
|
|
||||||
set("maxCardCount", maxCardCount.toString());
|
|
||||||
context.$eventHub.$emit(
|
|
||||||
Event.SNACKBAR_EVENT,
|
|
||||||
"Successfully updated max card count to " + maxCardCount + "."
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
context.$eventHub.$emit(Event.SNACKBAR_EVENT, e);
|
|
||||||
}
|
|
||||||
}
|
|
11
src/helpers/updateMaxCardCount.ts
Normal file
11
src/helpers/updateMaxCardCount.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { showSnackbar } from "./snackbarHelper";
|
||||||
|
|
||||||
|
export function updateMaxCardCount(context: any, newValue: string) {
|
||||||
|
context.maxCardCount = newValue;
|
||||||
|
newValue !== "0"
|
||||||
|
? showSnackbar(
|
||||||
|
context,
|
||||||
|
"Successfully updated max card count to " + newValue + "."
|
||||||
|
)
|
||||||
|
: showSnackbar(context, "Successfully deactivated max card count.");
|
||||||
|
}
|
|
@ -117,6 +117,7 @@ export enum Event {
|
||||||
DESELECT_ALL_DECKS = "deselectAllDecks",
|
DESELECT_ALL_DECKS = "deselectAllDecks",
|
||||||
SWIPE_LEFT_IN_LEARN = "swipeLeftInLearn",
|
SWIPE_LEFT_IN_LEARN = "swipeLeftInLearn",
|
||||||
SWIPE_RIGHT_IN_LEARN = "swipeRightInLearn",
|
SWIPE_RIGHT_IN_LEARN = "swipeRightInLearn",
|
||||||
|
UPDATE_MAX_CARD_COUNT = "updateMaxCardCount",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NavBarConfigItem {
|
export interface NavBarConfigItem {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
:decks="decks"
|
:decks="decks"
|
||||||
:numberOfSelectedDecks="numberOfSelectedDecks"
|
:numberOfSelectedDecks="numberOfSelectedDecks"
|
||||||
:learningSession="learningSession"
|
:learningSession="learningSession"
|
||||||
|
:maxCardCount="maxCardCount"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -20,7 +21,8 @@ const LearnProps = Vue.extend({
|
||||||
props: {
|
props: {
|
||||||
decks: { type: Array as () => Deck[] },
|
decks: { type: Array as () => Deck[] },
|
||||||
learningSession: { type: Object as () => LearningSession },
|
learningSession: { type: Object as () => LearningSession },
|
||||||
numberOfSelectedDecks: Number
|
numberOfSelectedDecks: Number,
|
||||||
|
maxCardCount: String
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="settings">
|
<div class="settings">
|
||||||
<SettingsComponent />
|
<SettingsComponent :maxCardCount="maxCardCount" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -10,12 +10,18 @@ import Component from "vue-class-component";
|
||||||
|
|
||||||
import SettingsComponent from "../components/settings/Settings.vue";
|
import SettingsComponent from "../components/settings/Settings.vue";
|
||||||
|
|
||||||
|
const SettingProps = Vue.extend({
|
||||||
|
props: {
|
||||||
|
maxCardCount: String
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
SettingsComponent
|
SettingsComponent
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default class Settings extends Vue {}
|
export default class Settings extends SettingProps {}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
Loading…
Reference in a new issue