Navbar to script setup

This commit is contained in:
Matthias 2023-03-23 19:30:13 +01:00
parent b1ceb7158a
commit 5ed68096e6

View File

@ -122,37 +122,33 @@
</header>
</template>
<script lang="ts">
<script setup lang="ts">
import LoginModal from '@/views/LoginModal.vue';
import BootswatchThemeSelect from '@/components/BootswatchThemeSelect.vue';
import Favico from 'favico.js';
import ReloadControl from '@/components/ftbot/ReloadControl.vue';
import BotEntry from '@/components/BotEntry.vue';
import BotList from '@/components/BotList.vue';
import { defineComponent, ref, onBeforeUnmount, onMounted, watch } from 'vue';
import { ref, onBeforeUnmount, onMounted, watch } from 'vue';
import { OpenTradeVizOptions, useSettingsStore } from '@/stores/settings';
import { useLayoutStore } from '@/stores/layout';
import { useBotStore } from '@/stores/ftbotwrapper';
import { useRoute } from 'vue-router';
export default defineComponent({
name: 'NavBar',
components: { LoginModal, BootswatchThemeSelect, ReloadControl, BotEntry, BotList },
setup() {
const botStore = useBotStore();
const botStore = useBotStore();
const settingsStore = useSettingsStore();
const layoutStore = useLayoutStore();
const route = useRoute();
const favicon = ref<Favico | undefined>(undefined);
const pingInterval = ref<number>();
const settingsStore = useSettingsStore();
const layoutStore = useLayoutStore();
const route = useRoute();
const favicon = ref<Favico | undefined>(undefined);
const pingInterval = ref<number>();
const clickLogout = () => {
const clickLogout = () => {
botStore.removeBot(botStore.selectedBot);
// TODO: This should be per bot
};
};
const setOpenTradesAsPill = (tradeCount: number) => {
const setOpenTradesAsPill = (tradeCount: number) => {
if (!favicon.value) {
favicon.value = new Favico({
animation: 'none',
@ -168,8 +164,8 @@ export default defineComponent({
favicon.value.reset();
console.log('reset');
}
};
const resetDynamicLayout = (): void => {
};
const resetDynamicLayout = (): void => {
console.log(`resetLayout called for ${route?.fullPath}`);
switch (route?.fullPath) {
case '/trade':
@ -180,8 +176,8 @@ export default defineComponent({
break;
default:
}
};
const setTitle = () => {
};
const setTitle = () => {
let title = 'freqUI';
if (settingsStore.openTradesInTitle === OpenTradeVizOptions.asTitle) {
title = `(${botStore.activeBotorUndefined?.openTradeCount}) ${title}`;
@ -190,32 +186,32 @@ export default defineComponent({
title = `${title} - ${botStore.activeBotorUndefined?.botName}`;
}
document.title = title;
};
};
onBeforeUnmount(() => {
onBeforeUnmount(() => {
if (pingInterval) {
clearInterval(pingInterval.value);
}
});
});
onMounted(async () => {
onMounted(async () => {
await settingsStore.loadUIVersion();
pingInterval.value = window.setInterval(botStore.pingAll, 60000);
});
});
settingsStore.$subscribe((_, state) => {
settingsStore.$subscribe((_, state) => {
const needsUpdate = settingsStore.openTradesInTitle !== state.openTradesInTitle;
if (needsUpdate) {
setTitle();
setOpenTradesAsPill(botStore.activeBotorUndefined?.openTradeCount || 0);
}
});
});
watch(
watch(
() => botStore.activeBotorUndefined?.botName,
() => setTitle(),
);
watch(
);
watch(
() => botStore.activeBotorUndefined?.openTradeCount,
() => {
if (settingsStore.openTradesInTitle === OpenTradeVizOptions.showPill) {
@ -224,21 +220,7 @@ export default defineComponent({
setTitle();
}
},
);
return {
favicon,
clickLogout,
resetDynamicLayout,
setTitle,
layoutStore,
botStore,
settingsStore,
route,
};
},
});
);
</script>
<style lang="scss" scoped>