mirror of
https://github.com/aljazceru/hypergolic.git
synced 2026-01-28 09:44:22 +01:00
problem: can't publish new products
This commit is contained in:
89
src/components/CreateNewProduct.svelte
Normal file
89
src/components/CreateNewProduct.svelte
Normal file
@@ -0,0 +1,89 @@
|
||||
<script lang="ts">
|
||||
import { Button, buttonVariants } from '$lib/components/ui/button/index.js';
|
||||
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
||||
import { Input } from '$lib/components/ui/input/index.js';
|
||||
import { Label } from '$lib/components/ui/label/index.js';
|
||||
import { ndk } from '@/ndk';
|
||||
import Todo from './Todo.svelte';
|
||||
import { currentUser } from '@/stores/session';
|
||||
import { Terminal } from 'lucide-svelte';
|
||||
import * as Alert from '@/components/ui/alert';
|
||||
import type NDKSvelte from '@nostr-dev-kit/ndk-svelte';
|
||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { getRocketURL } from '@/helpers';
|
||||
import Textarea from '@/components/ui/textarea/textarea.svelte';
|
||||
|
||||
export let rocketEvent:NDKEvent;
|
||||
|
||||
let name: string;
|
||||
let desc: string;
|
||||
let image: string;
|
||||
|
||||
function publish(ndk: NDKSvelte) {
|
||||
if (!ndk.signer) {
|
||||
throw new Error('no ndk signer found');
|
||||
}
|
||||
let e = new NDKEvent(ndk);
|
||||
let author = $currentUser;
|
||||
if (!author) {
|
||||
throw new Error('no current user');
|
||||
}
|
||||
e.author = author;
|
||||
e.kind = 1908;
|
||||
e.created_at = Math.floor(new Date().getTime() / 1000);
|
||||
//todo validate d tag
|
||||
e.tags.push(['name', name]);
|
||||
e.tags.push(['description', desc]);
|
||||
e.tags.push(['cover', image])
|
||||
e.tags.push(['a', `31108:${rocketEvent.pubkey}:${rocketEvent.dTag}`])
|
||||
e.tags.push(['ruleset', '334000']);
|
||||
console.log(e.rawEvent())
|
||||
e.publish().then((x) => {
|
||||
console.log(x);
|
||||
//goto(`${base}/rockets/${getRocketURL(e)}`);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog.Root>
|
||||
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}>Create a Product</Dialog.Trigger>
|
||||
<Dialog.Content class="sm:max-w-[425px]">
|
||||
<Todo text={["validate sane field entries", "name.length > 5 < 20", "description length > 20", "image url resolves and is image"]} />
|
||||
{#if !currentUser}
|
||||
<Alert.Root>
|
||||
<Terminal class="h-4 w-4" />
|
||||
<Alert.Title>Heads up!</Alert.Title>
|
||||
<Alert.Description>You need a nostr signing extension to use Nostrocket!</Alert.Description>
|
||||
</Alert.Root>
|
||||
{/if}
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>Publish a New Product</Dialog.Title>
|
||||
|
||||
<Dialog.Description>Create a new product listing for your Rocket!</Dialog.Description>
|
||||
</Dialog.Header>
|
||||
<div class="grid gap-4 py-4">
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label for="name" class="text-right">Name</Label>
|
||||
<Input bind:value={name} id="name" placeholder="Product Name" class="col-span-3" />
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label for="desc" class="text-right">Description</Label>
|
||||
<Textarea bind:value={desc} id="desc" placeholder="Description" class="col-span-3" />
|
||||
</div>
|
||||
<div class="grid grid-cols-4 items-center gap-4">
|
||||
<Label for="image" class="text-right">Cover Image</Label>
|
||||
<Input bind:value={image} id="name" placeholder="URL of cover image" class="col-span-3" />
|
||||
</div>
|
||||
</div>
|
||||
<Dialog.Footer>
|
||||
<Button
|
||||
on:click={() => {
|
||||
publish($ndk);
|
||||
}}
|
||||
type="submit">Publish</Button
|
||||
>
|
||||
</Dialog.Footer>
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
@@ -36,7 +36,7 @@
|
||||
<Badge class="ml-auto flex h-6 w-6 shrink-0 items-center justify-center rounded-full">6</Badge>
|
||||
</a>
|
||||
<a
|
||||
href="##"
|
||||
href="{base}/products"
|
||||
class={getClass("products")}
|
||||
>
|
||||
<Package class={iconClass} />
|
||||
|
||||
25
src/components/ProductCard.svelte
Normal file
25
src/components/ProductCard.svelte
Normal file
@@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { Button } from '$lib/components/ui/button/index.js';
|
||||
import * as Card from '$lib/components/ui/card/index.js';
|
||||
import { getMission, getRocketURL } from '@/helpers';
|
||||
import type { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||
import { ChevronRight } from 'lucide-svelte';
|
||||
|
||||
export let event: NDKEvent;
|
||||
//$page.url.searchParams.get("tab")
|
||||
|
||||
</script>
|
||||
|
||||
<Card.Root class="w-[350px]">
|
||||
<Card.Header>
|
||||
<Card.Title>{event.getMatchingTags('name')[0][1]}</Card.Title>
|
||||
<Card.Description>{getMission(event)}</Card.Description>
|
||||
</Card.Header>
|
||||
<Card.Content></Card.Content>
|
||||
<Card.Footer class="flex justify-between">
|
||||
<Button on:click={()=>{console.log(event.rawEvent())}} variant="outline">Print to Console</Button>
|
||||
<Button on:click={()=>{goto(`${base}/rockets/${getRocketURL(event)}`)}}>View Full Rocket<ChevronRight class="h-4 w-4" /></Button>
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
9
src/components/Subheading.svelte
Normal file
9
src/components/Subheading.svelte
Normal file
@@ -0,0 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let title: string;
|
||||
</script>
|
||||
|
||||
<div class="mb-4 flex items-center">
|
||||
<h1 class="scroll-m-20 text-lg font-semibold tracking-tight md:text-xl">
|
||||
{title}
|
||||
</h1>
|
||||
</div>
|
||||
Reference in New Issue
Block a user