preparing for directory creation

This commit is contained in:
2025-09-30 08:52:44 +02:00
parent b58186cd41
commit 280be3c41f

View File

@@ -8,8 +8,18 @@
const router = useTinyRouter();
let children = $state({});
let new_dir = $state(null);
let parent = $state(false);
let path = $state(router.path)
async function createDir(ev){
console.log(ev);
ev.stopPropagation();
ev.preventDefault();
alert(new_dir);
return false;
}
async function loadChildren(p){
p = p.substring(6);
if (p == '') p = '/';
@@ -19,6 +29,7 @@
children.dirs[`/user/${user.id}`] = t('my_files');
children.dirs['/project'] = t('projects')
children.dirs['/company'] = t('companies');
parent = false;
} else {
const url = api(`files${p}`);
const res = await fetch(url,{credentials:'include'});
@@ -27,6 +38,8 @@
if (json.dirs) children.dirs = json.dirs;
if (json.files) children.files = json.files;
if (json.title) children.title = json.title;
parent = p.substring(0, p.lastIndexOf("/"));
if (parent == '/user'||p=='/project'||p=='/company') parent = '/';
yikes();
} else {
error(res);
@@ -55,6 +68,12 @@
<h1>{t('files')} {children?.title}</h1>
<ul>
{#if parent}
<li class="dir parent">
<span class="symbol"></span>
<a href={'/files'+parent} {onclick}>..</a>
</li>
{/if}
{#if children?.dirs}
{#each Object.entries(children.dirs) as [k,v]}
<li class="dir">
@@ -62,7 +81,16 @@
<a href={'/files'+k} {onclick}>{v}</a>
</li>
{/each}
{/if}
{/if}
{#if parent}
<li class="action">
<form onsubmit={create_dir}>
<span class="symbol">+</span>
<input type="text" bind:value={new_dir} />
<button type="submit" disabled={!new_dir}>{t('create_directory')}</button>
</form>
</li>
{/if}
{#if children.files}
{#each Object.entries(children.files) as [k,v]}
<li class="file">
@@ -71,5 +99,14 @@
</li>
{/each}
{/if}
{#if parent}
<li class="action">
<form>
<span class="symbol">+</span>
<input type="file" />
<button>{t('upload_file')}</button>
</form>
</li>
{/if}
</ul>