moving instruments/categories to global state

practiced-songs
Matthew Huntington 11 months ago
parent 7d9f05a758
commit c7e780f716

@ -7,15 +7,18 @@
import Timer from './components/timer.vue' import Timer from './components/timer.vue'
import Status from './components/status.vue' import Status from './components/status.vue'
import { currentWorkingCategory, currentWorkingInstrument } from './libs/state.js' import {
currentWorkingCategory,
currentWorkingInstrument,
instruments,
categories
} from './libs/state.js'
const timerRunning = ref(false) const timerRunning = ref(false)
const micThresholdExceeded = ref(false) const micThresholdExceeded = ref(false)
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 categories = ref([])
const refreshPage = (session) => { const refreshPage = (session) => {
summaryRef.value.loadData() summaryRef.value.loadData()
@ -64,18 +67,12 @@
/> />
</section> </section>
<section id="summary"> <section id="summary">
<Summary <Summary ref="summaryRef" />
ref="summaryRef"
:instruments="instruments"
:categories="categories"
/>
</section> </section>
<section id="category"> <section id="category">
<ShowCategory <ShowCategory
v-if="currentWorkingInstrument" v-if="currentWorkingInstrument"
ref="showCategoryRef" ref="showCategoryRef"
:instruments="instruments"
:categories="categories"
/> />
</section> </section>
<section id="songs"> <section id="songs">

@ -1,23 +1,27 @@
<script setup> <script setup>
import { defineProps } from 'vue'; import { defineProps } from 'vue';
const props = defineProps(['instruments', 'categories']) import {
import { currentWorkingCategory, currentWorkingInstrument } from '../libs/state.js' currentWorkingCategory,
currentWorkingInstrument,
instruments,
categories
} from '../libs/state.js'
const selectFirstInstrumentOfCategory = () => { const selectFirstInstrumentOfCategory = () => {
currentWorkingCategory.value = props.categories.find(category => category.instrument === currentWorkingInstrument.value.name) currentWorkingCategory.value = categories.value.find(category => category.instrument === currentWorkingInstrument.value.name)
} }
</script> </script>
<template> <template>
<select @change="selectFirstInstrumentOfCategory" v-model="currentWorkingInstrument"> <select @change="selectFirstInstrumentOfCategory" v-model="currentWorkingInstrument">
<option :value="instrument" v-for="instrument in props.instruments"> <option :value="instrument" v-for="instrument in instruments">
{{instrument.name}} {{instrument.name}}
</option> </option>
</select> </select>
<select v-model="currentWorkingCategory"> <select v-model="currentWorkingCategory">
<option <option
v-for="category in props.categories.filter(currentCategory => currentCategory.instrument === currentWorkingInstrument.name)" v-for="category in categories.filter(currentCategory => currentCategory.instrument === currentWorkingInstrument.name)"
:value="category"> :value="category">
{{category.category}} {{category.category}}
</option> </option>

@ -2,9 +2,10 @@
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 } from 'vue' import { onMounted, ref, watch, defineProps } from 'vue'
import { currentWorkingCategory, currentWorkingInstrument } from '../libs/state.js' import {
currentWorkingCategory,
const props = defineProps(['categories', 'instruments']) currentWorkingInstrument
} from '../libs/state.js'
const categorySessions = ref([]) const categorySessions = ref([])
@ -25,9 +26,7 @@
<template> <template>
<h2>Show Category</h2> <h2>Show Category</h2>
<CategoryChooser <CategoryChooser />
:instruments="props.instruments"
:categories="props.categories" />
<table> <table>
<thead> <thead>
<tr> <tr>

@ -1,7 +1,11 @@
<script setup> <script setup>
import { onMounted, ref, defineExpose } from 'vue' import { onMounted, ref, defineExpose } from 'vue'
import { currentWorkingCategory, currentWorkingInstrument } from '../libs/state.js' import {
const props = defineProps(['instruments', 'categories']) currentWorkingCategory,
currentWorkingInstrument,
instruments,
categories
} from '../libs/state.js'
const summary = ref([]) const summary = ref([])
@ -13,9 +17,9 @@
onMounted(loadData) onMounted(loadData)
const setWorkingCategory = (choice) => { const setWorkingCategory = (choice) => {
const chosenCategory = props.categories.find(category => category.id === choice.category_id) const chosenCategory = categories.value.find(category => category.id === choice.category_id)
currentWorkingCategory.value = chosenCategory currentWorkingCategory.value = chosenCategory
currentWorkingInstrument.value = props.instruments.find(instrument => instrument.name === chosenCategory.instrument) currentWorkingInstrument.value = instruments.value.find(instrument => instrument.name === chosenCategory.instrument)
} }
defineExpose({loadData}) defineExpose({loadData})

@ -4,8 +4,6 @@
const micThresholdExceeded = defineModel('micThresholdExceeded') const micThresholdExceeded = defineModel('micThresholdExceeded')
const timerRunning = defineModel('timerRunning') const timerRunning = defineModel('timerRunning')
const props = defineProps(['categories', 'instruments'])
const { proxy } = getCurrentInstance(); const { proxy } = getCurrentInstance();
onMounted(()=>{ onMounted(()=>{
@ -228,9 +226,7 @@
<input @change="updateSavedPreviousSeconds" v-model="totalSeconds" type="number"/> <input @change="updateSavedPreviousSeconds" v-model="totalSeconds" type="number"/>
<label>Practice Category</label> <label>Practice Category</label>
<CategoryChooser <CategoryChooser />
:instruments="instruments"
:categories="categories" />
<input type="submit"/> <input type="submit"/>
<label>Comments</label> <label>Comments</label>

@ -2,3 +2,5 @@ import { ref } from 'vue'
export const copiedSongs = ref([]) export const copiedSongs = ref([])
export const currentWorkingCategory = ref(null) export const currentWorkingCategory = ref(null)
export const currentWorkingInstrument = ref(null) export const currentWorkingInstrument = ref(null)
export const instruments = ref([])
export const categories = ref([])

Loading…
Cancel
Save