Load project meta from seed

This commit is contained in:
Alexis Sellier
2021-05-28 12:36:53 +02:00
parent b57f662dfd
commit 7f2394d9de
6 changed files with 75 additions and 4 deletions
+4
View File
@@ -249,6 +249,10 @@ input.wide {
font-weight: bold !important;
}
span.small {
font-size: 0.75rem;
}
button.error:hover {
background-color: var(--color-negative);
}
+1 -1
View File
@@ -168,7 +168,7 @@
<Loading center />
{:then projects}
{#each projects as project}
<Project {project} />
<Project {project} {config} />
{/each}
{:catch err}
<div class="error">
+29
View File
@@ -1,5 +1,34 @@
import type { Config } from '@app/config';
export interface Project {
id: string
stateHash: string
stateHashFormat: string
}
export interface User {
urn: string
avatar: { emoji: string, background: { r: number, g: number, b: number } }
}
export interface Meta {
name: string
description: string
maintainers: User[]
}
export async function getMetadata(urn: string, config: Config): Promise<Meta | null> {
const response = await fetch(`${config.seed.url}/projects/${urn}`, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
mode: 'no-cors'
});
if (! response.ok) {
return null;
}
return await response.json();
}
+36 -3
View File
@@ -1,7 +1,30 @@
<script type="typescript">
import type { Project } from './Project';
import { onMount } from 'svelte';
import type { Config } from '@app/config';
import { getMetadata } from './Project';
import type { Project, Meta } from './Project';
enum Status { Loading, Loaded, Error }
type State =
{ status: Status.Loading }
| { status: Status.Loaded, meta: Meta | null }
| { status: Status.Error, error: string };
export let project: Project;
export let config: Config;
let state: State = { status: Status.Loading };
onMount(async () => {
try {
const meta = await getMetadata(project.id, config);
state = { status: Status.Loaded, meta };
} catch (err) {
state = { status: Status.Error, error: err.message };
}
});
</script>
<style>
@@ -21,6 +44,16 @@
</style>
<article>
<div class="id">{project.id}</div>
<div class="anchor">commit {project.stateHash}</div>
{#if state.status == Status.Loaded && state.meta}
<div class="name">{state.meta.name}</div>
<div class="description">{state.meta.description}</div>
<div class="id">{project.id}</div>
<div class="anchor">commit {project.stateHash}</div>
{:else}
<div class="id">{project.id}</div>
<div class="anchor">commit {project.stateHash}</div>
{#if state.status == Status.Error}
<span class="faded small"><strong>Error</strong>: {state.error}</span>
{/if}
{/if}
</article>
+3
View File
@@ -25,5 +25,8 @@
"orgs": {
"subgraph": "https://api.thegraph.com/subgraphs/name/radicle-dev/radicle-orgs-ropsten"
}
},
"seed": {
"url": "http://sprout.radicle.xyz"
}
}
+2
View File
@@ -24,6 +24,7 @@ export class Config {
gasLimits: { createOrg: number };
provider: ethers.providers.JsonRpcProvider;
signer: ethers.Signer & TypedDataSigner | null;
seed: { url: string };
constructor(
network: { name: string, chainId: number },
@@ -46,6 +47,7 @@ export class Config {
this.provider = provider;
this.signer = signer;
this.gasLimits = gasLimits;
this.seed = config.seed;
}
}