readd global refresh switch

This commit is contained in:
Matthias 2021-09-26 09:15:06 +02:00
parent a95ea597d0
commit e2dc1b9b10
2 changed files with 41 additions and 38 deletions

View File

@ -1,23 +1,27 @@
<template>
<div class="d-flex flex-align-center">
<b-button class="m-1 mr-3" variant="secondary" size="sm" @click="allRefreshFull(true)">
<div class="d-flex flex-align-center ml-2">
<b-form-checkbox
v-model="autoRefreshLoc"
class="ml-auto float-right my-auto"
title="AutoRefresh"
></b-form-checkbox>
<b-button
class="m-1"
variant="secondary"
size="sm"
title="Auto Refresh All bots"
@click="allRefreshFull(true)"
>
<RefreshIcon :size="16" />
</b-button>
<!-- <b-form-checkbox
v-model="autoRefreshLoc"
class="ml-auto float-right mr-2 my-auto"
title="AutoRefresh"
variant="secondary"
>AutoRefresh</b-form-checkbox
> -->
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Getter, namespace } from 'vuex-class';
import { namespace } from 'vuex-class';
import RefreshIcon from 'vue-material-design-icons/Refresh.vue';
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
const ftbot = namespace('ftbot');
@ -27,37 +31,19 @@ export default class ReloadControl extends Vue {
refreshIntervalSlow: number | null = null;
created() {
// if (this.loggedIn) {
// this.refreshOnce();
// this.refreshFull(true);
// }
}
mounted() {
// this.startRefresh(false);
}
beforeDestroy() {
// this.stopRefresh();
}
// TODO-multi: This should be per bot!
@Getter loggedIn;
@ftbot.Getter autoRefresh!: boolean;
@ftbot.Getter [MultiBotStoreGetters.globalAutoRefresh]!: boolean;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action setAutoRefresh!: (newValue: boolean) => void;
@ftbot.Action setGlobalAutoRefresh!: (newValue: boolean) => void;
@ftbot.Action allRefreshFull;
get autoRefreshLoc() {
return this.autoRefresh;
return this.globalAutoRefresh;
}
set autoRefreshLoc(newValue: boolean) {
this.setAutoRefresh(newValue);
this.setGlobalAutoRefresh(newValue);
}
}
</script>

View File

@ -14,6 +14,7 @@ const AUTH_SELECTED_BOT = 'ftSelectedBot';
interface FTMultiBotState {
selectedBot: string;
availableBots: BotDescriptors;
globalAutoRefresh: boolean;
refreshing: boolean;
refreshInterval: number | null;
refreshIntervalSlow: number | null;
@ -25,6 +26,7 @@ export enum MultiBotStoreGetters {
nextBotId = 'nextBotId',
selectedBot = 'selectedBot',
selectedBotObj = 'selectedBotObj',
globalAutoRefresh = 'globalAutoRefresh',
allAvailableBots = 'allAvailableBots',
allAvailableBotsList = 'allAvailableBotsList',
allTradesAllBots = 'allTradesAllBots',
@ -57,6 +59,7 @@ export default function createBotStore(store) {
const state: FTMultiBotState = {
selectedBot: '',
availableBots: {},
globalAutoRefresh: true,
refreshing: false,
refreshInterval: null,
refreshIntervalSlow: null,
@ -84,6 +87,9 @@ export default function createBotStore(store) {
[MultiBotStoreGetters.selectedBotObj](state: FTMultiBotState): BotDescriptor {
return state.availableBots[state.selectedBot];
},
[MultiBotStoreGetters.globalAutoRefresh](state: FTMultiBotState): boolean {
return state.globalAutoRefresh;
},
[MultiBotStoreGetters.allAvailableBots](state: FTMultiBotState): BotDescriptors {
return state.availableBots;
},
@ -166,7 +172,9 @@ export default function createBotStore(store) {
console.warn(`Botid ${botId} not available, but selected.`);
}
},
setGlobalAutoRefresh(state, value: boolean) {
state.globalAutoRefresh = value;
},
setRefreshing(state, refreshing: boolean) {
state.refreshing = refreshing;
},
@ -224,18 +232,27 @@ export default function createBotStore(store) {
localStorage.setItem(AUTH_SELECTED_BOT, botId);
commit('selectBot', botId);
},
setGlobalAutoRefresh({ commit }, value: boolean) {
commit('setGlobalAutoRefresh', value);
},
allRefreshFrequent({ dispatch, getters }, slow: boolean) {
getters.allAvailableBotsList.forEach((e) => {
if (getters[`${e}/${BotStoreGetters.refreshNow}`]) {
if (
getters[`${e}/${BotStoreGetters.refreshNow}`] &&
getters[MultiBotStoreGetters.globalAutoRefresh]
) {
// console.log('refreshing', e);
dispatch(`${e}/${BotStoreActions.refreshFrequent}`, slow);
}
});
},
allRefreshSlow({ dispatch, getters }) {
allRefreshSlow({ dispatch, getters }, forceUpdate = false) {
getters.allAvailableBotsList.forEach((e) => {
if (getters[`${e}/${BotStoreGetters.refreshNow}`]) {
dispatch(`${e}/${BotStoreActions.refreshSlow}`);
if (
getters[`${e}/${BotStoreGetters.refreshNow}`] &&
getters[MultiBotStoreGetters.globalAutoRefresh]
) {
dispatch(`${e}/${BotStoreActions.refreshSlow}`, forceUpdate);
}
});
},