frequi_origin/src/components/ftbot/ReloadControl.vue

101 lines
2.0 KiB
Vue
Raw Normal View History

<template>
<div>
2020-08-31 18:01:51 +00:00
<button class="btn btn-secondary btn-sm" @click="refreshAll()">Refresh all</button>
2020-08-31 18:01:51 +00:00
<b-form-checkbox v-model="autoRefreshLoc" class="float-right" size="sm" switch
>AutoRefresh</b-form-checkbox
>
</div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
2020-07-19 13:35:10 +00:00
import { Action, State } from 'vuex-class';
@Component({})
export default class ReloadControl extends Vue {
2020-09-07 18:44:57 +00:00
refreshInterval: number | null = null;
2020-09-07 18:44:57 +00:00
refreshIntervalSlow: number | null = null;
created() {
2020-07-19 13:35:10 +00:00
if (this.loggedIn) {
this.refreshOnce();
this.refreshAll();
}
}
mounted() {
this.startRefresh();
}
beforeDestroy() {
this.stopRefresh();
}
2020-07-19 13:35:10 +00:00
@State loggedIn;
2020-07-23 17:58:25 +00:00
@State autoRefresh!: boolean;
2020-09-08 13:45:01 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2020-07-23 17:58:25 +00:00
@Action setAutoRefresh!: (newValue: boolean) => void;
@Action refreshSlow;
@Action refreshFrequent;
@Action refreshAll;
@Action refreshOnce;
2020-07-23 17:58:25 +00:00
get autoRefreshLoc() {
return this.autoRefresh;
}
set autoRefreshLoc(newValue: boolean) {
this.setAutoRefresh(newValue);
}
startRefresh() {
2020-07-19 13:35:10 +00:00
if (this.loggedIn !== true) {
console.log('Not logged in.');
return;
}
console.log('Starting automatic refresh.');
this.refreshFrequent();
if (this.autoRefresh) {
2020-09-07 18:44:57 +00:00
this.refreshInterval = window.setInterval(() => {
this.refreshFrequent();
}, 5000);
}
this.refreshSlow();
if (this.autoRefresh) {
2020-09-07 18:44:57 +00:00
this.refreshIntervalSlow = window.setInterval(() => {
this.refreshSlow();
}, 60000);
}
}
stopRefresh() {
console.log('Stopping automatic refresh.');
if (this.refreshInterval) {
2020-09-07 18:44:57 +00:00
window.clearInterval(this.refreshInterval);
}
if (this.refreshIntervalSlow) {
2020-09-07 18:44:57 +00:00
window.clearInterval(this.refreshIntervalSlow);
}
}
@Watch('autoRefresh')
watchAutoRefresh(val) {
if (val) {
this.startRefresh();
} else {
this.stopRefresh();
}
}
}
</script>
<style scoped></style>