charts fetch data + cards
This commit is contained in:
parent
9f0c6a8ad4
commit
7b1214e42f
3 changed files with 71 additions and 2 deletions
17
src/api/charts.js
Normal file
17
src/api/charts.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { apiClient } from '@/services/apiClient.js'
|
||||||
|
|
||||||
|
export const useChartsApi = () => {
|
||||||
|
const getChartsPrices = async (days) => {
|
||||||
|
console.log(days)
|
||||||
|
const response = await apiClient.get('/prices', { days: days })
|
||||||
|
if (response.status === 200) {
|
||||||
|
return response
|
||||||
|
} else {
|
||||||
|
console.log('Add merch error: ', response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getChartsPrices,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,41 @@
|
||||||
<script setup lang="ts">
|
<script setup>
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { useChartsApi } from '@/api/charts.js'
|
||||||
|
import ChartsCard from '@/views/ChartsView/ChartsCard.vue'
|
||||||
|
|
||||||
|
const { getChartsPrices } = useChartsApi()
|
||||||
|
|
||||||
|
const pricesList = ref(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const error = ref(null)
|
||||||
|
|
||||||
|
const fetchPrices = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getChartsPrices(7)
|
||||||
|
pricesList.value = response.data
|
||||||
|
if (!response.status === 400) {
|
||||||
|
router.push({ name: 'collection' })
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
error.value = err.message
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchPrices()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
Charts view
|
<n-grid responsive="screen" cols="1 s:1 m:2 l:2 xl:2 2xl:2" class="grid-main">
|
||||||
|
<n-gi class="grid-item" v-for="item in pricesList" :key="item.merch_uuid">
|
||||||
|
<router-link :to="`/details/${item.merch_uuid}`" class="card-link">
|
||||||
|
<ChartsCard :chartsData="item" />
|
||||||
|
</router-link>
|
||||||
|
</n-gi>
|
||||||
|
</n-grid>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
20
src/views/ChartsView/ChartsCard.vue
Normal file
20
src/views/ChartsView/ChartsCard.vue
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
chartsData: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<n-card :title="chartsData.name" class="charts-card" style="--n-padding-bottom: 5px">
|
||||||
|
<p class="micro-uuid text-center">{{ chartsData.merch_uuid }}</p>
|
||||||
|
</n-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.charts-card {
|
||||||
|
min-width: 80%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue