[ui] add creation from Search

feat/vaults
Tomáš Mládek 2022-01-16 19:53:40 +01:00
parent bcb73ec439
commit ead5e31d58
No known key found for this signature in database
GPG Key ID: ED21612889E75EC5
1 changed files with 60 additions and 20 deletions

View File

@ -7,6 +7,10 @@
import UpEntryDisplay from "../components/display/UpEntry.svelte"; import UpEntryDisplay from "../components/display/UpEntry.svelte";
import UpObjectDisplay from "../components/display/UpObject.svelte"; import UpObjectDisplay from "../components/display/UpObject.svelte";
import UpObjectCard from "../components/display/UpObjectCard.svelte"; import UpObjectCard from "../components/display/UpObjectCard.svelte";
import { useNavigate } from "svelte-navigator";
import type { ListingResult } from "upend/types";
const navigate = useNavigate();
export let query: string; export let query: string;
let debouncedQuery = ""; let debouncedQuery = "";
@ -54,6 +58,26 @@
} }
} }
} }
async function create() {
const response = await fetch(`/api/obj`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
attribute: "LBL",
value: {
t: "Value",
c: query,
},
}),
});
if (!response.ok) {
throw new Error(`Failed to create object: ${await response.text()}`);
}
const result = (await response.json()) as ListingResult;
const address = Object.values(result)[0].entity;
navigate(`/browse/${address}`);
}
</script> </script>
<div> <div>
@ -70,48 +94,53 @@
{/each} {/each}
</ul> </ul>
{:else} {:else}
<div class="create">Create?</div> <div class="create">
<div class="create" /> <p>Create new object?</p>
<button class="create-object" on:click={create}>"{query}"</button>
</div>
{/if} {/if}
</section> </section>
<section class="objects"> <section class="objects">
<h2>Objects</h2>
{#await objects} {#await objects}
<h2>Objects</h2>
<Spinner /> <Spinner />
{:then objects} {:then objects}
<ul> {#if objects.length}
{#each objects as address} <h2>Objects</h2>
<li> <ul>
<UpObjectDisplay {#each objects as address}
{address} <li>
on:resolved={(ids) => onResolved(address, ids.detail)} <UpObjectDisplay
/> {address}
</li> on:resolved={(ids) => onResolved(address, ids.detail)}
{/each} />
</ul> </li>
{/each}
</ul>
{/if}
{/await} {/await}
</section> </section>
{#if entries.length} <section class="raw">
<section class="raw"> {#if entries.length}
<h2>Raw results</h2> <h2>Raw results</h2>
<ul> <ul>
{#each entries as entry} {#each entries as entry}
<li><UpEntryDisplay {entry} /></li> <li><UpEntryDisplay {entry} /></li>
{/each} {/each}
</ul> </ul>
</section> {:else}
{:else} <div class="global">No results found.</div>
<div class="global">No results found.</div> {/if}
{/if} </section>
{:else} {:else}
<div class="global"> <div class="global">
<Spinner /> <Spinner />
</div> </div>
{/if} {/if}
{:else} {:else}
<div class="error"> <div class="error global">
{$error} {$error}
</div> </div>
{/if} {/if}
@ -146,6 +175,17 @@
.create { .create {
text-align: center; text-align: center;
} }
.create-object {
display: inline-block;
color: var(--foreground);
background: var(--background-lighter);
border: 1px solid var(--foreground);
border-radius: 4px;
padding: 0.2em;
font-size: 1.25em;
cursor: pointer;
}
} }
.objects { .objects {