New eveal #32

Merged
Sirttas merged 115 commits from new-eveal into main 2026-07-14 17:15:11 +02:00
4 changed files with 48 additions and 10 deletions
Showing only changes of commit 9f6cc616ad - Show all commits
+1
View File
@@ -0,0 +1 @@
export { useAutoRefresh } from './useAutoRefresh';
+30
View File
@@ -0,0 +1,30 @@
import {onUnmounted, ref} from "vue";
const DEFAULT_INTERVAL = 1_000;
export const useAutoRefresh = (callback: () => void | Promise<void>, interval: number = DEFAULT_INTERVAL) => {
const active = ref(false);
let timer: ReturnType<typeof setInterval> | undefined;
const stop = () => {
if (timer) {
clearInterval(timer);
timer = undefined;
}
active.value = false;
};
const start = () => {
if (active.value) {
return;
}
active.value = true;
timer = setInterval(callback, interval);
};
const toggle = () => active.value ? stop() : start();
onUnmounted(stop);
return {active, start, stop, toggle};
};
@@ -47,9 +47,9 @@ watchEffect(async () => {
<template> <template>
<Tooltip v-model:open="open" class="tooltip"> <Tooltip v-model:open="open" class="tooltip">
<template #header> <template #header>
<LoadingSpinner v-if="history.length < trendingScale" class="w-6 h-6" /> <LoadingSpinner v-if="history.length < trendingScale" />
<ArrowTrendingUpIcon v-else-if="history[0].average > history[trendingScale - 1].average" class="w-6 h-6" /> <ArrowTrendingUpIcon v-else-if="history[0].average > history[trendingScale - 1].average" />
<ArrowTrendingDownIcon v-else class="w-6 h-6" /> <ArrowTrendingDownIcon v-else />
</template> </template>
<template #default> <template #default>
<div class="bg-slate-500 -left-1/2 relative tooltip-content" v-if="history.length > 0"> <div class="bg-slate-500 -left-1/2 relative tooltip-content" v-if="history.length > 0">
@@ -79,9 +79,6 @@ watchEffect(async () => {
.tooltip { .tooltip {
@apply ms-auto; @apply ms-auto;
>:deep(div.header) {
@apply btn-icon px-2;
}
&.open { &.open {
&.tooltip-top>:deep(div.header) { &.tooltip-top>:deep(div.header) {
@apply rounded-t-md bg-slate-600; @apply rounded-t-md bg-slate-600;
@@ -94,4 +91,8 @@ watchEffect(async () => {
} }
} }
} }
.tooltip>:deep(div.header) {
@apply btn-icon px-2;
}
</style> </style>
+10 -4
View File
@@ -2,7 +2,8 @@
import {getMarketTypes, MarketTypePrice, useApraisalStore} from "@/market"; import {getMarketTypes, MarketTypePrice, useApraisalStore} from "@/market";
import {AcquiredType, AcquisitionResultTable, BuyModal, SellModal, useAcquiredTypesStore} from '@/market/acquisition'; import {AcquiredType, AcquisitionResultTable, BuyModal, SellModal, useAcquiredTypesStore} from '@/market/acquisition';
import {ref, watch} from 'vue'; import {ref, watch} from 'vue';
import {activityApi} from "@/mammon"; import {ArrowPathIcon} from '@heroicons/vue/24/outline';
import {useAutoRefresh} from '@/composables';
const buyModal = ref<typeof BuyModal>(); const buyModal = ref<typeof BuyModal>();
const sellModal = ref<typeof SellModal>(); const sellModal = ref<typeof SellModal>();
@@ -12,11 +13,11 @@ const acquiredTypesStore = useAcquiredTypesStore();
const items = ref<AcquiredType[]>([]); const items = ref<AcquiredType[]>([]);
const refresh = async () => { const refresh = async () => {
await activityApi.fetchAllNewActivities();
await activityApi.processNewActivities();
await acquiredTypesStore.refresh(); await acquiredTypesStore.refresh();
} }
const {active: autoRefresh, toggle: toggleAutoRefresh} = useAutoRefresh(refresh, 5 * 60 * 1000);
watch(() => acquiredTypesStore.acquiredTypes, async itms => { watch(() => acquiredTypesStore.acquiredTypes, async itms => {
if (itms.length === 0) { if (itms.length === 0) {
return; return;
@@ -41,7 +42,12 @@ watch(() => acquiredTypesStore.acquiredTypes, async itms => {
<template> <template>
<div class="mt-4"> <div class="mt-4">
<div class="flex"> <div class="flex">
<button class="ms-auto" @click="refresh">Refresh</button> <div class="ms-auto flex">
<button class="rounded-e-none" @click="refresh">Refresh</button>
<button class="rounded-s-none border-s-0 flex items-center" :class="{ 'bg-slate-700': autoRefresh }" title="Auto refresh" @click="toggleAutoRefresh">
<ArrowPathIcon class="w-5 h-5" :class="{ 'animate-spin': autoRefresh }" />
</button>
</div>
</div> </div>
<template v-if="items.length > 0"> <template v-if="items.length > 0">
<AcquisitionResultTable :items="items" @buy="(types, price, buy, sell) => buyModal?.open(types[0].type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="types => sellModal?.open(types)" ignoredColums="date" /> <AcquisitionResultTable :items="items" @buy="(types, price, buy, sell) => buyModal?.open(types[0].type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="types => sellModal?.open(types)" ignoredColums="date" />