using v-model for show category

practiced-songs
Matthew Huntington 1 year ago
parent ed4a78f373
commit b7690e1265

@ -8,6 +8,7 @@
import Status from './components/status.vue' import Status from './components/status.vue'
const currentWorkingCategory = ref(null) const currentWorkingCategory = ref(null)
const currentWorkingInstrument = 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)
@ -26,6 +27,7 @@
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] currentWorkingCategory.value = categories.value[0]
currentWorkingInstrument.value = instruments.value.find(instrument => instrument.name === currentWorkingCategory.value.instrument)
} }
onMounted(loadData) onMounted(loadData)
</script> </script>
@ -34,26 +36,29 @@
<main> <main>
<section id="timer"> <section id="timer">
<Status ref="statusRef"/> <Status ref="statusRef"/>
<Timer <!--<Timer
v-if="categories.length > 0" v-if="categories.length > 0"
@loggedTime="refreshPage" @loggedTime="refreshPage"
:categories="categories" :categories="categories"
:instruments="instruments" :instruments="instruments"
:currentWorkingCategory="currentWorkingCategory"/> :currentWorkingCategory="currentWorkingCategory"/>-->
</section> </section>
<section id="summary"> <section id="summary">
<Summary <Summary
ref="summaryRef" ref="summaryRef"
:instruments="instruments"
:categories="categories" :categories="categories"
v-model="currentWorkingCategory" /> v-model:currentWorkingInstrument="currentWorkingInstrument"
v-model:currentWorkingCategory="currentWorkingCategory"/>
</section> </section>
<section id="category"> <section id="category">
<ShowCategory <ShowCategory
v-if="categories.length > 0" v-if="currentWorkingInstrument"
ref="showCategoryRef"
:instruments="instruments" :instruments="instruments"
:categories="categories" :categories="categories"
ref="showCategoryRef" v-model:currentWorkingInstrument="currentWorkingInstrument"
:currentWorkingCategory="currentWorkingCategory"/> v-model:currentWorkingCategory="currentWorkingCategory"/>
</section> </section>
<section id="songs"> <section id="songs">
<Songs/> <Songs/>

@ -1,21 +1,18 @@
<script setup> <script setup>
import { onMounted, ref, watch, toRefs } from 'vue' const props = defineProps(['instruments', 'categories'])
const emit = defineEmits(['update']) const currentWorkingCategory = defineModel('currentWorkingCategory')
const props = defineProps(['instruments', 'categories', 'currentWorkingCategory']) const currentWorkingInstrument = defineModel('currentWorkingInstrument')
const handleSelection = (event)=>{
emit('update', event.target.value)
}
</script> </script>
<template> <template>
<select v-model="currentWorkingCategory.instrument"> <select v-model="currentWorkingInstrument">
<option v-for="instrument in props.instruments"> <option :value="instrument" v-for="instrument in props.instruments">
{{instrument.name}} {{instrument.name}}
</option> </option>
</select> </select>
<select @change="handleSelection" v-model="currentWorkingCategory.id"> <select v-model="currentWorkingCategory">
<option v-show="category.instrument === currentWorkingCategory.instrument" <option
v-bind:value="category.id" v-show="category.instrument === currentWorkingInstrument.name"
:value="category"
v-for="category in props.categories"> v-for="category in props.categories">
{{category.category}} {{category.category}}
</option> </option>

@ -1,41 +1,34 @@
<script setup> <script setup>
import { formatSeconds } from '../libs/time.js' import { formatSeconds } from '../libs/time.js'
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 } from 'vue'
const props = defineProps(['categories', 'instruments', 'currentWorkingCategory']) const props = defineProps(['categories', 'instruments'])
const currentWorkingCategory = defineModel('currentWorkingCategory')
const currentWorkingInstrument = defineModel('currentWorkingInstrument')
const categorySessions = ref([]) const categorySessions = ref([])
const change = async (event) => {
const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+event.target.value)
categorySessions.value = await response.json()
}
const copy = (event) => { const copy = (event) => {
navigator.clipboard.writeText(event.target.innerText) navigator.clipboard.writeText(event.target.innerText)
} }
const loadCategory = async (chosenCategoryID) => { const loadCategory = async () => {
const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+chosenCategoryID) const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+currentWorkingCategory.value.id)
categorySessions.value = await response.json() categorySessions.value = await response.json()
} }
onMounted(async () => { onMounted(loadCategory)
loadCategory(props.currentWorkingCategory.id)
})
watch(() => props.currentWorkingCategory, (chosenCategory)=>{ watch(currentWorkingCategory, loadCategory)
loadCategory(chosenCategory.id)
})
defineExpose({loadCategory}) defineExpose({loadCategory})
</script> </script>
<template> <template>
<h2>Show Category</h2> <h2>Show Category</h2>
<CategoryChooser <CategoryChooser
@update="loadCategory" v-model:currentWorkingCategory="currentWorkingCategory"
:currentWorkingCategory="props.currentWorkingCategory" v-model:currentWorkingInstrument="currentWorkingInstrument"
:instruments="props.instruments" :instruments="props.instruments"
:categories="props.categories" /> :categories="props.categories" />
<table> <table>

@ -1,9 +1,8 @@
<script setup> <script setup>
import { onMounted, ref, defineExpose } from 'vue' import { onMounted, ref, defineExpose } from 'vue'
const props = defineProps(['categories']) const props = defineProps(['instruments', 'categories'])
const currentWorkingCategory = defineModel() const currentWorkingCategory = defineModel('currentWorkingCategory')
const currentWorkingInstrument = defineModel('currentWorkingInstrument')
const emit = defineEmits(['update'])
const summary = ref([]) const summary = ref([])
@ -15,7 +14,9 @@
onMounted(loadData) onMounted(loadData)
const setWorkingCategory = (choice) => { const setWorkingCategory = (choice) => {
currentWorkingCategory.value = props.categories.find(category => category.id === choice.category_id) const chosenCategory = props.categories.find(category => category.id === choice.category_id)
currentWorkingCategory.value = chosenCategory
currentWorkingInstrument.value = props.instruments.find(instrument => instrument.name === chosenCategory.instrument)
} }
defineExpose({loadData}) defineExpose({loadData})

Loading…
Cancel
Save