From ead5e31d58bb60a743c30a844e3d50284e05e7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 16 Jan 2022 19:53:40 +0100 Subject: [PATCH] [ui] add creation from Search --- webui/src/views/Search.svelte | 80 ++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/webui/src/views/Search.svelte b/webui/src/views/Search.svelte index 34766cc..f61537f 100644 --- a/webui/src/views/Search.svelte +++ b/webui/src/views/Search.svelte @@ -7,6 +7,10 @@ import UpEntryDisplay from "../components/display/UpEntry.svelte"; import UpObjectDisplay from "../components/display/UpObject.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; 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}`); + }
@@ -70,48 +94,53 @@ {/each} {:else} -
Create?
-
+
+

Create new object?

+ +
{/if}
-

Objects

{#await objects} +

Objects

{:then objects} -
    - {#each objects as address} -
  • - onResolved(address, ids.detail)} - /> -
  • - {/each} -
+ {#if objects.length} +

Objects

+
    + {#each objects as address} +
  • + onResolved(address, ids.detail)} + /> +
  • + {/each} +
+ {/if} {/await}
- {#if entries.length} -
+
+ {#if entries.length}

Raw results

    {#each entries as entry}
  • {/each}
-
- {:else} -
No results found.
- {/if} + {:else} +
No results found.
+ {/if} +
{:else}
{/if} {:else} -
+
{$error}
{/if} @@ -146,6 +175,17 @@ .create { 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 {