refac: user list sub-standard code

This commit is contained in:
Timothy Jaeryang Baek
2025-04-30 16:49:41 +04:00
parent db06a925fe
commit f9d238e850
5 changed files with 188 additions and 154 deletions
+3 -18
View File
@@ -5,34 +5,19 @@
import { goto } from '$app/navigation';
import { user } from '$lib/stores';
import { getUsers } from '$lib/apis/users';
import UserList from './Users/UserList.svelte';
import Groups from './Users/Groups.svelte';
const i18n = getContext('i18n');
let users = [];
let totalUsers = 0;
let selectedTab = 'overview';
let loaded = false;
$: if (selectedTab) {
getUsersHandler();
}
const getUsersHandler = async () => {
users = await getUsers(localStorage.token);
};
onMount(async () => {
if ($user?.role !== 'admin') {
await goto('/');
} else {
users = await getUsers(localStorage.token);
totalUsers = users.length;
}
loaded = true;
const containerElement = document.getElementById('users-tabs-container');
@@ -104,9 +89,9 @@
<div class="flex-1 mt-1 lg:mt-0 overflow-y-scroll">
{#if selectedTab === 'overview'}
<UserList {totalUsers}/>
<UserList />
{:else if selectedTab === 'groups'}
<Groups {users} />
<Groups />
{/if}
</div>
</div>