This commit is contained in:
Timothy Jaeryang Baek committed 2026-10-12 23:22:18 +04:00
1 parent cc4fe3eab3
commit e9635596dd
7 files changed
+276 -162

No files matched your search

@@ -17,6 +17,8 @@
import Spinner from '$lib/components/common/Spinner.svelte';
import Checkbox from '$lib/components/common/Checkbox.svelte';
import { getGroups } from '$lib/apis/groups';
import type { App } from '$lib/apis/apps';
import Grid from '$lib/components/icons/Grid.svelte';
export let includeGroups = true;
export let includeUsers = true;
@@ -26,6 +28,11 @@
export let groupIds: string[] = [];
export let userIds: string[] = [];
export let appIds: string[] = [];
export let apps: App[] = [];
$: filteredApps = apps.filter((app) =>
`${app.name} ${app.slug}`.toLowerCase().includes(query.toLowerCase())
);
let groups: any[] | null = null;
let filteredGroups: any[] = [];
@@ -79,7 +86,7 @@
const handleSearchInput = () => {
clearTimeout(searchDebounceTimer);
searchDebounceTimer = setTimeout(() => {
getUserList();
if (includeUsers) getUserList();
}, 300);
};
@@ -87,15 +94,20 @@
clearTimeout(searchDebounceTimer);
});
$: if (page !== null && orderBy !== null && direction !== null) {
$: if (includeUsers && page !== null && orderBy !== null && direction !== null) {
getUserList();
} else if (!includeUsers) {
users = [];
total = 0;
}
onMount(async () => {
groups = await getGroups(localStorage.token, true).catch((error) => {
console.error(error);
return [];
});
groups = includeGroups
? await getGroups(localStorage.token, true).catch((error) => {
console.error(error);
return [];
})
: [];
if (userIds.length > 0) {
userIds.forEach(async (id) => {
@@ -180,6 +192,22 @@
</div>
{/if}
{#if appIds.length > 0}
<div class="mx-1 mb-1.5">
<div class="text-xs text-gray-500 mx-0.5 mb-1">{appIds.length} {$i18n.t('Apps')}</div>
<div class="flex gap-1 flex-wrap">
{#each apps.filter((app) => appIds.includes(app.id)) as app (app.id)}
<button
type="button"
class="inline-flex items-center space-x-1 px-2 py-1 bg-gray-100/50 dark:bg-gray-850 rounded-lg text-xs"
on:click={() => (appIds = appIds.filter((id) => id !== app.id))}
>
<span>{app.name}</span><XMark className="size-3" />
</button>
{/each}
</div>
</div>
{/if}
<div class="flex gap-1 mb-1">
<div class=" flex w-full space-x-2">
<div class="flex flex-1">
@@ -207,7 +235,7 @@
</div>
</div>
{#if filteredUsers.length > 0 || filteredGroups.length > 0}
{#if (includeUsers && filteredUsers.length > 0) || (includeGroups && filteredGroups.length > 0) || filteredApps.length > 0}
<div class="scrollbar-hidden relative whitespace-nowrap w-full max-w-full">
<div class=" text-sm text-left text-gray-500 dark:text-gray-400 w-full max-w-full">
<div class="w-full max-h-96 overflow-y-auto rounded-lg">
@@ -311,6 +339,43 @@
{/each}
</div>
{/if}
{#if filteredApps.length > 0}
<div class="text-xs text-gray-500 mb-1 mx-1 mt-3">{$i18n.t('Apps')}</div>
<div>
{#each filteredApps as app (app.id)}
<div class="text-xs flex items-center justify-between w-full">
<button
type="button"
class="px-3 py-1.5 font-normal text-gray-900 dark:text-white flex-1 min-w-0"
on:click={() =>
(appIds = appIds.includes(app.id)
? appIds.filter((id) => id !== app.id)
: [...appIds, app.id])}
>
<div class="flex items-center gap-2">
<div
class="size-6 rounded-lg bg-gray-100 dark:bg-gray-850 flex items-center justify-center shrink-0"
>
<Grid className="size-3.5" />
</div>
<span class="truncate">{app.name}</span>
</div>
</button>
<div class="px-3 py-1">
<Checkbox
ariaLabel={app.name}
state={appIds.includes(app.id) ? 'checked' : 'unchecked'}
on:change={() =>
(appIds = appIds.includes(app.id)
? appIds.filter((id) => id !== app.id)
: [...appIds, app.id])}
/>
</div>
</div>
{/each}
</div>
{/if}
</div>
</div>
</div>