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

118 lines
2.7 KiB
Vue
Raw Normal View History

2021-06-27 16:30:58 +02:00
<template>
<base-dialog
:show="!!error"
title="An error has occured!"
@close="handleError"
>
<p>{{ error }}</p>
</base-dialog>
2021-06-27 16:30:58 +02:00
<section>
2021-06-28 21:02:28 +02:00
<coach-filter @change-filter="setFilter"></coach-filter>
2021-06-27 16:30:58 +02:00
</section>
2021-06-28 17:43:27 +02:00
<base-card>
<section>
<div class="controls">
2021-07-28 20:51:47 +02:00
<base-button mode="outline" @click="loadCoaches(true)"
>Refresh</base-button
>
2021-07-28 17:09:10 +02:00
<base-button v-if="!isCoach && !isLoading" link to="/register"
>Register as Coach</base-button
>
2021-06-28 17:43:27 +02:00
</div>
2021-07-28 17:09:10 +02:00
<div v-if="isLoading">
<base-spinner></base-spinner>
</div>
<ul v-else-if="hasCoaches">
2021-06-28 17:43:27 +02:00
<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>
2021-06-27 16:30:58 +02:00
</template>
2021-06-27 18:21:12 +02:00
<script>
2021-06-28 21:02:28 +02:00
import CoachFilter from '../../components/coaches/CoachFilter.vue';
2021-06-28 17:20:42 +02:00
import CoachItem from '../../components/coaches/CoachItem.vue';
2021-06-27 18:21:12 +02:00
export default {
2021-06-28 21:02:28 +02:00
components: { CoachItem, CoachFilter },
data() {
return {
2021-07-28 17:09:10 +02:00
isLoading: false,
error: null,
2021-06-28 21:02:28 +02:00
activeFilters: {
backend: true,
frontend: true,
career: true
}
};
},
2021-06-27 18:21:12 +02:00
computed: {
isCoach() {
return this.$store.getters['coaches/isCoach'];
},
2021-06-27 18:21:12 +02:00
filteredCoaches() {
2021-06-28 21:02:28 +02:00
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() {
2021-07-28 17:09:10 +02:00
return !this.isLoading && this.$store.getters['coaches/hasCoaches'];
2021-06-27 18:21:12 +02:00
}
2021-06-28 21:02:28 +02:00
},
2021-07-28 17:01:33 +02:00
created() {
this.loadCoaches();
},
2021-06-28 21:02:28 +02:00
methods: {
setFilter(updatedFilters) {
this.activeFilters = updatedFilters;
2021-07-28 17:01:33 +02:00
},
2021-07-28 20:51:47 +02:00
async loadCoaches(refresh = false) {
2021-07-28 17:09:10 +02:00
this.isLoading = true;
try {
2021-07-28 20:51:47 +02:00
await this.$store.dispatch('coaches/loadCoaches', {
forceRefresh: refresh
});
} catch (error) {
this.error = error || 'Something went wrong!';
}
2021-07-28 17:09:10 +02:00
this.isLoading = false;
},
handleError() {
this.error = null;
2021-06-28 21:02:28 +02:00
}
2021-06-27 18:21:12 +02:00
}
};
</script>
2021-06-28 17:20:52 +02:00
<style scoped>
ul {
list-style: none;
margin: 0;
padding: 0;
}
.controls {
display: flex;
justify-content: space-between;
}
</style>