Organise files more consistently

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-12-22 16:46:08 +01:00
parent e86accafae
commit caa83db480
130 changed files with 720 additions and 707 deletions
+11
View File
@@ -0,0 +1,11 @@
<script lang="ts">
import View from "@app/views/seeds/View.svelte";
export let host: string;
</script>
{#if host === "radicle.local"}
<View hostAndPort={"0.0.0.0"} />
{:else}
<View hostAndPort={host} />
{/if}
+128
View File
@@ -0,0 +1,128 @@
<script lang="ts">
import type { Stats } from "@app/lib/seed";
import type { ProjectInfo } from "@app/lib/project";
import { formatSeedId, formatSeedHost, twemoji } from "@app/lib/utils";
import { Seed } from "@app/lib/seed";
import Loading from "@app/components/Loading.svelte";
import SeedAddress from "@app/components/SeedAddress.svelte";
import NotFound from "@app/components/NotFound.svelte";
import Clipboard from "@app/components/Clipboard.svelte";
import Projects from "@app/views/seeds/View/Projects.svelte";
import Async from "@app/components/Async.svelte";
import { Project } from "@app/lib/project";
import type { Host } from "@app/lib/api";
export let hostAndPort: string;
const [host, port] = hostAndPort.includes(":")
? hostAndPort.split(":")
: [hostAndPort, 8777];
const hostName = formatSeedHost(host);
const seedHost: Host = { host, port: Number(port) };
const getProjectsAndStats = async (
seed: Seed,
): Promise<{
stats: Stats;
projects: ProjectInfo[];
}> => {
const stats = await seed.getStats();
const projects = await Project.getProjects(seedHost, { perPage: 10 });
return { stats, projects };
};
</script>
<style>
main {
padding: 5rem 0;
width: 720px;
}
main > header {
display: flex;
width: 100%;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-bottom: 2rem;
}
.fields {
display: grid;
grid-template-columns: 5rem 4fr 2fr;
gap: 1rem 2rem;
margin-bottom: 2rem;
}
.fields > div {
place-self: center start;
height: 2rem;
line-height: 2rem;
}
.title {
display: flex;
align-items: center;
}
.seed-label {
display: flex;
align-items: center;
}
@media (max-width: 720px) {
main {
width: 100%;
padding: 1.5rem;
}
.fields {
grid-template-columns: 5rem auto;
}
}
</style>
<svelte:head>
<title>{hostName}</title>
</svelte:head>
{#await Seed.lookup(host, Number(port))}
<main class="layout-centered">
<Loading center />
</main>
{:then seed}
<main>
<header>
<span class="title txt-title">
<span class="txt-bold">
{hostName}
<span class="layout-desktop-inline" use:twemoji>{seed.emoji}</span>
</span>
</span>
</header>
<div class="fields">
<!-- Seed Address -->
<div class="txt-highlight">Address</div>
<SeedAddress {seed} port={seed.link.port} />
<!-- Seed ID -->
<div class="txt-highlight">Seed ID</div>
<div class="seed-label">
{formatSeedId(seed.id)}
<Clipboard small text={seed.id} />
</div>
<div class="layout-desktop" />
<!-- API Port -->
<div class="txt-highlight">API Port</div>
<div>{port}</div>
<div class="layout-desktop" />
<!-- API Version -->
<div class="txt-highlight">Version</div>
<div>{seed.version}</div>
<div class="layout-desktop" />
</div>
<!-- Seed Projects -->
<Async fetch={getProjectsAndStats(seed)} let:result>
<Projects {seed} projects={result.projects} stats={result.stats} />
</Async>
</main>
{:catch}
<NotFound
title={host}
subtitle="Not able to query information from this seed." />
{/await}
+80
View File
@@ -0,0 +1,80 @@
<script lang="ts">
import type { Profile } from "@app/lib/profile";
import type { ProjectInfo } from "@app/lib/project";
import type { Seed, Stats } from "@app/lib/seed";
import * as proj from "@app/lib/project";
import * as router from "@app/lib/router";
import List from "@app/components/List.svelte";
import Widget from "@app/views/projects/Widget.svelte";
export let seed: Seed;
export let profile: Profile | null = null;
export let projects: proj.ProjectInfo[];
export let stats: Stats;
// A pointer to the current page of projects added to the listing
let page = 0;
const fetchMoreProjects = async (): Promise<proj.ProjectInfo[]> => {
try {
stats = await seed.getStats();
const projects = await proj.Project.getProjects(seed.api, {
perPage: 10,
page: (page += 1),
});
if (projects.length > 0) {
return projects;
}
} catch (e) {
console.error(e);
}
// We return an empty array, for when no more projects are found, or an error is thrown
// since List is looking for an iterable.
return [];
};
const onClick = (project: ProjectInfo) => {
router.push({
resource: "projects",
params: {
view: { resource: "tree" },
urn: project.urn,
seed: seed.api.port
? `${seed.api.host}:${seed.api.port}`
: seed.api.host,
profile: profile?.name ?? profile?.address,
revision: project.head ?? undefined,
hash: undefined,
search: undefined,
},
});
};
</script>
<style>
.projects {
margin-top: 1rem;
}
.projects .project {
margin-bottom: 0.5rem;
}
</style>
<div class="projects">
<List
bind:items={projects}
complete={projects.length === stats.projects.count}
query={fetchMoreProjects}>
<svelte:fragment slot="list" let:items>
{#each items as project}
{#if project.head}
<div class="project">
<Widget {project} {seed} on:click={() => onClick(project)} />
</div>
{/if}
{/each}
</svelte:fragment>
</List>
</div>