Skip to content

Commit

Permalink
Update frontend/src/stores/users.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com>
  • Loading branch information
zurdi15 and gantoine committed Jul 5, 2024
1 parent 91dcec3 commit 3c658d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/Administration/Users/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const userSearch = ref("");
const { xs } = useDisplay();
const emitter = inject<Emitter<Events>>("emitter");
const usersStore = storeUsers();
const { allUSers } = storeToRefs(usersStore);
const { allUsers } = storeToRefs(usersStore);
const auth = storeAuth();
const HEADERS = [
{
Expand Down Expand Up @@ -60,7 +60,7 @@ emitter?.on("updateDataTablePages", updateDataTablePages);
// Functions
function updateDataTablePages() {
pageCount.value = Math.ceil(usersStore.allUSers.length / usersPerPage.value);
pageCount.value = Math.ceil(usersStore.allUsers.length / usersPerPage.value);
}
function disableUser(user: User) {
Expand Down Expand Up @@ -108,7 +108,7 @@ onMounted(() => {
:items-per-page-options="PER_PAGE_OPTIONS"
:search="userSearch"
:headers="HEADERS"
:items="allUSers"
:items="allUsers"
:sort-by="[{ key: 'username', order: 'asc' }]"
fixed-header
fixed-footer
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/stores/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ export type User = UserSchema;

export default defineStore("users", {
state: () => ({
allUSers: [] as User[],
allUsers: [] as User[],
}),

getters: {
admins: (state) => state.allUSers.filter((user) => user.role === "admin"),
admins: (state) => state.allUsers.filter((user) => user.role === "admin"),
},

actions: {
set(users: User[]) {
this.allUSers = users;
this.allUsers = users;
},
add(user: User) {
this.allUSers = this.allUSers.concat(user);
this.allUsers = this.allUsers.concat(user);
},
update(user: User) {
this.allUSers = this.allUSers.map((value) => {
this.allUsers = this.allUsers.map((value) => {
if (value.id === user.id) {
return user;
}
return value;
});
},
remove(userId: number) {
this.allUSers = this.allUSers.filter((value) => {
this.allUsers = this.allUsers.filter((value) => {
return value.id !== userId;
});
},
reset() {
this.allUSers = [];
this.allUsers = [];
},
},
});

0 comments on commit 3c658d0

Please sign in to comment.