From a0642e86cc4f4f9c087d9a8b8887f4e4411b9d6d Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Wed, 28 Aug 2024 20:43:52 +0200 Subject: [PATCH] category chooser mostly working --- src/App.vue | 14 ++++++++----- src/components/category_chooser.vue | 31 +++++++++++++++++++---------- src/components/show_category.vue | 24 ++++++++++------------ 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8c22fa4..fa2b956 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,15 +7,15 @@ import Timer from './components/timer.vue' import Status from './components/status.vue' - const currentWorkingCategoryID = ref(1) + const currentWorkingCategory = ref(null) const summaryRef = ref(null) const statusRef = ref(null) const showCategoryRef = ref(null) const instruments = ref([]) const categories = ref([]) - const updateCurrentWorkingCategoryID = (id) =>{ - currentWorkingCategoryID.value = id + const updateCurrentWorkingCategoryID = (category) =>{ + currentWorkingCategory.value = category } const refreshPage = (session) => { @@ -29,6 +29,7 @@ instruments.value = await response.json() response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'categories') categories.value = await response.json() + currentWorkingCategory.value = categories.value[0] } onMounted(loadData) @@ -37,21 +38,24 @@
+
+ :currentWorkingCategory="currentWorkingCategory"/>
diff --git a/src/components/category_chooser.vue b/src/components/category_chooser.vue index c0444d0..1acab15 100644 --- a/src/components/category_chooser.vue +++ b/src/components/category_chooser.vue @@ -1,21 +1,31 @@ diff --git a/src/components/show_category.vue b/src/components/show_category.vue index d4d6f4b..19f487b 100644 --- a/src/components/show_category.vue +++ b/src/components/show_category.vue @@ -2,13 +2,12 @@ import CategoryChooser from './category_chooser.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 practiceCategoryId = ref(0) - const { currentWorkingCategoryID } = toRefs(props); - + /*const { currentWorkingCategory } = toRefs(props);*/ + 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() @@ -18,29 +17,26 @@ navigator.clipboard.writeText(event.target.innerText) } - const loadCategory = async (newValue) => { - const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+newValue) + const loadCategory = async (chosenCategoryID) => { + const response = await fetch(import.meta.env.VITE_PRACTICE_TRACKER_API_URL+'show-category/'+chosenCategoryID) categorySessions.value = await response.json() - practiceCategoryId.value = newValue } onMounted(async () => { - practiceCategoryId.value = currentWorkingCategoryID - loadCategory(currentWorkingCategoryID.value) + loadCategory(props.currentWorkingCategory.id) }) - watch(currentWorkingCategoryID, loadCategory) - defineExpose ({loadCategory}) + /*watch(currentWorkingCategory, loadCategory)*/ + defineExpose({loadCategory})