category chooser mostly working

practiced-songs
Matthew Huntington 1 year ago
parent 03dc8d1bb4
commit a0642e86cc

@ -7,15 +7,15 @@
import Timer from './components/timer.vue' import Timer from './components/timer.vue'
import Status from './components/status.vue' import Status from './components/status.vue'
const currentWorkingCategoryID = ref(1) const currentWorkingCategory = ref(null)
const summaryRef = ref(null) const summaryRef = ref(null)
const statusRef = ref(null) const statusRef = ref(null)
const showCategoryRef = ref(null) const showCategoryRef = ref(null)
const instruments = ref([]) const instruments = ref([])
const categories = ref([]) const categories = ref([])
const updateCurrentWorkingCategoryID = (id) =>{ const updateCurrentWorkingCategoryID = (category) =>{
currentWorkingCategoryID.value = id currentWorkingCategory.value = category
} }
const refreshPage = (session) => { const refreshPage = (session) => {
@ -29,6 +29,7 @@
instruments.value = await response.json() instruments.value = await response.json()
response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'categories') response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'categories')
categories.value = await response.json() categories.value = await response.json()
currentWorkingCategory.value = categories.value[0]
} }
onMounted(loadData) onMounted(loadData)
</script> </script>
@ -37,21 +38,24 @@
<main> <main>
<section id="timer"> <section id="timer">
<Status ref="statusRef"/> <Status ref="statusRef"/>
<!--
<Timer <Timer
@loggedTime="refreshPage" @loggedTime="refreshPage"
:categories="categories" :categories="categories"
:instruments="instruments" :instruments="instruments"
:currentWorkingCategoryID="currentWorkingCategoryID"/> :currentWorkingCategory="currentWorkingCategory"/>
-->
</section> </section>
<section id="summary"> <section id="summary">
<Summary ref="summaryRef" @update="updateCurrentWorkingCategoryID"/> <Summary ref="summaryRef" @update="updateCurrentWorkingCategoryID"/>
</section> </section>
<section id="category"> <section id="category">
<ShowCategory <ShowCategory
v-if="categories.length > 0"
:instruments="instruments" :instruments="instruments"
:categories="categories" :categories="categories"
ref="showCategoryRef" ref="showCategoryRef"
:currentWorkingCategoryID="currentWorkingCategoryID"/> :currentWorkingCategory="currentWorkingCategory"/>
</section> </section>
<section id="songs"> <section id="songs">
<Songs/> <Songs/>

@ -1,21 +1,31 @@
<script setup> <script setup>
import { onMounted, ref, watch, toRefs } from 'vue' import { onMounted, ref, watch, toRefs } from 'vue'
const emit = defineEmits(['update']) const emit = defineEmits(['update'])
const props = defineProps(['instruments', 'categories', 'currentWorkingCategoryID']) const props = defineProps(['instruments', 'categories', 'currentWorkingCategory'])
const { currentWorkingCategoryID } = toRefs(props);
const chosenInstrument = ref('clarinet')
const handleSelection = (event)=>{ const handleSelection = (event)=>{
emit('update', event.target.value) emit('update', event.target.value)
} }
/*watch(() => props.currentWorkingCategory, (newValue)=>{*/
watch(() => props.currentWorkingCategoryID, (newValue)=>{ /*const newCategory = props.categories.find(category => category.id == newValue)*/
const newCategory = props.categories.find(category => category.id == newValue) /*chosenInstrument.value = newCategory.instrument*/
chosenInstrument.value = newCategory.instrument /*})*/
})
</script> </script>
<template> <template>
<select v-model="chosenInstrument"> <select v-model="currentWorkingCategory.instrument">
<option v-for="instrument in props.instruments">
{{instrument.name}}
</option>
</select>
<select @change="handleSelection" v-model="currentWorkingCategory.id">
<option v-show="category.instrument === currentWorkingCategory.instrument"
v-bind:value="category.id"
v-for="category in props.categories">
{{category.category}}
</option>
</select>
<!--
<select v-model="currentWorkingCategory.instrument">
<option v-for="instrument in props.instruments" v-bind:value="instrument.name"> <option v-for="instrument in props.instruments" v-bind:value="instrument.name">
{{instrument.name}} {{instrument.name}}
</option> </option>
@ -23,7 +33,7 @@
<select <select
@change="handleSelection" @change="handleSelection"
v-for="instrument in props.instruments" v-for="instrument in props.instruments"
v-model="props.currentWorkingCategoryID" v-model="props.currentWorkingCategory"
v-show="instrument.name == chosenInstrument"> v-show="instrument.name == chosenInstrument">
<option <option
v-bind:value="category.id" v-bind:value="category.id"
@ -34,4 +44,5 @@
{{category.category}} {{category.category}}
</option> </option>
</select> </select>
-->
</template> </template>

@ -2,13 +2,12 @@
import CategoryChooser from './category_chooser.vue' import CategoryChooser from './category_chooser.vue'
import { onMounted, ref, watch, defineProps, toRefs} from 'vue' import { onMounted, ref, watch, defineProps, toRefs} from 'vue'
const props = defineProps(['categories', 'instruments', 'currentWorkingCategoryID']) const props = defineProps(['categories', 'instruments', 'currentWorkingCategory'])
const categorySessions = ref([]) const categorySessions = ref([])
const practiceCategoryId = ref(0)
const { currentWorkingCategoryID } = toRefs(props); /*const { currentWorkingCategory } = toRefs(props);*/
const change = async (event) => { const change = async (event) => {
const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+event.target.value) const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+event.target.value)
categorySessions.value = await response.json() categorySessions.value = await response.json()
@ -18,29 +17,26 @@
navigator.clipboard.writeText(event.target.innerText) navigator.clipboard.writeText(event.target.innerText)
} }
const loadCategory = async (newValue) => { const loadCategory = async (chosenCategoryID) => {
const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+newValue) const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+chosenCategoryID)
categorySessions.value = await response.json() categorySessions.value = await response.json()
practiceCategoryId.value = newValue
} }
onMounted(async () => { onMounted(async () => {
practiceCategoryId.value = currentWorkingCategoryID loadCategory(props.currentWorkingCategory.id)
loadCategory(currentWorkingCategoryID.value)
}) })
watch(currentWorkingCategoryID, loadCategory) /*watch(currentWorkingCategory, loadCategory)*/
defineExpose ({loadCategory}) defineExpose({loadCategory})
</script> </script>
<template> <template>
<h2>Show Category</h2> <h2>Show Category</h2>
<CategoryChooser <CategoryChooser
@update="loadCategory" @update="loadCategory"
v-if="categories.length > 0" :currentWorkingCategory="props.currentWorkingCategory"
:currentWorkingCategoryID="props.currentWorkingCategoryID"
:instruments="props.instruments" :instruments="props.instruments"
:categories="categories" /> :categories="props.categories" />
<table> <table>
<thead> <thead>
<tr> <tr>

Loading…
Cancel
Save