2021-11-11 23:37:42 +01:00
|
|
|
<script lang="ts">
|
2021-12-15 19:38:25 +01:00
|
|
|
import { formatRelative, parseISO } from "date-fns";
|
|
|
|
|
2021-11-11 23:37:42 +01:00
|
|
|
import { Link } from "svelte-navigator";
|
2021-12-19 11:46:40 +01:00
|
|
|
import { UpListing } from "upend";
|
|
|
|
import type { IFile, ListingResult, VaultInfo } from "upend/types";
|
2021-12-15 19:38:25 +01:00
|
|
|
|
2021-11-11 23:37:42 +01:00
|
|
|
let infoData: VaultInfo | undefined;
|
|
|
|
|
|
|
|
fetch("/api/info").then(async (response) => {
|
|
|
|
infoData = await response.json();
|
|
|
|
});
|
|
|
|
|
2021-12-19 11:46:40 +01:00
|
|
|
const roots = (async () => {
|
|
|
|
const response = await fetch("/api/hier_roots");
|
|
|
|
const data = (await response.json()) as ListingResult;
|
|
|
|
const listing = new UpListing(data);
|
2021-12-19 19:20:09 +01:00
|
|
|
return Object.values(listing.objects).filter((obj) =>
|
|
|
|
Boolean(obj.attr["LBL"])
|
|
|
|
);
|
2021-12-19 11:46:40 +01:00
|
|
|
})();
|
|
|
|
|
2021-12-18 15:17:36 +01:00
|
|
|
const latestFiles = (async () => {
|
|
|
|
const response = await fetch("/api/files/latest");
|
|
|
|
return (await response.json()) as IFile[];
|
|
|
|
})();
|
2021-12-15 19:38:25 +01:00
|
|
|
|
|
|
|
function fmtDate(dateString: string) {
|
|
|
|
const date = parseISO(dateString);
|
|
|
|
return formatRelative(date, new Date());
|
|
|
|
}
|
2021-11-11 23:37:42 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="home">
|
|
|
|
<h1>
|
2021-12-15 19:38:25 +01:00
|
|
|
{infoData?.name || "UpEnd"}
|
2021-11-11 23:37:42 +01:00
|
|
|
</h1>
|
2021-12-18 15:17:36 +01:00
|
|
|
|
2021-12-19 11:46:40 +01:00
|
|
|
<section class="roots">
|
|
|
|
<h2>Roots</h2>
|
|
|
|
{#await roots}
|
2021-12-20 13:41:06 +01:00
|
|
|
<sl-spinner />
|
2021-12-19 11:46:40 +01:00
|
|
|
{:then data}
|
|
|
|
<ul>
|
|
|
|
{#each data as root}
|
|
|
|
<li>
|
|
|
|
<sl-card class="root">
|
2021-12-21 12:13:46 +01:00
|
|
|
<Link class="root-link" to="/browse/{root.address}">
|
2021-12-19 19:20:09 +01:00
|
|
|
<h1>{root.identify()}</h1>
|
2021-12-21 12:13:46 +01:00
|
|
|
{#if root.get("NOTE")}
|
|
|
|
<p>{root.get("NOTE")}</p>
|
|
|
|
{/if}
|
2021-12-19 11:46:40 +01:00
|
|
|
</Link>
|
|
|
|
<div slot="footer">
|
|
|
|
{root.attr["HAS"]?.length || 0} children
|
|
|
|
</div>
|
|
|
|
</sl-card>
|
|
|
|
</li>
|
|
|
|
{:else}
|
|
|
|
<li>No roots :(</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
{/await}
|
|
|
|
</section>
|
|
|
|
|
2021-12-18 15:17:36 +01:00
|
|
|
<section class="latest">
|
|
|
|
<h2>Most recently added files</h2>
|
|
|
|
{#await latestFiles}
|
2021-12-20 13:41:06 +01:00
|
|
|
<sl-spinner />
|
2021-12-18 15:17:36 +01:00
|
|
|
{:then data}
|
2021-12-15 19:38:25 +01:00
|
|
|
<table>
|
2021-12-18 15:17:36 +01:00
|
|
|
{#each data as file}
|
2021-12-15 19:38:25 +01:00
|
|
|
<tr>
|
|
|
|
<td class="file-added">{fmtDate(file.added)}</td>
|
|
|
|
<td>
|
|
|
|
<Link to="/browse/{file.hash}">
|
|
|
|
<div class="file-path">{file.path}</div>
|
|
|
|
</Link>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2021-11-11 23:37:42 +01:00
|
|
|
{/each}
|
2021-12-15 19:38:25 +01:00
|
|
|
</table>
|
2021-12-18 15:17:36 +01:00
|
|
|
{/await}
|
|
|
|
</section>
|
2021-11-11 23:37:42 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-12-15 19:38:25 +01:00
|
|
|
h1,
|
|
|
|
h2 {
|
2021-11-11 23:37:42 +01:00
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
2021-12-15 19:38:25 +01:00
|
|
|
.latest {
|
|
|
|
table {
|
2021-12-18 15:17:36 +01:00
|
|
|
border-spacing: 1em 0.25em;
|
2021-12-15 19:38:25 +01:00
|
|
|
}
|
2021-11-11 23:37:42 +01:00
|
|
|
|
2021-12-15 19:38:25 +01:00
|
|
|
.file-added {
|
|
|
|
opacity: 0.77;
|
|
|
|
white-space: nowrap;
|
2021-12-21 12:13:46 +01:00
|
|
|
text-align: center;
|
2021-11-11 23:37:42 +01:00
|
|
|
}
|
2021-12-15 19:38:25 +01:00
|
|
|
}
|
2021-12-18 15:17:36 +01:00
|
|
|
|
2021-12-19 11:46:40 +01:00
|
|
|
.roots {
|
|
|
|
ul {
|
|
|
|
list-style: none;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0 2rem;
|
2021-12-21 12:13:46 +01:00
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
justify-content: center;
|
2021-12-19 11:46:40 +01:00
|
|
|
gap: 2rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.root {
|
|
|
|
width: 100%;
|
|
|
|
text-align: center;
|
|
|
|
}
|
2021-12-21 12:13:46 +01:00
|
|
|
|
|
|
|
:global(.root-link) {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
2021-12-19 11:46:40 +01:00
|
|
|
}
|
2021-11-11 23:37:42 +01:00
|
|
|
</style>
|