From 9fd8ddb9bd7c9487d4453479c461c45b8b2957ff Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 11 Feb 2024 11:16:23 +0100 Subject: [PATCH] =?UTF-8?q?Code=20Cleanup=E2=84=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintignore | 2 + .eslintrc.json | 11 +- src/components/PostComponent.astro | 14 +- src/components/admin/App.svelte | 57 +++--- .../admin/components/FightEditPart.svelte | 35 ++-- .../admin/components/TypeAheadSearch.svelte | 27 +-- src/components/admin/pages/Edit.svelte | 76 ++++---- src/components/admin/pages/Event.svelte | 2 +- src/components/admin/pages/Home.svelte | 14 +- src/components/admin/pages/Login.svelte | 23 ++- src/components/admin/pages/NotFound.svelte | 2 +- src/components/admin/pages/Perms.svelte | 22 ++- src/components/admin/pages/edit/Editor.svelte | 28 +-- .../admin/pages/edit/MDEMarkdownEditor.svelte | 18 +- .../admin/pages/event/EventEdit.svelte | 8 +- .../admin/pages/event/FightCard.svelte | 11 +- .../admin/pages/event/FightList.svelte | 48 +++-- .../admin/pages/event/TeamList.svelte | 3 +- .../event/modals/CreateFightModal.svelte | 6 +- .../pages/event/modals/FightEditModal.svelte | 15 +- .../admin/pages/generate/DragAcceptor.svelte | 5 +- .../pages/generate/GroupGenerator.svelte | 71 ++++---- .../admin/pages/generate/TeamChip.svelte | 9 +- .../admin/pages/home/CreateEventModal.svelte | 8 +- .../admin/pages/home/EventCard.svelte | 2 +- src/components/admin/util.ts | 6 +- src/components/repo/auth.ts | 6 +- src/components/repo/data.ts | 3 +- src/components/repo/event.ts | 35 ++-- src/components/repo/fight.ts | 47 ++--- src/components/repo/page.ts | 17 +- src/components/repo/perms.ts | 3 +- src/components/repo/repo.ts | 7 +- src/components/repo/schem.ts | 11 +- src/components/repo/stats.ts | 3 +- src/components/stores/cached.ts | 12 +- src/components/types/data.ts | 6 +- src/components/types/page.ts | 8 +- src/components/types/perms.ts | 2 +- src/components/types/schem.ts | 10 +- src/components/types/stats.ts | 2 +- src/content/config.ts | 23 ++- src/layouts/Basic.astro | 14 +- src/layouts/NavbarLayout.astro | 78 ++++---- src/layouts/PageLayout.astro | 11 +- src/pages/[...slug].astro | 16 +- src/pages/admin/index.astro | 2 +- src/pages/announcements/[...slug].astro | 49 ++--- src/pages/announcements/index.astro | 8 +- src/pages/announcements/tags/[tag].astro | 17 +- src/pages/dashboard.astro | 3 +- src/pages/downloads.astro | 9 +- src/pages/help/[...slug].astro | 14 +- src/pages/help/index.astro | 2 +- src/pages/index.astro | 171 ++++++++++-------- src/pages/login.astro | 6 +- src/pages/ranked/[...gamemode].astro | 14 +- src/pages/rules/[mode].astro | 12 +- src/pages/rules/index.astro | 13 +- src/pages/stats/fight.astro | 3 +- src/styles/button.css | 16 +- src/util/util.ts | 6 +- 62 files changed, 663 insertions(+), 519 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..98d2168 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +src/pages/de +src/env.d.ts \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 66ed61f..a1a2d0a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -48,6 +48,15 @@ "semi": [ "error", "always" - ] + ], + "no-console": "error", + "no-debugger": "error", + "no-alert": "error", + "no-undef": "error", + "no-var": "error", + "no-const-assign": "error", + "comma-dangle": ["error", "always-multiline"], + "no-unneeded-ternary": "error", + "multiline-ternary": ["error", "always-multiline"] } } diff --git a/src/components/PostComponent.astro b/src/components/PostComponent.astro index 4ba0e2a..5deaa5d 100644 --- a/src/components/PostComponent.astro +++ b/src/components/PostComponent.astro @@ -15,17 +15,19 @@ const { post } = Astro.props as Props;
- {post.data.image != null ? ( -
- Post Image -
- ) : null} + {post.data.image != null + ? ( +
+ Post Image +
+ ) + : null}

