new stats + use store + refactoring

This commit is contained in:
RemiSaurel
2022-08-26 01:17:35 +02:00
parent 398c261624
commit 0ed5f2e7eb
5 changed files with 67 additions and 24 deletions
+48 -11
View File
@@ -9,7 +9,7 @@
</div> </div>
</div> </div>
<hr> <hr>
<div id="word-definition"> <div id="word-definition" v-if="displayWord">
<div id="word"> <div id="word">
{{ this.word.word }} {{ this.word.word }}
</div> </div>
@@ -17,10 +17,28 @@
{{ this.word.definition }} {{ this.word.definition }}
</div> </div>
<div id="btn"> <div id="btn">
<button @click="getNewWordEveryday" id="fetch"> <button @click="getNewWordEveryday" id="fetch" class="btn">
Générer un mot Générer un mot
</button> </button>
</div> </div>
<hr>
</div>
<div id="stats">
<div class="center" v-if="displayWord">
<button @click="displayWord = false" class="btn">
Voir les stats
</button>
</div>
<div v-else>
Total todo: {{this.nbItemsFinished}}
<br>
Total sessions: {{this.$store.getters.nbSessions}}
<div class="center">
<button class="btn" id="see-words" @click="displayWord = true">
Revoir les mots
</button>
</div>
</div>
</div> </div>
</div> </div>
</template> </template>
@@ -37,6 +55,7 @@ export default {
word: "", word: "",
definition: "", definition: "",
}, },
displayWord: true,
} }
}, },
methods: { methods: {
@@ -79,7 +98,6 @@ export default {
}) })
}, },
getDefinition(word) { getDefinition(word) {
console.log(this.$store.getters.itemsFinished)
const url = 'https://api.dictionaryapi.dev/api/v2/entries/en/' + word; const url = 'https://api.dictionaryapi.dev/api/v2/entries/en/' + word;
return fetch(url) return fetch(url)
.then(response => response.json()) .then(response => response.json())
@@ -101,22 +119,24 @@ export default {
mounted() { mounted() {
this.generateDateOfTheDay(); this.generateDateOfTheDay();
this.getCurrentTime(); this.getCurrentTime();
this.getNewWordEveryday() this.getNewWordEveryday();
}, },
computed: { computed: {
itemsFinished() { itemsFinished() {
return this.$store.getters.itemsFinished; return this.$store.getters.itemsFinished;
}, },
nbItemsFinished() {
return this.$store.getters.itemsFinished.length;
},
colorSelected() { colorSelected() {
return this.$store.getters.colorSelected; return this.$store.getters.colorSelected;
} }
}, },
watch: { watch: {
itemsFinished: function(items) {
console.log(items);
},
colorSelected: function(color) { colorSelected: function(color) {
document.getElementById("word").style.color = color; if (this.displayWord) {
document.getElementById("word").style.color = color;
}
} }
} }
} }
@@ -128,10 +148,10 @@ export default {
position: relative; position: relative;
background: #504746; background: #504746;
width: 100%; width: 100%;
height: 300px;
border-radius: 16px; border-radius: 16px;
padding: 16px 24px 18px 24px; padding: 16px 24px 18px 24px;
color: white; color: white;
max-height: 320px;
overflow: auto; overflow: auto;
box-shadow: rgba(0, 0, 0) 0px 4px 10px; box-shadow: rgba(0, 0, 0) 0px 4px 10px;
} }
@@ -151,7 +171,7 @@ export default {
font-size: 24px; font-size: 24px;
font-weight: bold; font-weight: bold;
margin-bottom: 8px; margin-bottom: 8px;
color: #b4c2ff; color: #fdde95;
} }
#definition { #definition {
@@ -164,11 +184,28 @@ export default {
margin-top: 24px; margin-top: 24px;
} }
#btn > button { .btn {
font-size: 20px; font-size: 20px;
padding: 8px; padding: 8px;
} }
#fetch {
margin-bottom: 8px;
}
#stats {
font-size: 28px;
margin-top: 16px;
}
.center {
text-align: center;
}
#see-words {
margin-top: 16px;
}
@media (max-width: 835px) { @media (max-width: 835px) {
#container-infos { #container-infos {
display: none; display: none;
+1 -2
View File
@@ -128,7 +128,6 @@ export default {
}, },
countDownTimer: function () { countDownTimer: function () {
if (this.minutes === "00" && this.seconds === "00") { if (this.minutes === "00" && this.seconds === "00") {
console.log("ici")
if (this.isRestingTime) { if (this.isRestingTime) {
this.isRestingTime = false; this.isRestingTime = false;
this.resetSession(); this.resetSession();
@@ -136,6 +135,7 @@ export default {
} else { } else {
alert("SESSION TERMINÉE 👏"); alert("SESSION TERMINÉE 👏");
this.nbSessionsFinished++; this.nbSessionsFinished++;
this.$store.commit("setNbSessions");
if (this.nbSessionsFinished === 4) { if (this.nbSessionsFinished === 4) {
this.setupPauseTimer(LONG_PAUSE); this.setupPauseTimer(LONG_PAUSE);
this.nbSessionsFinished = 0; this.nbSessionsFinished = 0;
@@ -221,7 +221,6 @@ export default {
padding-bottom: 16px; padding-bottom: 16px;
margin-right: 16px; margin-right: 16px;
min-height: 260px; min-height: 260px;
max-height: 380px;
box-shadow: rgba(0, 0, 0) 0px 4px 10px; box-shadow: rgba(0, 0, 0) 0px 4px 10px;
} }
+2 -1
View File
@@ -9,12 +9,13 @@
</template> </template>
<script> <script>
const DEFAULT_COLOR = "#fdde95";
export default { export default {
name: "Settings", name: "Settings",
data() { data() {
return { return {
colors: { colors: {
default: "#fdde95", default: DEFAULT_COLOR,
greenBlue: "#9acabf", greenBlue: "#9acabf",
green: "#ABCEA7", green: "#ABCEA7",
grey: "#d4d4e8", grey: "#d4d4e8",
+7 -8
View File
@@ -35,10 +35,8 @@ export default {
const trimmedItem = item.trim(); const trimmedItem = item.trim();
if (trimmedItem.length > 0 && this.items.indexOf(trimmedItem) === -1) { if (trimmedItem.length > 0 && this.items.indexOf(trimmedItem) === -1) {
this.items = [trimmedItem].concat(this.items) this.items = [trimmedItem].concat(this.items)
this.clearItem()
} else {
this.clearItem()
} }
this.clearItem()
}, },
removeItem(item) { removeItem(item) {
this.items = this.items.filter(e => this.items = this.items.filter(e =>
@@ -59,15 +57,12 @@ export default {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
max-height: 825px; max-height: 825px;
overflow: auto;
height: 100%; height: 100%;
} }
#todolist { #todolist {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-left: 16px;
width: 100%; width: 100%;
} }
@@ -96,6 +91,7 @@ export default {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding-left: 16px;
} }
#add_button { #add_button {
@@ -133,6 +129,9 @@ export default {
flex-direction: column; flex-direction: column;
padding-right: 16px; padding-right: 16px;
margin-top: 8px; margin-top: 8px;
overflow: auto;
padding-left: 16px;
padding-bottom: 16px;
} }
.item { .item {
@@ -163,8 +162,8 @@ export default {
margin-top: 8px; margin-top: 8px;
} }
#todolist { #todolist {
margin-right: 32px; padding-right: 32px;
padding-left: 16px; padding-left: 32px;
} }
#liste { #liste {
padding-bottom: 8px; padding-bottom: 8px;
+9 -2
View File
@@ -1,14 +1,15 @@
// store/index.js // store/index.js
import Vue from "vue"; import Vue from "vue";
import Vuex from "vuex"; import Vuex from "vuex";
Vue.use(Vuex); Vue.use(Vuex);
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {
itemsFinished: [], itemsFinished: [],
colorSelected: "" colorSelected: "",
nbSessions: 0
}, },
getters: { getters: {
itemsFinished(state) { itemsFinished(state) {
@@ -16,6 +17,9 @@ export default new Vuex.Store({
}, },
colorSelected(state) { colorSelected(state) {
return state.colorSelected; return state.colorSelected;
},
nbSessions(state) {
return state.nbSessions;
} }
}, },
mutations: { mutations: {
@@ -24,6 +28,9 @@ export default new Vuex.Store({
}, },
setColorSelected(state, color) { setColorSelected(state, color) {
state.colorSelected = color; state.colorSelected = color;
},
setNbSessions(state) {
state.nbSessions++;
} }
}, },
actions: { actions: {