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;
|
|
|
|
let latestFiles: IFile[] = [];
|
|
|
|
|
|
|
|
fetch("/api/info").then(async (response) => {
|
|
|
|
infoData = await response.json();
|
|
|
|
});
|
|
|
|
|
|
|
|
fetch("/api/files/latest").then(async (response) => {
|
|
|
|
latestFiles = await response.json();
|
|
|
|
});
|
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-15 19:38:25 +01:00
|
|
|
|
2021-11-11 23:37:42 +01:00
|
|
|
{#if latestFiles}
|
|
|
|
<section class="latest">
|
|
|
|
<h2>Most recently added files</h2>
|
2021-12-15 19:38:25 +01:00
|
|
|
<table>
|
2021-11-11 23:37:42 +01:00
|
|
|
{#each latestFiles 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-11-11 23:37:42 +01:00
|
|
|
</section>
|
|
|
|
{/if}
|
|
|
|
</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 {
|
|
|
|
border-spacing: 1em .25em;
|
|
|
|
}
|
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-11-11 23:37:42 +01:00
|
|
|
</style>
|