This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vuejs_course/2021-09-04_composition-13-d.../src/components/users/UserList.vue

71 lines
1.4 KiB
Vue
Raw Normal View History

2021-09-04 15:18:48 +02:00
<template>
<base-container>
<h2>Active Users</h2>
2021-09-04 16:01:46 +02:00
<base-search
@search="updateSearch"
:search-term="enteredSearchTerm"
></base-search>
2021-09-04 15:18:48 +02:00
<div>
2021-09-04 16:01:46 +02:00
<button @click="sort('asc')" :class="{ selected: sorting === 'asc' }">
Sort Ascending
</button>
<button @click="sort('desc')" :class="{ selected: sorting === 'desc' }">
Sort Descending
</button>
2021-09-04 15:18:48 +02:00
</div>
<ul>
<user-item
v-for="user in displayedUsers"
:key="user.id"
:user-name="user.fullName"
:id="user.id"
@list-projects="$emit('list-projects', $event)"
></user-item>
</ul>
</base-container>
</template>
<script>
2021-09-06 21:52:25 +02:00
import { toRefs } from 'vue';
2021-09-04 15:18:48 +02:00
import UserItem from './UserItem.vue';
2021-09-06 21:37:16 +02:00
import useSearch from '../../hooks/search';
2021-09-06 21:52:25 +02:00
import useSort from '../../hooks/sort';
2021-09-04 15:18:48 +02:00
export default {
components: {
2021-09-04 16:01:46 +02:00
UserItem
2021-09-04 15:18:48 +02:00
},
props: ['users'],
2021-09-04 16:33:19 +02:00
emits: ['list-projects'],
2021-09-04 16:01:46 +02:00
setup(props) {
2021-09-06 21:37:16 +02:00
const { users } = toRefs(props);
2021-09-04 16:33:19 +02:00
2021-09-06 21:37:16 +02:00
const { enteredSearchTerm, availableItems, updateSearch } = useSearch(
users,
'fullName'
);
2021-09-04 16:01:46 +02:00
2021-09-06 21:52:25 +02:00
const { displayedUsers, sort, sorting } = useSort(
availableItems,
'fullName'
);
2021-09-04 16:01:46 +02:00
return {
enteredSearchTerm,
updateSearch,
2021-09-04 16:33:19 +02:00
displayedUsers,
sort,
sorting
2021-09-04 16:01:46 +02:00
};
}
2021-09-04 15:18:48 +02:00
};
</script>
<style scoped>
ul {
list-style: none;
margin: 0;
padding: 0;
}
2021-09-04 16:01:46 +02:00
</style>