mirror of
https://github.com/aljazceru/hypergolic.git
synced 2025-12-18 22:14:21 +01:00
problem: can't create new rockets
This commit is contained in:
@@ -13,6 +13,9 @@ The commit message MUST be a short summary of the problem being solved, usually
|
||||
## Style Guide
|
||||
Avoid uneccessary whitespace changes. Whitespace changes make it difficult to see what code was really changed.
|
||||
|
||||
## UX Library
|
||||
https://www.shadcn-svelte.com/docs
|
||||
|
||||
## Getting Paid
|
||||
If you want to get paid for working on this project, demonstrate your capability by solving some problems and adhering to the instructions in this readme. After you have 2-3 PR's merged, DM gsovereignty on nostr to have a conversation about paid work.
|
||||
|
||||
|
||||
68
src/components/CreateNewRocket.svelte
Normal file
68
src/components/CreateNewRocket.svelte
Normal file
@@ -0,0 +1,68 @@
|
||||
<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';
|
||||
|
||||
let name:string;
|
||||
|
||||
function publish(ndk: NDKSvelte, name: string) {
|
||||
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 = 31108;
|
||||
e.created_at = Math.floor(new Date().getTime() / 1000);
|
||||
//todo validate d tag
|
||||
e.tags.push(["d", name])
|
||||
e.tags.push(["ruleset", "334000"])
|
||||
e.publish().then((x)=>{
|
||||
console.log(x)
|
||||
goto(`${base}/rockets/${getRocketURL(e)}`)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog.Root>
|
||||
<Dialog.Trigger class={buttonVariants({ variant: 'default' })}>Create a Rocket</Dialog.Trigger>
|
||||
<Dialog.Content class="sm:max-w-[425px]">
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>Name Your Rocket</Dialog.Title>
|
||||
{#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.Description>Choose a name for your new Rocket and click Publish</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="Name-of-your-rocket" class="col-span-3" />
|
||||
</div>
|
||||
</div>
|
||||
<Todo text={['validate input is a valid d tag (NIP01)']} />
|
||||
<Dialog.Footer>
|
||||
<Button on:click={()=>{publish($ndk, name)}} type="submit">Publish</Button>
|
||||
</Dialog.Footer>
|
||||
</Dialog.Content>
|
||||
</Dialog.Root>
|
||||
35
src/components/Login.svelte
Normal file
35
src/components/Login.svelte
Normal file
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
import { ndk } from "$lib/ndk";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { NDKNip07Signer } from "@nostr-dev-kit/ndk";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
onMount(() => {
|
||||
if (localStorage.getItem("signed-in")) {
|
||||
nip07();
|
||||
}
|
||||
})
|
||||
|
||||
async function nip07() {
|
||||
document.body.appendChild(document.createElement('script')).src = 'https://unpkg.com/window.nostr.js/dist/window.nostr.js';
|
||||
|
||||
try {
|
||||
|
||||
const signer = new NDKNip07Signer();
|
||||
const user = await signer.blockUntilReady();
|
||||
|
||||
if (user) {
|
||||
$ndk.signer = signer;
|
||||
$ndk = $ndk
|
||||
localStorage.setItem("signed-in", "true");
|
||||
}
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{#if !$ndk.signer}
|
||||
<Button on:click={nip07}>
|
||||
<span class="hidden sm:block">Sign in</span>
|
||||
</Button>
|
||||
{/if}
|
||||
@@ -3,30 +3,19 @@
|
||||
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 rocketEvent: NDKEvent;
|
||||
//$page.url.searchParams.get("tab")
|
||||
function getRocketURL(e:NDKEvent):string {
|
||||
|
||||
let ignitionID = undefined;
|
||||
if (e.getMatchingTags('ignition') && e.getMatchingTags('ignition')[0] && e.getMatchingTags('ignition')[0][1]) {
|
||||
ignitionID = e.getMatchingTags('ignition')[0][1]
|
||||
}
|
||||
if (!ignitionID) {
|
||||
ignitionID = e.id
|
||||
}
|
||||
let d = e.getMatchingTags('d')[0][1]
|
||||
let p = e.pubkey
|
||||
return `${ignitionID}?d=${d}&p=${p}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<Card.Root class="w-[350px]">
|
||||
<Card.Header>
|
||||
<Card.Title>{rocketEvent.getMatchingTags('d')[0][1]}</Card.Title>
|
||||
<Card.Description>{rocketEvent.getMatchingTags('mission')[0][1]}</Card.Description>
|
||||
<Card.Description>{getMission(rocketEvent)}</Card.Description>
|
||||
</Card.Header>
|
||||
<Card.Content></Card.Content>
|
||||
<Card.Footer class="flex justify-between">
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
import NewMenu from '../components/Menu.svelte';
|
||||
import RocketPillCard from '../components/RocketPillCard.svelte';
|
||||
import { base } from '$app/paths';
|
||||
import Login from '../components/Login.svelte';
|
||||
|
||||
export let title = '';
|
||||
</script>
|
||||
@@ -86,6 +87,7 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<Login />
|
||||
<DropdownMenu.Root>
|
||||
<DropdownMenu.Trigger asChild let:builder>
|
||||
<Button builders={[builder]} variant="secondary" size="icon" class="rounded-full">
|
||||
|
||||
22
src/lib/helpers.ts
Normal file
22
src/lib/helpers.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
|
||||
export function getRocketURL(e:NDKEvent):string {
|
||||
|
||||
let ignitionID = undefined;
|
||||
if (e.getMatchingTags('ignition') && e.getMatchingTags('ignition')[0] && e.getMatchingTags('ignition')[0][1]) {
|
||||
ignitionID = e.getMatchingTags('ignition')[0][1]
|
||||
}
|
||||
if (!ignitionID) {
|
||||
ignitionID = e.id
|
||||
}
|
||||
let d = e.getMatchingTags('d')[0][1]
|
||||
let p = e.pubkey
|
||||
return `${ignitionID}?d=${d}&p=${p}`
|
||||
}
|
||||
|
||||
export function getMission(rocketEvent:NDKEvent):string {
|
||||
if (rocketEvent.getMatchingTags('mission') && rocketEvent.getMatchingTags('mission')[0] && rocketEvent.getMatchingTags('mission')[0][1]) {
|
||||
return rocketEvent.getMatchingTags('mission')[0][1]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const _ndk = new NDKSvelte({
|
||||
'wss://purplepag.es',
|
||||
'wss://relay.nostr.band',
|
||||
'wss://nos.lol',
|
||||
'wss://relay.nostrocket.org'
|
||||
//'wss://relay.nostrocket.org'
|
||||
],
|
||||
enableOutboxModel: false,
|
||||
clientName: 'nostrocket'
|
||||
|
||||
@@ -6,6 +6,7 @@ export const currentUser = writable<NDKUser | undefined>(undefined);
|
||||
|
||||
export async function prepareUserSession(ndk: NDKSvelte, user: NDKUser): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
//implement any session set up stuff here
|
||||
});
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
import * as Card from '$lib/components/ui/card/index.js';
|
||||
import { Switch } from '$lib/components/ui/switch/index.js';
|
||||
import { base } from '$app/paths';
|
||||
import CreateNewRocket from '../../components/CreateNewRocket.svelte';
|
||||
|
||||
const notifications = [
|
||||
{
|
||||
@@ -93,7 +94,7 @@
|
||||
</div>
|
||||
</Card.Content>
|
||||
<Card.Footer>
|
||||
<Button class="w-full">Create a Rocket Now</Button>
|
||||
<CreateNewRocket />
|
||||
</Card.Footer>
|
||||
</Card.Root>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user