Code Cleanup™
This commit is contained in:
@@ -40,8 +40,9 @@
|
||||
import TypeAheadSearch from "../../components/TypeAheadSearch.svelte";
|
||||
import {fightRepo, type UpdateFight} from "@repo/fight.ts";
|
||||
import dayjs from "dayjs";
|
||||
import duration from "dayjs/plugin/duration"
|
||||
dayjs.extend(duration)
|
||||
import duration from "dayjs/plugin/duration";
|
||||
|
||||
dayjs.extend(duration);
|
||||
|
||||
export let data: ExtendedEvent;
|
||||
|
||||
@@ -54,13 +55,13 @@
|
||||
return {
|
||||
group: group,
|
||||
fights: fights.filter(fight => fight.group === group)
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function cycleSelect() {
|
||||
if (selectedFights.size === fights.length) {
|
||||
selectedFights = new Set();
|
||||
} else if(selectedFights.size === 0){
|
||||
} else if (selectedFights.size === 0) {
|
||||
selectedFights = new Set(fights.filter(fight => fight.start > Date.now()));
|
||||
|
||||
if (selectedFights.size === 0) {
|
||||
@@ -72,7 +73,7 @@
|
||||
}
|
||||
|
||||
function cycleGroup(groupFights: EventFight[]) {
|
||||
if(groupFights.every(gf => selectedFights.has(gf))) {
|
||||
if (groupFights.every(gf => selectedFights.has(gf))) {
|
||||
groupFights.forEach(fight => selectedFights.delete(fight));
|
||||
} else {
|
||||
groupFights.forEach(fight => selectedFights.add(fight));
|
||||
@@ -81,6 +82,7 @@
|
||||
}
|
||||
|
||||
let deleteOpen = false;
|
||||
|
||||
async function deleteFights() {
|
||||
for (const fight of selectedFights) {
|
||||
await $fightRepo.deleteFight(fight.id);
|
||||
@@ -95,9 +97,10 @@
|
||||
return {
|
||||
name: player.name,
|
||||
value: player.id.toString()
|
||||
}
|
||||
};
|
||||
}).sort((a, b) => a.name.localeCompare(b.name));
|
||||
let kampfleiter = "";
|
||||
|
||||
async function updateKampfleiter() {
|
||||
for (const fight of selectedFights) {
|
||||
let f: UpdateFight = {
|
||||
@@ -122,8 +125,8 @@
|
||||
let groupSearch = "";
|
||||
|
||||
$: selectableGroups = [{
|
||||
name: 'None',
|
||||
value: ''
|
||||
name: "None",
|
||||
value: ""
|
||||
}, {
|
||||
value: groupSearch,
|
||||
name: `Create: '${groupSearch}'`
|
||||
@@ -131,8 +134,9 @@
|
||||
return {
|
||||
name: group,
|
||||
value: group
|
||||
}
|
||||
};
|
||||
}).sort((a, b) => a.name.localeCompare(b.name))];
|
||||
|
||||
async function updateGroup() {
|
||||
for (const fight of selectedFights) {
|
||||
let f: UpdateFight = {
|
||||
@@ -157,7 +161,7 @@
|
||||
let changeTimeOpen = false;
|
||||
let changedTime = fights.length != 0 ? dayjs(Math.min(...fights.map(fight => fight.start)))?.utc(true)?.toISOString()?.slice(0, -1) : undefined;
|
||||
|
||||
$: deltaTime = dayjs.duration(dayjs(changedTime).utc(true).diff(minTime))
|
||||
$: deltaTime = dayjs.duration(dayjs(changedTime).utc(true).diff(minTime));
|
||||
|
||||
async function updateStartTime() {
|
||||
for (const fight of selectedFights) {
|
||||
@@ -168,7 +172,7 @@
|
||||
map: null,
|
||||
redTeam: null,
|
||||
spielmodus: null,
|
||||
start: dayjs(fight.start).add(deltaTime.asMilliseconds(), 'millisecond')
|
||||
start: dayjs(fight.start).add(deltaTime.asMilliseconds(), "millisecond")
|
||||
};
|
||||
await $fightRepo.updateFight(fight.id, f);
|
||||
}
|
||||
@@ -194,7 +198,8 @@
|
||||
<CalendarWeekOutline/>
|
||||
</ToolbarButton>
|
||||
<Tooltip>Reschedule Fights</Tooltip>
|
||||
<ToolbarButton on:click={() => selectedFights.size > 0 ? kampfleiterOpen = true : kampfleiterOpen = false} disabled={changedTime === undefined}>
|
||||
<ToolbarButton on:click={() => selectedFights.size > 0 ? kampfleiterOpen = true : kampfleiterOpen = false}
|
||||
disabled={changedTime === undefined}>
|
||||
<ProfileCardOutline/>
|
||||
</ToolbarButton>
|
||||
<Tooltip>Change Kampfleiter</Tooltip>
|
||||
@@ -204,7 +209,8 @@
|
||||
<Tooltip>Change Group</Tooltip>
|
||||
</ToolbarGroup>
|
||||
<ToolbarGroup>
|
||||
<ToolbarButton color="red" on:click={() => selectedFights.size > 0 ? deleteOpen = true : deleteOpen = false}>
|
||||
<ToolbarButton color="red"
|
||||
on:click={() => selectedFights.size > 0 ? deleteOpen = true : deleteOpen = false}>
|
||||
<TrashBinOutline/>
|
||||
</ToolbarButton>
|
||||
<Tooltip>Delete</Tooltip>
|
||||
@@ -212,12 +218,13 @@
|
||||
</Toolbar>
|
||||
{#each groupedFights as group}
|
||||
<div class="flex mt-4">
|
||||
<Checkbox class="ml-2 text-center" checked={group.fights.every(gf => selectedFights.has(gf))} on:click={() => cycleGroup(group.fights)}/>
|
||||
<Checkbox class="ml-2 text-center" checked={group.fights.every(gf => selectedFights.has(gf))}
|
||||
on:click={() => cycleGroup(group.fights)}/>
|
||||
<h1 class="ml-4 text-2xl">{group.group ?? "Ungrouped"}</h1>
|
||||
</div>
|
||||
{#each group.fights.sort((a, b) => a.start - b.start) as fight, i (fight.id)}
|
||||
<FightCard {fight} {i} {data} selected={selectedFights.has(fight)}
|
||||
on:select={() => {
|
||||
on:select={() => {
|
||||
if (selectedFights.has(fight)) {
|
||||
selectedFights.delete(fight);
|
||||
} else {
|
||||
@@ -225,13 +232,14 @@
|
||||
}
|
||||
selectedFights = selectedFights;
|
||||
}}
|
||||
on:update={async () => fights = await $fightRepo.listFights(data.event.id)}
|
||||
on:update={async () => fights = await $fightRepo.listFights(data.event.id)}
|
||||
/>
|
||||
{/each}
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<CreateFightModal {data} bind:open={createOpen} on:create={async () => data.fights = await $fightRepo.listFights(data.event.id)}></CreateFightModal>
|
||||
<CreateFightModal {data} bind:open={createOpen}
|
||||
on:create={async () => data.fights = await $fightRepo.listFights(data.event.id)}></CreateFightModal>
|
||||
|
||||
<Modal bind:open={deleteOpen} title="Delete {selectedFights.size} Fights" autoclose size="sm">
|
||||
<p>Are you sure you want to delete {selectedFights.size} fights?</p>
|
||||
@@ -255,7 +263,8 @@
|
||||
<Modal bind:open={groupChangeOpen} title="Change Group" size="sm">
|
||||
<div class="m-2">
|
||||
<Label for="fight-kampf">Group</Label>
|
||||
<TypeAheadSearch items={selectableGroups} bind:selected={group} bind:searchValue={groupSearch} all></TypeAheadSearch>
|
||||
<TypeAheadSearch items={selectableGroups} bind:selected={group} bind:searchValue={groupSearch}
|
||||
all></TypeAheadSearch>
|
||||
</div>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button class="ml-auto" on:click={updateGroup}>Change</Button>
|
||||
@@ -270,7 +279,8 @@
|
||||
<input type="datetime-local" {...props} bind:value={changedTime}/>
|
||||
</Input>
|
||||
</div>
|
||||
<p>{deltaTime.asMilliseconds() < 0 ? '' : '+'}{("0" + deltaTime.hours()).slice(-2)}:{("0" + deltaTime.minutes()).slice(-2)}</p>
|
||||
<p>{deltaTime.asMilliseconds() < 0 ? '' : '+'}{("0" + deltaTime.hours()).slice(-2)}
|
||||
:{("0" + deltaTime.minutes()).slice(-2)}</p>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button class="ml-auto" on:click={updateStartTime}>Update</Button>
|
||||
<Button on:click={() => changeTimeOpen = false} color="alternative">Cancel</Button>
|
||||
|
||||
Reference in New Issue
Block a user