feat(frontend): add sync in settings

This commit is contained in:
DCsunset 2020-10-29 20:57:21 +08:00
parent 066c92946f
commit 98b4e8be81
6 changed files with 80 additions and 9 deletions

View file

@ -51,13 +51,14 @@ export default defineComponent({
setup(_props, context) {
context.root.$store.dispatch('fetchTasks');
let interval: NodeJS.Timeout | null = null;
// Auto Refresh
let refreshInterval: NodeJS.Timeout | null = null;
const setAutoRefresh = () => {
if (interval)
clearInterval(interval);
if (refreshInterval)
clearInterval(refreshInterval);
const freq = +context.root.$store.state.settings.autoRefresh;
if (freq > 0) {
interval = setInterval(() => {
refreshInterval = setInterval(() => {
context.root.$store.dispatch('fetchTasks');
}, +context.root.$store.state.settings.autoRefresh * 60000);
}
@ -65,6 +66,21 @@ export default defineComponent({
setAutoRefresh();
watch(() => context.root.$store.state.settings, setAutoRefresh);
// Auto Sync
let syncInterval: NodeJS.Timeout | null = null;
const setAutoSync = () => {
if (syncInterval)
clearInterval(syncInterval);
const freq = +context.root.$store.state.settings.autoSync;
if (freq > 0) {
syncInterval = setInterval(() => {
context.root.$store.dispatch('syncTasks');
}, +context.root.$store.state.settings.autoSync * 60000);
}
};
setAutoSync();
watch(() => context.root.$store.state.settings, setAutoSync);
const mode = ref('Tasks');
const allModes = ['Tasks', 'Projects'];