refactor: clean up imports and improve player search functionality in RefereesList
All checks were successful
SteamWarCI Build successful
All checks were successful
SteamWarCI Build successful
This commit is contained in:
@ -18,38 +18,35 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@components/ui/table/index.js";
|
import { Table, TableBody, TableCell, TableCaption, TableHead, TableHeader, TableRow } from "@components/ui/table";
|
||||||
import {
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@components/ui/command/index.js";
|
||||||
Command,
|
import { Popover, PopoverContent, PopoverTrigger } from "@components/ui/popover/index.js";
|
||||||
CommandEmpty,
|
import { Button } from "@components/ui/button/index.js";
|
||||||
CommandGroup,
|
import type { ExtendedEvent } from "@type/event.ts";
|
||||||
CommandInput,
|
|
||||||
CommandItem,
|
|
||||||
CommandList,
|
|
||||||
} from "@components/ui/command/index.js";
|
|
||||||
import {Popover, PopoverContent, PopoverTrigger} from "@components/ui/popover/index.js";
|
|
||||||
import {Button} from "@components/ui/button/index.js";
|
|
||||||
import type {ExtendedEvent} from "@type/event.ts";
|
|
||||||
import { eventRepo } from "@repo/event";
|
import { eventRepo } from "@repo/event";
|
||||||
import { players } from "@stores/stores"
|
import { players } from "@stores/stores";
|
||||||
|
|
||||||
const {
|
const { event }: { event: ExtendedEvent } = $props();
|
||||||
event
|
|
||||||
}: { event: ExtendedEvent } = $props();
|
|
||||||
|
|
||||||
let referees = $state(event.event.referees)
|
let referees = $state(event.event.referees);
|
||||||
|
|
||||||
async function addReferee(value: string) {
|
async function addReferee(value: string) {
|
||||||
referees = (await $eventRepo.updateEvent(event.event.id.toString(), {
|
referees = (
|
||||||
addReferee: [value]
|
await $eventRepo.updateEvent(event.event.id.toString(), {
|
||||||
})).referees;
|
addReferee: [value],
|
||||||
|
})
|
||||||
|
).referees;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeReferee(value: string) {
|
async function removeReferee(value: string) {
|
||||||
referees = (await $eventRepo.updateEvent(event.event.id.toString(), {
|
referees = (
|
||||||
removeReferee: [value]
|
await $eventRepo.updateEvent(event.event.id.toString(), {
|
||||||
})).referees;
|
removeReferee: [value],
|
||||||
|
})
|
||||||
|
).referees;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let playerSearch = $state("");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Table>
|
<Table>
|
||||||
@ -69,24 +66,27 @@
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
{/each}
|
{/each}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
<Popover>
|
||||||
<Popover>
|
<TableCaption>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
<Button>
|
<Button>Add</Button>
|
||||||
Add
|
|
||||||
</Button>
|
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
|
</TableCaption>
|
||||||
<PopoverContent class="p-0">
|
<PopoverContent class="p-0">
|
||||||
<Command>
|
<Command shouldFilter={false}>
|
||||||
<CommandInput placeholder="Search players..." />
|
<CommandInput bind:value={playerSearch} placeholder="Search players..." />
|
||||||
<CommandList>
|
<CommandList>
|
||||||
<CommandEmpty>No Players found :(</CommandEmpty>
|
<CommandEmpty>No Players found :(</CommandEmpty>
|
||||||
<CommandGroup heading="Players">
|
<CommandGroup heading="Players">
|
||||||
{#each $players.filter(v => v.perms.length > 0).filter(v => !referees.some(k => k.uuid === v.uuid)) as player (player.uuid)}
|
{#each $players
|
||||||
<CommandItem value={player.uuid} onSelect={() => addReferee(player.uuid)}>{player.name}</CommandItem>
|
.filter((v) => v.name.includes(playerSearch))
|
||||||
|
.filter((v, i) => i < 50)
|
||||||
|
.filter((v) => !referees.some((k) => k.uuid === v.uuid)) as player (player.uuid)}
|
||||||
|
<CommandItem value={player.name} onSelect={() => addReferee(player.uuid)} keywords={[player.uuid]}>{player.name}</CommandItem>
|
||||||
{/each}
|
{/each}
|
||||||
</CommandGroup>
|
</CommandGroup>
|
||||||
</CommandList>
|
</CommandList>
|
||||||
</Command>
|
</Command>
|
||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
</Table>
|
||||||
|
|||||||
Reference in New Issue
Block a user