feat(frontend): add settings and auto refresh

This commit is contained in:
DCsunset 2020-07-15 03:20:39 -07:00
parent e0c6f98cf9
commit 099543c0e1
4 changed files with 181 additions and 4 deletions

View file

@ -35,11 +35,28 @@
<script lang="ts">
import { defineComponent, ref, computed, watch, ComputedRef } from '@vue/composition-api';
import TaskList from '../components/TaskList.vue';
import { Task } from 'taskwarrior-lib';
export default defineComponent({
setup(_props, context) {
context.root.$store.dispatch('fetchTasks');
let interval: NodeJS.Timeout | null = null;
const setAutoRefresh = () => {
console.log('Setting inverval');
if (interval)
clearInterval(interval);
const freq = +context.root.$store.state.settings.autoRefresh;
if (freq > 0) {
interval = setInterval(() => {
console.log('Refreshing...');
context.root.$store.dispatch('fetchTasks');
}, +context.root.$store.state.settings.autoRefresh * 60000);
}
};
setAutoRefresh();
watch(() => context.root.$store.state.settings, setAutoRefresh);
const mode = ref('Tasks');
const allModes = ['Tasks', 'Projects'];
@ -60,7 +77,7 @@ export default defineComponent({
if (project.value)
return context.root.$store.state.tasks.filter(
task => task.project === project.value
(task: Task) => task.project === project.value
);
return [];