You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

<script setup>
import { onMounted, ref, defineExpose } from 'vue'
import {
currentWorkingCategory,
currentWorkingInstrument,
instruments,
categories
} from '../libs/state.js'
const summary = ref([])
const loadData = async () => {
const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'summary')
summary.value = await response.json()
}
onMounted(loadData)
const setWorkingCategory = (choice) => {
const chosenCategory = categories.value.find(category => category.id === choice.category_id)
currentWorkingCategory.value = chosenCategory
currentWorkingInstrument.value = instruments.value.find(instrument => instrument.name === chosenCategory.instrument)
}
defineExpose({loadData})
</script>
<template>
<h2 @click="loadData">Summary</h2>
<table>
<thead>
<tr>
<th>category id</th>
<th>category</th>
<th>chunks practiced</th>
<th>instrument</th>
<th>weight</th>
</tr>
</thead>
<tbody>
<tr v-for="category in summary" @click="setWorkingCategory(category)">
<td>{{category.category_id}}</td>
<td>{{category.category}}</td>
<td>{{category.chunks_practiced}}</td>
<td>{{category.instrument}}</td>
<td>{{category.weight}}</td>
</tr>
</tbody>
</table>
</template>