Merge pull request #10 from RemiSaurel/dev

Storage, refactor
This commit is contained in:
Rémi
2022-08-29 14:44:47 +02:00
committed by GitHub
7 changed files with 96 additions and 32 deletions
+3 -1
View File
@@ -103,12 +103,14 @@ button:disabled {
/* ********** */ /* ********** */
@media (max-width: 835px) { @media (max-width: 835px) {
#container{ #container {
flex-direction: column; flex-direction: column;
} }
#todo-container { #todo-container {
width: 100%; width: 100%;
} }
#right-side { #right-side {
margin-right: 32px; margin-right: 32px;
margin-left: 32px; margin-left: 32px;
+29 -9
View File
@@ -18,7 +18,7 @@
</div> </div>
<div id="btn-newword"> <div id="btn-newword">
<button @click="getNewWordEveryday" id="fetch" class="btn"> <button @click="getNewWordEveryday" id="fetch" class="btn">
Generate a word 📝 Generate a word
</button> </button>
</div> </div>
<hr> <hr>
@@ -26,16 +26,22 @@
<div id="stats"> <div id="stats">
<div class="center" v-if="displayWord"> <div class="center" v-if="displayWord">
<button @click="displayWord = false" class="btn"> <button @click="displayWord = false" class="btn">
Session stats 📊 Session stats
</button> </button>
</div> </div>
<div v-else> <div v-else>
Total todo: {{ this.nbItemsFinished }} Total todo: {{ this.nbItemsFinished }}
<br> <br>
Total sessions: {{ this.$store.getters.nbSessions }} Total sessions: {{ this.nbSessions }}
<br>
<span id="hint">(last + current session)</span>
<div class="center"> <div class="center">
<button @click="resetStats" class="btn" id="reset-stats" :disabled="resetDone">
🔁 Reset last session
</button>
<br>
<button class="btn" id="see-words" @click="displayWord = true"> <button class="btn" id="see-words" @click="displayWord = true">
English word 🇬🇧 English word
</button> </button>
</div> </div>
</div> </div>
@@ -56,6 +62,7 @@ export default {
definition: '', definition: '',
}, },
displayWord: true, displayWord: true,
resetDone: false
}; };
}, },
methods: { methods: {
@@ -134,6 +141,10 @@ export default {
console.log(error); console.log(error);
}); });
}, },
resetStats() {
this.resetDone = true;
this.$store.commit('resetStats');
},
}, },
mounted() { mounted() {
this.generateDateOfTheDay(); this.generateDateOfTheDay();
@@ -141,15 +152,15 @@ export default {
this.getNewWordEveryday(); this.getNewWordEveryday();
}, },
computed: { computed: {
itemsFinished() {
return this.$store.getters.itemsFinished;
},
nbItemsFinished() { nbItemsFinished() {
return this.$store.getters.itemsFinished.length; return parseInt(this.$store.getters.globalState.nbItemsFinished) + this.$store.getters.itemsFinished.length
}, },
colorSelected() { colorSelected() {
return this.$store.getters.colorSelected; return this.$store.getters.colorSelected;
}, },
nbSessions() {
return parseInt(this.$store.getters.globalState.nbSessions) + this.$store.getters.nbSessions
}
}, },
watch: { watch: {
colorSelected: function(color) { colorSelected: function(color) {
@@ -216,10 +227,19 @@ export default {
text-align: center; text-align: center;
} }
#see-words { #hint {
font-size: 18px;
font-weight: lighter;
}
#reset-stats {
margin-top: 16px; margin-top: 16px;
} }
#see-words {
margin-top: 8px;
}
/* ********** */ /* ********** */
/* RESPONSIVE */ /* RESPONSIVE */
/* ********** */ /* ********** */
+18 -8
View File
@@ -18,11 +18,11 @@
<div id="time"> <div id="time">
<div id="minutes"> <div id="minutes">
<div><i @click="this.addMinutes" class="arrow up"></i></div> <div><i @click="this.addMinutes" class="arrow up"></i></div>
<span>{{minutes}}</span> <span>{{ minutes }}</span>
<div><i @click="this.substractMinutes" class="arrow down"></i></div> <div><i @click="this.substractMinutes" class="arrow down"></i></div>
</div> </div>
<span id="colon">:</span> <span id="colon">:</span>
<span id="seconds">{{seconds}}</span> <span id="seconds">{{ seconds }}</span>
</div> </div>
<div id="params"> <div id="params">
<div id="startStop"> <div id="startStop">
@@ -38,6 +38,7 @@
<script> <script>
import Stats from "@/components/Infos"; import Stats from "@/components/Infos";
const MINUTES = 25; const MINUTES = 25;
const RANGE_MINUTES = 5; const RANGE_MINUTES = 5;
const SECONDS = 0; const SECONDS = 0;
@@ -47,7 +48,7 @@ const LONG_PAUSE = 30;
export default { export default {
name: "Pomodoro", name: "Pomodoro",
components: {Stats}, components: {Stats},
data () { data() {
return { return {
minutes: MINUTES, minutes: MINUTES,
seconds: SECONDS, seconds: SECONDS,
@@ -99,7 +100,9 @@ export default {
} }
this.disableButton("start"); this.disableButton("start");
let all = document.querySelectorAll("#presetTime button"); let all = document.querySelectorAll("#presetTime button");
for (let el of all) { el.disabled = true; } for (let el of all) {
el.disabled = true;
}
}, },
pauseSession() { pauseSession() {
this.sessionStarted = false; this.sessionStarted = false;
@@ -122,7 +125,9 @@ export default {
this.prettyTime(); this.prettyTime();
clearTimeout(this.timeout); clearTimeout(this.timeout);
let all = document.querySelectorAll("#presetTime button, #start"); let all = document.querySelectorAll("#presetTime button, #start");
for (let el of all) { el.disabled = false; } for (let el of all) {
el.disabled = false;
}
this.disableButton("pause") this.disableButton("pause")
this.unlockArrows() this.unlockArrows()
}, },
@@ -136,6 +141,7 @@ export default {
alert("SESSION TERMINÉE 👏"); alert("SESSION TERMINÉE 👏");
this.nbSessionsFinished++; this.nbSessionsFinished++;
this.$store.commit("updateNbSessionsFinished"); this.$store.commit("updateNbSessionsFinished");
localStorage.setItem("nbSessions", this.$store.getters.nbSessions);
if (this.nbSessionsFinished === 4) { if (this.nbSessionsFinished === 4) {
this.setupPauseTimer(LONG_PAUSE); this.setupPauseTimer(LONG_PAUSE);
this.nbSessionsFinished = 0; this.nbSessionsFinished = 0;
@@ -181,7 +187,7 @@ export default {
dots[i].classList.add("active"); dots[i].classList.add("active");
} }
}, },
setupPauseTimer(minutes){ setupPauseTimer(minutes) {
this.isRestingTime = true; this.isRestingTime = true;
this.sessionStarted = false; this.sessionStarted = false;
this.enableButton("start"); this.enableButton("start");
@@ -191,7 +197,7 @@ export default {
this.seconds = 0; this.seconds = 0;
this.prettyTime(); this.prettyTime();
}, },
prettyTime () { prettyTime() {
if (this.minutes < 10) { if (this.minutes < 10) {
this.minutes = "0" + this.minutes; this.minutes = "0" + this.minutes;
} }
@@ -240,7 +246,7 @@ export default {
margin-bottom: 16px; margin-bottom: 16px;
} }
#startStop > button{ #startStop > button {
font-size: 32px; font-size: 32px;
text-align: center; text-align: center;
} }
@@ -326,6 +332,7 @@ export default {
margin: 12px 4px 12px 4px; margin: 12px 4px 12px 4px;
display: inline-block; display: inline-block;
} }
/* ********** */ /* ********** */
/* RESPONSIVE */ /* RESPONSIVE */
/* ********** */ /* ********** */
@@ -334,9 +341,11 @@ export default {
#container { #container {
margin-top: 16px; margin-top: 16px;
} }
#message { #message {
font-size: 1.6rem; font-size: 1.6rem;
} }
.pomodoro { .pomodoro {
margin-right: 8px; margin-right: 8px;
width: 50%; width: 50%;
@@ -347,6 +356,7 @@ export default {
#time { #time {
font-size: 38px; font-size: 38px;
} }
#colon { #colon {
margin-right: 8px; margin-right: 8px;
margin-left: 8px; margin-left: 8px;
+12 -9
View File
@@ -1,11 +1,12 @@
<template> <template>
<div id="settings-container"> <div id="settings-container">
<div id="color-palette" class="bubble-container"> <div id="color-palette" class="bubble-container">
<div v-for="color in colors" :key="color.id"> <div v-for="color in colors" :key="color.id">
<div class="bubble-item" :style="{backgroundColor: color, borderColor: activeColor}" @click="setBackgroundColor($event, color)"></div> <div class="bubble-item" :id="color" :style="{backgroundColor: color, borderColor: activeColor}"
@click="setBackgroundColor($event, color)"></div>
</div>
</div> </div>
</div> </div>
</div>
</template> </template>
<script> <script>
@@ -25,11 +26,12 @@ export default {
} }
}, },
methods: { methods: {
setBackgroundColor(event,color) { setBackgroundColor(event, color) {
this.removeActiveColorFromPalette() this.removeActiveColorFromPalette()
event.target.style.borderColor = this.activeColor; event.target.style.borderColor = this.activeColor;
document.body.style.backgroundColor = color; document.body.style.backgroundColor = color;
this.$store.commit("setColorSelected", color); this.$store.commit("setColorSelected", color);
localStorage.setItem("themeColor", this.$store.getters.colorSelected)
}, },
removeActiveColorFromPalette() { removeActiveColorFromPalette() {
const palette = document.querySelectorAll(".bubble-item"); const palette = document.querySelectorAll(".bubble-item");
@@ -38,9 +40,9 @@ export default {
} }
}, },
setFirstColor() { setFirstColor() {
// get first div of color-palette const color = this.$store.getters.globalState.themeColor;
const palette = document.querySelectorAll(".bubble-item"); document.getElementById(color).style.borderColor = this.activeColor;
palette[0].style.borderColor = this.activeColor; document.body.style.backgroundColor = color;
} }
}, },
mounted() { mounted() {
@@ -79,6 +81,7 @@ export default {
justify-content: center; justify-content: center;
margin-top: 8px; margin-top: 8px;
} }
.bubble-item { .bubble-item {
margin-top: 0; margin-top: 0;
margin-right: 4px; margin-right: 4px;
+10 -2
View File
@@ -9,7 +9,7 @@
<div id="liste" ref="todoList"> <div id="liste" ref="todoList">
<div v-for="item in items" :key="item.text" class="item" :id=item :class="item.isPinned? 'pinned' : ''"> <div v-for="item in items" :key="item.text" class="item" :id=item :class="item.isPinned? 'pinned' : ''">
<div class="text"> <div class="text">
{{item.text}} {{ item.text }}
</div> </div>
<div id="emojis"> <div id="emojis">
<div @click="pinItem(item)" id="pin"> <div @click="pinItem(item)" id="pin">
@@ -32,7 +32,7 @@ export default {
data() { data() {
return { return {
item: "", item: "",
items: [] items: JSON.parse(this.$store.getters.globalState.currentItems)
} }
}, },
methods: { methods: {
@@ -47,6 +47,7 @@ export default {
} }
this.sortArrayPinnedElements() this.sortArrayPinnedElements()
this.clearItem() this.clearItem()
this.saveCurrentItems()
}, },
removeItem(item) { removeItem(item) {
this.items = this.items.filter(e => this.items = this.items.filter(e =>
@@ -54,6 +55,8 @@ export default {
) )
this.$store.commit("addItemFinished", item); this.$store.commit("addItemFinished", item);
this.clearItem() this.clearItem()
this.saveCurrentItems()
localStorage.setItem("nbItemsFinished", this.$store.getters.itemsFinished.length);
}, },
clearItem() { clearItem() {
this.item = "" this.item = ""
@@ -69,6 +72,7 @@ export default {
list.scrollTo({top: 0, behavior: 'smooth'}); list.scrollTo({top: 0, behavior: 'smooth'});
} }
this.sortArrayPinnedElements() this.sortArrayPinnedElements()
this.saveCurrentItems()
} }
}, },
sortArrayPinnedElements() { sortArrayPinnedElements() {
@@ -81,6 +85,9 @@ export default {
return 0 return 0
} }
}) })
},
saveCurrentItems() {
localStorage.setItem("currentItems", JSON.stringify(this.items));
} }
} }
} }
@@ -214,6 +221,7 @@ export default {
padding-right: 16px; padding-right: 16px;
padding-left: 16px; padding-left: 16px;
} }
#liste { #liste {
padding-bottom: 8px; padding-bottom: 8px;
padding-left: 16px; padding-left: 16px;
+8 -2
View File
@@ -30,7 +30,7 @@ export default {
livesId: [], livesId: [],
easterEggs: [], easterEggs: [],
easterEggsSongsId: -1, easterEggsSongsId: -1,
songId: 0, songId: this.$store.getters.globalState.currentSongIndex,
muted: true muted: true
} }
}, },
@@ -42,11 +42,13 @@ export default {
}, },
nextPlaylist() { nextPlaylist() {
this.songId++ === this.livesId.length - 1 ? this.songId = 0 : this.songId; this.songId++ === this.livesId.length - 1 ? this.songId = 0 : this.songId;
localStorage.setItem("currentSongIndex", this.songId);
let id = this.livesId[this.songId]; let id = this.livesId[this.songId];
this.loadVideoFromApi(id) this.loadVideoFromApi(id)
}, },
prevPlaylist() { prevPlaylist() {
--this.songId === -1 ? this.songId = this.livesId.length - 1 : this.songId; --this.songId === -1 ? this.songId = this.livesId.length - 1 : this.songId;
localStorage.setItem("currentSongIndex", this.songId);
let id = this.livesId[this.songId]; let id = this.livesId[this.songId];
this.loadVideoFromApi(id) this.loadVideoFromApi(id)
}, },
@@ -73,13 +75,17 @@ export default {
this.muted = !this.muted; this.muted = !this.muted;
}, },
loadVideoFromApi(id) { loadVideoFromApi(id) {
this.saveLocalStorage(id);
player.loadVideoById(id); player.loadVideoById(id);
}, },
saveLocalStorage(id) {
localStorage.setItem("lastSong", id);
},
loadApi() { loadApi() {
window.onYouTubeIframeAPIReady = () => { window.onYouTubeIframeAPIReady = () => {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
player = new window.YT.Player("player", { player = new window.YT.Player("player", {
videoId: "XDh0JcxrbPM", videoId: this.$store.getters.globalState.lastSong,
playerVars: { playerVars: {
'autoplay': 1, 'autoplay': 1,
'mute': 1, 'mute': 1,
+16 -1
View File
@@ -8,7 +8,15 @@ export default new Vuex.Store({
state: { state: {
itemsFinished: [], itemsFinished: [],
colorSelected: "", colorSelected: "",
nbSessions: 0 nbSessions: 0,
globalState: {
currentItems: localStorage.getItem("currentItems") ? localStorage.getItem("currentItems") : JSON.stringify([]),
nbItemsFinished: localStorage.getItem("nbItemsFinished") ? localStorage.getItem("nbItemsFinished") : 0,
nbSessions: localStorage.getItem("nbSessions") ? localStorage.getItem("nbSessions") : 0,
lastSong: localStorage.getItem("lastSong") ? localStorage.getItem("lastSong") : "XDh0JcxrbPM",
currentSongIndex: localStorage.getItem("currentSongIndex") ? localStorage.getItem("currentSongIndex") : 0,
themeColor: localStorage.getItem("themeColor") ? localStorage.getItem("themeColor") : "#fdde95",
}
}, },
getters: { getters: {
itemsFinished(state) { itemsFinished(state) {
@@ -19,6 +27,9 @@ export default new Vuex.Store({
}, },
nbSessions(state) { nbSessions(state) {
return state.nbSessions; return state.nbSessions;
},
globalState(state) {
return state.globalState;
} }
}, },
mutations: { mutations: {
@@ -30,6 +41,10 @@ export default new Vuex.Store({
}, },
updateNbSessionsFinished(state) { updateNbSessionsFinished(state) {
state.nbSessions++; state.nbSessions++;
},
resetStats(state) {
state.globalState.nbItemsFinished = 0;
state.globalState.nbSessions = 0;
} }
}, },
actions: { actions: {