{post.data.title}

{Intl.DateTimeFormat(astroI18n.locale, { day: "numeric", month: "long", - year: "numeric" + year: "numeric", }).format(post.data.created)}

{post.data.description}

diff --git a/src/components/admin/App.svelte b/src/components/admin/App.svelte index 3ef627f..f27672b 100644 --- a/src/components/admin/App.svelte +++ b/src/components/admin/App.svelte @@ -18,31 +18,46 @@ -->
- +
diff --git a/src/components/admin/components/FightEditPart.svelte b/src/components/admin/components/FightEditPart.svelte index 829b8b8..9c99dcf 100644 --- a/src/components/admin/components/FightEditPart.svelte +++ b/src/components/admin/components/FightEditPart.svelte @@ -37,48 +37,48 @@ return { name: player.name, value: player.id.toString() - } + }; }).sort((a, b) => a.name.localeCompare(b.name)); $: selectableTeams = teams.map(team => { return { name: team.name, value: team.id.toString() - } + }; }).sort((a, b) => a.name.localeCompare(b.name)); $: selectableGamemodes = $gamemodes.map(gamemode => { return { name: gamemode, value: gamemode - } + }; }).sort((a, b) => a.name.localeCompare(b.name)); - $: customGamemode = !selectableGamemodes.some((e) => e.name === gamemode) && gamemode !== ''; + $: customGamemode = !selectableGamemodes.some((e) => e.name === gamemode) && gamemode !== ""; $: selectableCustomGamemode = [ ...selectableGamemodes, { - name: gamemode + ' (custom)', + name: gamemode + " (custom)", value: gamemode } - ] + ]; $: mapsStore = maps(gamemode); $: selectableMaps = $mapsStore.map(map => { return { name: map, value: map - } + }; }).sort((a, b) => a.name.localeCompare(b.name)); - $: customMap = !selectableMaps.some((e) => e.name === map) && map !== '' + $: customMap = !selectableMaps.some((e) => e.name === map) && map !== ""; $: selectableCustomMaps = [ ...selectableMaps, { - name: map + ' (custom)', + name: map + " (custom)", value: map } - ] + ]; $: selectableGroups = [{ - name: 'None', - value: '' + name: "None", + value: "" }, { value: groupSearch, name: `Create: '${groupSearch}'` @@ -86,7 +86,7 @@ return { name: group, value: group - } + }; }).sort((a, b) => a.name.localeCompare(b.name))]; @@ -106,11 +106,13 @@
- +
- +
@@ -118,5 +120,6 @@
- +
diff --git a/src/components/admin/components/TypeAheadSearch.svelte b/src/components/admin/components/TypeAheadSearch.svelte index 27ad50c..a2c8f82 100644 --- a/src/components/admin/components/TypeAheadSearch.svelte +++ b/src/components/admin/components/TypeAheadSearch.svelte @@ -18,32 +18,35 @@ --> - +
open = true} on:keydown={() => open = true}/>
{#each filteredItems as item (item)} - {/each} diff --git a/src/components/admin/pages/Edit.svelte b/src/components/admin/pages/Edit.svelte index 98346e2..c54fbda 100644 --- a/src/components/admin/pages/Edit.svelte +++ b/src/components/admin/pages/Edit.svelte @@ -40,68 +40,69 @@ $: availableBranches = $branches.map((branch) => ({ name: branch, value: branch - })) + })); async function createBranch() { - const name = prompt("Branch name:") + const name = prompt("Branch name:"); if (name) { - selected = null - await $pageRepo.createBranch(name) + selected = null; + await $pageRepo.createBranch(name); let inter = setInterval(() => { - branches.reload() + branches.reload(); if ($branches.includes(name)) { - selectedBranch = name - searchValue = "" - clearInterval(inter) + selectedBranch = name; + searchValue = ""; + clearInterval(inter); } - }, 1000) + }, 1000); } } function changePage(id: number) { if (dirty) { if (confirm("You have unsaved changes. Are you sure you want to change the page?")) { - selected = id - dirty = false + selected = id; + dirty = false; } } else { - selected = id + selected = id; } } async function deleteBranch(con: boolean) { if (selectedBranch !== "master") { - let conf = con || confirm("Are you sure you want to delete this branch?") - if(conf) { - await $pageRepo.deleteBranch(selectedBranch) + let conf = con || confirm("Are you sure you want to delete this branch?"); + if (conf) { + await $pageRepo.deleteBranch(selectedBranch); let inter = setInterval(() => { - branches.reload() + branches.reload(); if (!$branches.includes(selectedBranch)) { - selectedBranch = "master" - searchValue = "" - clearInterval(inter) + selectedBranch = "master"; + searchValue = ""; + clearInterval(inter); } - }, 1000) + }, 1000); } } else { - alert("You can't delete the master branch") + alert("You can't delete the master branch"); } } async function createFile() { - let name = prompt("File name:", "[Name].md") + let name = prompt("File name:", "[Name].md"); if (name) { - await $pageRepo.createFile(`${selectedPath}${name}`, selectedBranch) - reload() + await $pageRepo.createFile(`${selectedPath}${name}`, selectedBranch); + reload(); } } function reload() { - const w = selectedBranch - selectedBranch = "###!" - selectedBranch = w + const w = selectedBranch; + selectedBranch = "###!"; + selectedBranch = w; } +
@@ -115,17 +116,20 @@
{#await pagesFuture} - + {:then pages} {@const pagesMap = mapToMap(pages)}
- - ({value, name: value}))} bind:selected={selectedPath} bind:searchValue={pathSearchValue} maxItems={Number.MAX_VALUE} leftText={true} /> + + ({value, name: value}))} + bind:selected={selectedPath} bind:searchValue={pathSearchValue} + maxItems={Number.MAX_VALUE} leftText={true}/>
{#if selectedBranch !== "master"} - + {:else} @@ -140,8 +144,12 @@ {@const match = nameRegexExec ? nameRegexExec[0] : ""} {@const startIndex = page.path.indexOf(match)} {@const endIndex = startIndex + match.length} -
  • changePage(page.id)}> - {page.path.substring(0, startIndex)}{match}{page.path.substring(endIndex, page.path.length)} +
  • changePage(page.id)}> + {page.path.substring(0, startIndex)}{match}{page.path.substring(endIndex, page.path.length)}
  • {/each} {/if} @@ -152,7 +160,7 @@ {#if selected} - + {/if}
    diff --git a/src/components/admin/pages/Event.svelte b/src/components/admin/pages/Event.svelte index 1e31ec9..ba30f28 100644 --- a/src/components/admin/pages/Event.svelte +++ b/src/components/admin/pages/Event.svelte @@ -48,7 +48,7 @@ Event - + Teams diff --git a/src/components/admin/pages/Home.svelte b/src/components/admin/pages/Home.svelte index 567ebcb..7989ce8 100644 --- a/src/components/admin/pages/Home.svelte +++ b/src/components/admin/pages/Home.svelte @@ -26,18 +26,18 @@ import {eventRepo} from "@repo/event.ts"; import {tokenStore} from "@repo/repo.ts"; - let events = $eventRepo.listEvents() - let showAdd = false - let millis = Date.now() + let events = $eventRepo.listEvents(); + let showAdd = false; + let millis = Date.now(); - Admin-Tool + Mod-Tool - + Edit Pages Permissions @@ -58,13 +58,13 @@

    Upcoming

    {#each data.filter((e) => e.start > millis) as event} - + {/each}

    Past

    {#each data.filter((e) => e.start < millis).reverse() as event} - + {/each}
    {:catch error} diff --git a/src/components/admin/pages/Login.svelte b/src/components/admin/pages/Login.svelte index 7a48852..8932665 100644 --- a/src/components/admin/pages/Login.svelte +++ b/src/components/admin/pages/Login.svelte @@ -31,9 +31,9 @@ async function handleSubmit() { loading = true; - let res = await fetchWithToken(value, "/data") + let res = await fetchWithToken(value, "/data"); loading = false; - if(res.ok) { + if (res.ok) { $tokenStore = value; await replace("/"); } else { @@ -41,7 +41,7 @@ value = ""; setTimeout(() => { error = false; - }, 5000) + }, 5000); } } @@ -51,12 +51,13 @@
    - + @@ -64,7 +65,8 @@
    +
    - {:catch error} + {:catch error}

    {error.toString()}

    {/await} {:catch error} diff --git a/src/components/admin/pages/edit/Editor.svelte b/src/components/admin/pages/edit/Editor.svelte index c421ca7..f6a549f 100644 --- a/src/components/admin/pages/edit/Editor.svelte +++ b/src/components/admin/pages/edit/Editor.svelte @@ -23,7 +23,7 @@ import CodeMirror from "svelte-codemirror-editor"; import {base64ToBytes} from "../../util.ts"; import type {Page} from "@type/page.ts"; - import {materialDark} from '@ddietr/codemirror-themes/material-dark.js' + import {materialDark} from "@ddietr/codemirror-themes/material-dark.js"; import {createEventDispatcher} from "svelte"; import MDEMarkdownEditor from "./MDEMarkdownEditor.svelte"; import {pageRepo} from "@repo/page.ts"; @@ -40,24 +40,30 @@ function getPage(value: Page): Page { page = value; - pageContent = new TextDecoder().decode(base64ToBytes(value.content)); + + if (!dirty || confirm("You have unchanged Changes! Discard them? ")) { + navigator.clipboard.writeText(pageContent); + dirty = false; + pageContent = new TextDecoder().decode(base64ToBytes(value.content)); + } + return value; } function savePage() { - let message = window.prompt("Commit message:", "Update " + page!.name) + let message = window.prompt("Commit message:", "Update " + page!.name); if (message) { - $pageRepo.updatePage(pageId, pageContent, page!.sha, message, branch) + $pageRepo.updatePage(pageId, pageContent, page!.sha, message, branch); dirty = false; } } async function deletePage() { - let message = window.prompt("Commit message:", "Delete " + page!.name) + let message = window.prompt("Commit message:", "Delete " + page!.name); if (message) { - await $pageRepo.deletePage(pageId, message, page!.sha, branch) + await $pageRepo.deletePage(pageId, message, page!.sha, branch); dirty = false; - dispatcher("reload") + dispatcher("reload"); } } @@ -65,9 +71,9 @@ if (dirty) { return "You have unsaved changes. Are you sure you want to leave?"; } -}} /> +}}/> {#await pageFuture} - + {:then p}
    @@ -83,9 +89,9 @@
    {#if page?.name.endsWith("md")} - + {:else} - dirty = true} /> + dirty = true}/> {/if}
    {:catch error} diff --git a/src/components/admin/pages/edit/MDEMarkdownEditor.svelte b/src/components/admin/pages/edit/MDEMarkdownEditor.svelte index 2a8b663..6d4f4d5 100644 --- a/src/components/admin/pages/edit/MDEMarkdownEditor.svelte +++ b/src/components/admin/pages/edit/MDEMarkdownEditor.svelte @@ -20,7 +20,7 @@