This repository has been archived on 2021-07-29. You can view files and clone it, but cannot push or open issues or pull requests.
find_coach/src/pages/coaches/CoachesList.vue

93 lines
2.1 KiB
Vue

<template>
<section>
<coach-filter @change-filter="setFilter"></coach-filter>
</section>
<base-card>
<section>
<div class="controls">
<base-button mode="outline" @click="loadCoaches">Refresh</base-button>
<base-button v-if="!isCoach" link to="/register"
>Register as Coach</base-button
>
</div>
<ul v-if="hasCoaches">
<coach-item
v-for="coach in filteredCoaches"
:key="coach.id"
:id="coach.id"
:firstName="coach.firstName"
:lastName="coach.lastName"
:areas="coach.areas"
:rate="coach.hourlyRate"
></coach-item>
</ul>
<h3 v-else>No coaches found.</h3>
</section>
</base-card>
</template>
<script>
import CoachFilter from '../../components/coaches/CoachFilter.vue';
import CoachItem from '../../components/coaches/CoachItem.vue';
export default {
components: { CoachItem, CoachFilter },
data() {
return {
activeFilters: {
backend: true,
frontend: true,
career: true
}
};
},
computed: {
isCoach() {
return this.$store.getters['coaches/isCoach'];
},
filteredCoaches() {
const coaches = this.$store.getters['coaches/coaches'];
return coaches.filter(coach => {
if (this.activeFilters.backend && coach.areas.includes('backend')) {
return true;
}
if (this.activeFilters.frontend && coach.areas.includes('frontend')) {
return true;
}
if (this.activeFilters.career && coach.areas.includes('career')) {
return true;
}
return false;
});
},
hasCoaches() {
return this.$store.getters['coaches/hasCoaches'];
}
},
created() {
this.loadCoaches();
},
methods: {
setFilter(updatedFilters) {
this.activeFilters = updatedFilters;
},
loadCoaches() {
this.$store.dispatch('coaches/loadCoaches');
}
}
};
</script>
<style scoped>
ul {
list-style: none;
margin: 0;
padding: 0;
}
.controls {
display: flex;
justify-content: space-between;
}
</style>