Make route organization RESTful

This commit is contained in:
Alexis Sellier
2021-05-19 12:15:49 +02:00
parent 73b00be0af
commit b61c336dca
19 changed files with 66 additions and 43 deletions
+42
View File
@@ -0,0 +1,42 @@
<script lang="typescript">
import { onMount } from 'svelte';
import { ethers } from 'ethers';
import { navigate } from 'svelte-routing';
import type { Config } from '@app/config';
import * as utils from '@app/utils';
import Error from '@app/Error.svelte';
export let config: Config;
export let query: string | null;
let error = false;
onMount(() => {
if (query) {
if (ethers.utils.isAddress(query)) {
// Go to org.
navigate(`/orgs/${query}`, { replace: true });
} else if (utils.isRadicleId(query)) {
// Go to Radicle entity.
alert("Radicle IDs are not yet supported");
} else {
let label = utils.parseEnsLabel(query, config);
if (label.includes(".")) {
error = true;
} else {
navigate(`/registrations/${label}`, { replace: true });
}
}
} else {
navigate('/');
}
});
</script>
<main>
{#if error}
<Error on:close={() => navigate('/')}>
Invalid query string “{query}”
</Error>
{/if}
</main>
+12
View File
@@ -0,0 +1,12 @@
<script lang="typescript">
import { Route } from "svelte-routing";
import Resolve from '@app/base/resolver/Query.svelte';
import type { Config } from '@app/config';
import * as utils from '@app/utils';
export let config: Config;
</script>
<Route path="/resolver/query" let:location>
<Resolve {config} query={utils.getSearchParam("q", location)} />
</Route>