added a remove button and fixed a bug where the input component was added to the view instead of getting a new one for the specifig exercise
parent
0a677bf743
commit
4c262ba076
|
|
@ -1,20 +1,24 @@
|
||||||
<template>
|
<template>
|
||||||
<input class="search text-white font-bold py-2 px-2 rounded mt-5" type="text" v-model="input" placeholder="Search..." />
|
<input class="search
|
||||||
|
text-black py-2 px-2 rounded mt-5"
|
||||||
|
v-model="input"
|
||||||
|
type="text"
|
||||||
|
placeholder="Search..." />
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div class="exerciseList">
|
<div class="exerciseList">
|
||||||
<ul class="exerciseItem" v-for="exercise in filterExercises()" :key="exercise.name">
|
<ul class="exerciseItem" v-for="exercise in filterExercises()" :key="exercise.name">
|
||||||
<button @click="exerciseClick(exercise)" class="btn bg-secondary-button hover:bg-accent text-white font-bold py-2 px-2 rounded" >{{ exercise.name }}</button>
|
<button @click="exerciseClick(exercise)" class="btn bg-secondary-button hover:bg-accent text-white font-bold py-2 px-2 rounded" >{{ exercise.name }}</button>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="selectedExercise in selectedExercises" :key="selectedExercise" class="show">
|
<div v-if="selectedExercise">
|
||||||
<WeightsInput v-model:selectedExercise="exerciseName"/>
|
<WeightsInput :selectedExercise="selectedExercise"></WeightsInput>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
|
|
||||||
import { usePostStore } from '@/stores/store.js';
|
import { useExerciseStore } from '@/stores/storeExercise.js';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import WeightsInput from "@/views/weight/WeightsInput.vue";
|
import WeightsInput from "@/views/weight/WeightsInput.vue";
|
||||||
|
|
||||||
|
|
@ -22,12 +26,9 @@
|
||||||
muscle: String,
|
muscle: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
const json = usePostStore()
|
const json = useExerciseStore()
|
||||||
const exercises = ref([])
|
const exercises = ref([])
|
||||||
// idee mit hilfe von chatGpt
|
const selectedExercise = ref(null)
|
||||||
const selectedExercises = ref([])
|
|
||||||
// const isClicked = ref(false)
|
|
||||||
let exerciseName = ""
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await json.fetchMuscleExercise()
|
await json.fetchMuscleExercise()
|
||||||
|
|
@ -63,13 +64,17 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
const exerciseClick = (exercise) => {
|
const exerciseClick = (exercise) => {
|
||||||
exerciseName = exercise.name
|
selectedExercise.value = exercise;
|
||||||
const existingExercise = selectedExercises.value.find((selected) => selected.name === exercise.name);
|
// const existingExercise = selectedExercises.value.find((selected) => selected.name === exercise.name);
|
||||||
if (!existingExercise) {
|
// if (!existingExercise) {
|
||||||
selectedExercises.value.push({ exercise, weight: '' });
|
// selectedExercises.value.push({ exercise, weight: '' });
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const selectedExercise = computed(() => {
|
||||||
|
// return selectedExercises.value.length > 0 ? selectedExercises.value[0] : null;
|
||||||
|
// });
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
color: #e7f1df;
|
color: #e7f1df;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
font-size: 1.2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-item:hover{
|
.nav-item:hover{
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@ import {defineStore} from 'pinia'
|
||||||
import muscleExercise from '../assets/muscleExercise';
|
import muscleExercise from '../assets/muscleExercise';
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
export const usePostStore = defineStore('json', () => {
|
export const useExerciseStore = defineStore('json', () => {
|
||||||
const postList = ref([])
|
const exerciseList = ref([])
|
||||||
const error = ref([])
|
const error = ref([])
|
||||||
|
|
||||||
async function fetchMuscleExercise() {
|
async function fetchMuscleExercise() {
|
||||||
postList.value = muscleExercise
|
exerciseList.value = muscleExercise
|
||||||
error.value = []
|
error.value = []
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
postList,
|
postList: exerciseList,
|
||||||
error,
|
error,
|
||||||
fetchMuscleExercise
|
fetchMuscleExercise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export default usePostStore
|
export default useExerciseStore
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {defineStore} from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
//https://vueuse.org/core/useStorage/
|
//https://vueuse.org/core/useStorage/
|
||||||
import {useStorage} from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
|
import { useExerciseStore } from './storeExercise.js';
|
||||||
|
|
||||||
//see https://stephanlangeveld.medium.com/simple-local-storage-implementation-using-vue-3-vueuse-and-pinia-with-zero-extra-lines-of-code-cb9ed2cce42a
|
//see https://stephanlangeveld.medium.com/simple-local-storage-implementation-using-vue-3-vueuse-and-pinia-with-zero-extra-lines-of-code-cb9ed2cce42a
|
||||||
export const useWeightInputStore = defineStore({
|
export const useWeightInputStore = defineStore({
|
||||||
|
|
@ -12,19 +13,20 @@ export const useWeightInputStore = defineStore({
|
||||||
warmUpSets: useStorage('warmUpSets', []),
|
warmUpSets: useStorage('warmUpSets', []),
|
||||||
warmUpReps: useStorage('warmUpReps', []),
|
warmUpReps: useStorage('warmUpReps', []),
|
||||||
warmUpSetsWeight: useStorage('warmUpSetsWeight', []),
|
warmUpSetsWeight: useStorage('warmUpSetsWeight', []),
|
||||||
selectedExercise: useStorage('selectedExercise', []),
|
selectedExercise: [],
|
||||||
warmUpSetCount: useStorage('warmUpSetCount', 0),
|
warmUpSetCount: useStorage('warmUpSetCount', 0),
|
||||||
workingSetCount: useStorage('workingSetCount', 0),
|
workingSetCount: useStorage('workingSetCount', 0),
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getAllWeights(state) {
|
getInputsPerExercise : (state) => {
|
||||||
return state.weight;
|
const exercise = useExerciseStore.exerciseList.value;
|
||||||
},
|
return state.selectedExercise.filter((item) => item.exercise === exercise.exerciseList.value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addWeight(weight, reps) {
|
removeWarmUpSet() {
|
||||||
this.weight.push(weight);
|
this.workingSets.pop();
|
||||||
this.reps.push(reps);
|
this.warmUpSetCount--;
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -6,6 +6,11 @@
|
||||||
class="bg-accent hover:bg-primary-button text-white font-bold py-2 px-2 rounded ml-5">
|
class="bg-accent hover:bg-primary-button text-white font-bold py-2 px-2 rounded ml-5">
|
||||||
Add
|
Add
|
||||||
</button>
|
</button>
|
||||||
|
<button :disabled="!warmUpSetSmallerOne"
|
||||||
|
@click="removeWarmUpSet()"
|
||||||
|
class="bg-accent hover:bg-primary-button text-white font-bold py-2 px-2 rounded ml-5 disabled:opacity-25">
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
<div>
|
<div>
|
||||||
<div v-for="(warmUpSet, warmUpSetCount) in weightInput.warmUpSets" :key="warmUpSetCount" class="item flex justify-smart mt-1">
|
<div v-for="(warmUpSet, warmUpSetCount) in weightInput.warmUpSets" :key="warmUpSetCount" class="item flex justify-smart mt-1">
|
||||||
{{ warmUpSet }}
|
{{ warmUpSet }}
|
||||||
|
|
@ -35,6 +40,11 @@
|
||||||
class="bg-accent hover:bg-primary-button text-white font-bold py-2 px-2 rounded ml-7">
|
class="bg-accent hover:bg-primary-button text-white font-bold py-2 px-2 rounded ml-7">
|
||||||
Add
|
Add
|
||||||
</button>
|
</button>
|
||||||
|
<button :disabled="!setSmallerOne"
|
||||||
|
@click="removeWarmUpSet()"
|
||||||
|
class="bg-accent hover:bg-primary-button text-white font-bold py-2 px-2 rounded ml-5 disabled:opacity-25">
|
||||||
|
Remove
|
||||||
|
</button>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div v-for="(workingset, workingSetCount) in weightInput.workingSets" :key="workingSetCount" class="item flex justify-smart mt-1">
|
<div v-for="(workingset, workingSetCount) in weightInput.workingSets" :key="workingSetCount" class="item flex justify-smart mt-1">
|
||||||
|
|
@ -64,12 +74,14 @@
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useWeightInputStore } from '@/stores/storeInput';
|
import { useWeightInputStore } from '@/stores/storeInput';
|
||||||
|
import { computed } from 'vue';
|
||||||
|
|
||||||
const selectedExercise = defineProps({
|
const selectedExercise = defineProps({
|
||||||
selectedExercise: String
|
selectedExercise: String
|
||||||
});
|
});
|
||||||
|
|
||||||
const weightInput = useWeightInputStore();
|
const weightInput = useWeightInputStore();
|
||||||
|
weightInput.selectedExercise = selectedExercise;
|
||||||
|
|
||||||
const warmUpAddSet = () => {
|
const warmUpAddSet = () => {
|
||||||
const newWarmUpSet = {
|
const newWarmUpSet = {
|
||||||
|
|
@ -87,6 +99,26 @@ const workingAddSet = () => {
|
||||||
weightInput.workingSets.push(newWorkingSet.content);
|
weightInput.workingSets.push(newWorkingSet.content);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeWarmUpSet = () => {
|
||||||
|
weightInput.warmUpSets.pop();
|
||||||
|
weightInput.warmUpSetsWeight.pop();
|
||||||
|
weightInput.warmUpSetCount--;
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeWorkingSet = () => {
|
||||||
|
weightInput.workingSets.pop();
|
||||||
|
weightInput.workingSetsWeight.pop();
|
||||||
|
weightInput.workingSetCount--;
|
||||||
|
};
|
||||||
|
|
||||||
|
const warmUpSetSmallerOne = computed(() => {
|
||||||
|
if (weightInput.warmUpSetCount < 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue