Initial commit
This commit is contained in:
78
stores/timer.js
Normal file
78
stores/timer.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useTimerStore = defineStore('timer', {
|
||||
state: () => ({
|
||||
started: false,
|
||||
progressBarWidth: '100%',
|
||||
settings: {
|
||||
timer: {
|
||||
work: {
|
||||
text: 'Focus',
|
||||
time: 25,
|
||||
color: '#72A5ED'
|
||||
},
|
||||
short: {
|
||||
text: 'Short Break',
|
||||
time: 5,
|
||||
color: '#FBA9A9'
|
||||
},
|
||||
long: {
|
||||
text: 'Long Break',
|
||||
time: 15,
|
||||
color: '#D77574'
|
||||
}
|
||||
},
|
||||
autoStart: false,
|
||||
maxSessions: 4 // the number of sessions before a long break
|
||||
},
|
||||
timeRemaining: 25 * 60,
|
||||
currentSession: 'work',
|
||||
currentSessionNumber: 1,
|
||||
showNotification: true,
|
||||
playSessionEndSound: true,
|
||||
alarmAudio: 'bell_focus'
|
||||
}),
|
||||
getters: {
|
||||
isStarted: state => state.started,
|
||||
getTimeRemaining: state => state.timeRemaining,
|
||||
getSessionTime: state => state.settings.timer[state.currentSession].time,
|
||||
getCurrentSession: state => state.currentSession,
|
||||
isWork: state => state.settings.timer[state.currentSession] === 'work',
|
||||
getCurrentSessionNumber: state => state.currentSessionNumber,
|
||||
getMaxSessions: state => state.settings.maxSessions,
|
||||
getCurrentColor: state => state.settings.timer[state.currentSession].color,
|
||||
getProgressBarWidth: state => state.settings.progressBarWidth
|
||||
},
|
||||
actions: {
|
||||
toggleTimer () {
|
||||
this.started = !this.started
|
||||
},
|
||||
clearTimeRemaining () {
|
||||
this.timeRemaining = this.getSessionTime * 60
|
||||
},
|
||||
setTimeRemaining (time) {
|
||||
this.timeRemaining = time
|
||||
},
|
||||
nextSession () {
|
||||
// if current session is not work (i.e. a break)
|
||||
if (this.currentSession !== 'work') {
|
||||
this.currentSessionNumber = this.currentSessionNumber % this.settings.maxSessions + 1
|
||||
this.currentSession = 'work'
|
||||
} else if (this.currentSessionNumber === this.settings.maxSessions) {
|
||||
this.currentSession = 'long'
|
||||
} else {
|
||||
this.currentSession = 'short'
|
||||
}
|
||||
this.timeRemaining = this.settings.timer[this.currentSession].time * 60
|
||||
},
|
||||
setMaxSessions (maxSessionsNumber) {
|
||||
this.settings.maxSessions = maxSessionsNumber
|
||||
},
|
||||
setTimerSettings (workTime, shortBreakTime, longBreakTime) {
|
||||
this.settings.timer.work.time = workTime
|
||||
this.settings.timer.short.time = shortBreakTime
|
||||
this.settings.timer.long.time = longBreakTime
|
||||
this.timeRemaining = workTime * 60
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user