frontend/src/views/ChartsView.vue

69 lines
1.7 KiB
Vue
Raw Normal View History

2025-09-24 21:31:20 +03:00
<script setup>
2025-09-25 19:43:46 +03:00
import { computed, onMounted, ref } from 'vue'
2025-09-24 21:31:20 +03:00
import { useChartsApi } from '@/api/charts.js'
2025-09-25 19:12:20 +03:00
import PeriodSelector from '@/components/PeriodSelector.vue'
2025-09-24 21:31:20 +03:00
import ChartsCard from '@/views/ChartsView/ChartsCard.vue'
2025-09-25 19:12:20 +03:00
import router from '@/router/index.js'
2025-09-25 19:43:46 +03:00
import ChartsSearch from '@/views/ChartsView/ChartsSearch.vue'
2025-09-25 19:12:20 +03:00
2025-09-24 21:31:20 +03:00
const { getChartsPrices } = useChartsApi()
2025-09-25 19:43:46 +03:00
const pricesList = ref([])
2025-09-24 21:31:20 +03:00
const loading = ref(true)
const error = ref(null)
2025-09-25 19:12:20 +03:00
const fetchPrices = async (days = 7) => {
loading.value = true
error.value = null
2025-09-24 21:31:20 +03:00
try {
2025-09-25 19:12:20 +03:00
const response = await getChartsPrices(days)
if (response.status === 400) {
2025-09-24 21:31:20 +03:00
router.push({ name: 'collection' })
2025-09-25 19:12:20 +03:00
return
2025-09-24 21:31:20 +03:00
}
2025-09-25 19:12:20 +03:00
pricesList.value = response.data
2025-09-24 21:31:20 +03:00
} catch (err) {
2025-09-25 19:12:20 +03:00
error.value = err.message || 'Fetch data error'
2025-09-24 21:31:20 +03:00
} finally {
loading.value = false
}
}
onMounted(() => {
2025-09-25 19:12:20 +03:00
fetchPrices(7)
2025-09-24 21:31:20 +03:00
})
2025-09-25 19:12:20 +03:00
function handleSelectDays(days) {
fetchPrices(days)
}
2025-09-25 19:43:46 +03:00
2025-09-25 20:40:11 +03:00
const searchQuery = ref('')
2025-09-25 19:43:46 +03:00
const filteredPrices = computed(() => {
if (!searchQuery.value.trim()) {
2025-09-25 20:40:11 +03:00
return pricesList.value
2025-09-25 19:43:46 +03:00
}
2025-09-25 20:40:11 +03:00
const q = searchQuery.value.toLowerCase()
return pricesList.value.filter((item) => item.name.toLowerCase().includes(q))
})
2025-09-12 20:23:58 +03:00
</script>
<template>
2025-09-25 20:40:11 +03:00
<div class="sticky-search-container">
<ChartsSearch v-model="searchQuery" />
</div>
2025-09-25 19:12:20 +03:00
<PeriodSelector @days="handleSelectDays" />
<n-grid responsive="screen" cols="1 s:1 m:1 l:2 xl:2 2xl:2" class="grid-main">
2025-09-25 19:43:46 +03:00
<n-gi class="grid-item" v-for="item in filteredPrices" :key="item.merch_uuid">
2025-09-24 21:31:20 +03:00
<router-link :to="`/details/${item.merch_uuid}`" class="card-link">
<ChartsCard :chartsData="item" />
</router-link>
</n-gi>
</n-grid>
2025-09-12 20:23:58 +03:00
</template>
<style scoped>
</style>