-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1.db utils refactor 2.pomodoro refactor 3.timeline follows cale…
…ndar
- Loading branch information
Showing
19 changed files
with
478 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { createPinia } from 'pinia'; | ||
import { useEditorStore } from './editor'; | ||
import { useSystemStore } from './system'; | ||
import { usePomodoroStore } from './pomodoro'; | ||
const pinia = createPinia(); | ||
export default pinia; | ||
export { useEditorStore, useSystemStore }; | ||
export { useEditorStore, useSystemStore, usePomodoroStore }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,52 @@ | ||
import type { Pomodoro } from '@/schemas/spaces'; | ||
import { DBUtil } from '@/utils/db/db'; | ||
import { defineStore } from 'pinia'; | ||
import { ref } from 'vue'; | ||
import { ref, type Ref } from 'vue'; | ||
|
||
// TODO 将数据持久化,优化性能 注意不同设备之间的持久化策略 | ||
export const usePomodoroStore = defineStore('pomodoro', () => { | ||
const totalTask = ref(0); | ||
function increment() { | ||
totalTask.value++; | ||
const currentPomodoro: Ref<Pomodoro | null> = ref(null); | ||
const pomodoroHistory: Ref<Pomodoro[]> = ref([]); | ||
|
||
function updatePomodoro(pomodoro: Pomodoro) { | ||
DBUtil.updatePomodoro(pomodoro); | ||
const updateIndex = pomodoroHistory.value.findIndex(item => item.timestamp === pomodoro.timestamp); | ||
pomodoroHistory.value[updateIndex] = pomodoro; | ||
if (pomodoro.timestamp === currentPomodoro.value?.timestamp && pomodoro.status === 'done') { | ||
currentPomodoro.value = null; | ||
} else if (pomodoro.status === 'ing') { | ||
currentPomodoro.value = pomodoro; | ||
} | ||
} | ||
|
||
async function loadPomodoroData() { | ||
const data = await DBUtil.loadPomodoroData(); | ||
pomodoroHistory.value = data; | ||
currentPomodoro.value = data.filter(pomodoro => pomodoro.status === 'ing')[0] as Pomodoro; | ||
} | ||
|
||
function addPomodoro(pomodoro: Pomodoro) { | ||
DBUtil.addPomodoro(pomodoro); | ||
pomodoroHistory.value.push(pomodoro); | ||
} | ||
|
||
function deletePomodoro(pomodoro: Pomodoro) { | ||
DBUtil.deletePomodoro(pomodoro); | ||
pomodoroHistory.value = pomodoroHistory.value.filter(item => item.timestamp !== pomodoro.timestamp); | ||
if (currentPomodoro.value && currentPomodoro.value.timestamp === pomodoro.timestamp) { | ||
currentPomodoro.value = null; | ||
} | ||
} | ||
|
||
return { | ||
totalTime: 0, | ||
currentPomodoro, | ||
totalTime: 0, | ||
totalTask, | ||
increment, | ||
pomodoroHistory, | ||
loadPomodoroData, | ||
addPomodoro, | ||
updatePomodoro, | ||
deletePomodoro, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.