working on file module

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-09-28 21:12:51 +02:00
parent 92bc976da9
commit fba707d77b
7 changed files with 147 additions and 10 deletions

View File

@@ -1,5 +1,58 @@
<script>
import { t } from '../../translations.svelte';
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte';
import { error } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import { user } from '../../user.svelte';
const router = useTinyRouter();
let children = $state({});
async function loadChildren(path){
path = path.substring(6);
if (path == '') path = '/';
children = { dirs : {}};
if (path == '/'){
children.dirs[t('my_files')] = `user/${user.id}`;
children.dirs[t('projects')] = `projects`;
children.dirs[t('companies')] = `company`;
} else {
const url = api(`files${path}`);
const res = await fetch(url,{credentials:'include'});
if (res.ok){
} else {
error(res);
}
}
}
function onclick(ev){
ev.preventDefault();
ev.stopPropagation();
var target = ev.target;
while (target && !target.href) target=target.parentNode;
let href = target.getAttribute('href');
if (href) {
router.navigate(href);
loadChildren(href);
}
return false;
}
onMount(() => loadChildren(window.location.pathname));
</script>
<h1>{t('files')}</h1>
<h1>{t('files')} {router.path}</h1>
{#if children?.dirs}
<ul>
{#each Object.entries(children.dirs) as [k,v]}
<li>
<a href={router.fullPath+'/'+v} {onclick}>{k}</a>
</li>
{/each}
</ul>
{/if}