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";
|
|
|
|
import type { IFile, 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-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
|
|
|
|
|
|
|
<section class="latest">
|
|
|
|
<h2>Most recently added files</h2>
|
|
|
|
{#await latestFiles}
|
|
|
|
<sl-spinner style="font-size: 3rem; --track-width: 6px" />
|
|
|
|
{: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-11-11 23:37:42 +01:00
|
|
|
}
|
2021-12-15 19:38:25 +01:00
|
|
|
}
|
2021-12-18 15:17:36 +01:00
|
|
|
|
|
|
|
sl-spinner {
|
|
|
|
position: relative;
|
|
|
|
left: 50%;
|
|
|
|
transform: translateX(-50%);
|
|
|
|
}
|
2021-11-11 23:37:42 +01:00
|
|
|
</style>
|