Editor: added game creation and deletion

This commit is contained in:
2025-12-28 12:51:43 +01:00
parent 48bc66b89a
commit daf3f779aa
4 changed files with 199 additions and 3 deletions

View File

@@ -27,6 +27,9 @@
let showDeleteDir = $state(false);
let dirToDelete: Directory | undefined = $state();
let showDeleteRessource = $state(false);
let resToDelete: Ressource | undefined = $state();
let showRenameFile = $state(false);
let fileToRename: Ressource | undefined = $state();
let newFileName = $state("");
@@ -73,23 +76,35 @@
});
}
function deleteRessource(res: Ressource | Directory) {
async function deleteRessource(res: Ressource | Directory): Promise<boolean> {
if (isRessource(res)) {
axios
return axios
.delete(url("/cdn/" + res.user + "/" + res.filename), {
withCredentials: true
})
.then((response) => {
if (response.status === 200) {
fetchDirectory();
return true;
} else {
alert("Something went wrong: " + response.status);
return false;
}
})
.catch((err) => {
console.error(err);
return false;
});
} else if (isDir(res)) {
showDeleteDir = true;
dirToDelete = res;
return true;
}
return false;
}
function deleteRessourceCancel() {
resToDelete = undefined;
}
async function deleteDir() {
@@ -313,7 +328,10 @@
class="btn border-red-600 text-red-600"
onclick={(event) => {
event.stopPropagation();
deleteRessource(ressource);
if (isRessource(ressource)) {
showDeleteRessource = true;
resToDelete = ressource;
}
}}><i class="fa-solid fa-trash"></i></button
>
</div>
@@ -365,6 +383,26 @@
</div>
</Modal>
<Modal
bind:showModal={showDeleteRessource}
okFn={async () => {
if (resToDelete === undefined) return false;
return deleteRessource(resToDelete);
}}
cancelFn={deleteRessourceCancel}
>
{#snippet header()}
<h2 class="text-3xl">Ressource löschen</h2>
{/snippet}
<div>
Soll die Ressource {resToDelete?.name} wirklich gelöscht werden?
</div>
{#if error.length > 0}
<div class="text-red-700">{error}</div>
{/if}
</Modal>
<Modal bind:showModal={showDeleteDir} okFn={deleteDir} cancelFn={deleteDirCancel}>
{#snippet header()}
<h2 class="text-3xl">Ordner löschen</h2>

View File

@@ -22,3 +22,14 @@ export function isDir(dir: Directory | Ressource): dir is Directory {
export function isRessource(ressource: Ressource | Directory): ressource is Ressource {
return (ressource as Directory).isDir === undefined;
}
export type GameId = string;
export type Game = {
name: string;
owner: string;
_id: GameId;
walls: WallId[];
};
export type WallId = string;