Skip to content

Commit

Permalink
problem: can't easily create a new rocket
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Jan 21, 2024
1 parent 236ad8f commit 32a8362
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 108 deletions.
6 changes: 5 additions & 1 deletion src/components/elements/LoginButtonWithError.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { InlineNotification } from "carbon-components-svelte";
import LoginNip07Button from "./LoginNIP07Button.svelte";
import { currentUser } from "$lib/stores/hot_resources/current-user";
export let reason:string = "";
let message = "you must login to proceed"
Expand All @@ -9,4 +10,7 @@
message = "you must login to " + reason
}}
</script>
<InlineNotification kind="info-square" lowContrast title="NOTICE" subtitle={message}><span style="position:absolute;top:8px;right:8px;"><LoginNip07Button /></span></InlineNotification>

{#if !$currentUser}
<InlineNotification kind="info-square" lowContrast title="NOTICE" subtitle={message}><span style="position:absolute;top:8px;right:8px;"><LoginNip07Button /></span></InlineNotification>
{/if}
17 changes: 10 additions & 7 deletions src/components/novoproblems/ProblemView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,20 @@
<Column noGutterRight lg={12}
><Tile>
{#if $selectedTab == "problem"}
<InlineNotification
kind="info-square"
title="TLDR"
lowContrast
subtitle={problem.Summary}
/>
{#if problem.Summary}{#if problem.Summary.length > 0}
<InlineNotification
kind="info-square"
title="TLDR"
lowContrast
subtitle={problem.Summary}
/>{/if}{/if}

<ProblemBody {problem} />
{/if}
{#if $selectedTab == "sub-problems"}
{#each problem.FullChildren as child}
<Tile light
<Tile
light
style="margin-top:2px;cursor:pointer;"
on:click={() => {
goto(
Expand Down
107 changes: 107 additions & 0 deletions src/components/rockets/NewRocketTile.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<script lang="ts">
import { currentUser } from "$lib/stores/hot_resources/current-user";
import {
Button,
Column,
InlineNotification,
Row,
TextInput,
Tile,
} from "carbon-components-svelte";
import { Rocket as RocketIcon, SendFilled } from "carbon-icons-svelte";
import CommentUser from "../comments/CommentUser.svelte";
import { nostrocketIgnitionEvent, rocketNameValidator } from "../../settings";
import { nameIsUnique } from "$lib/stores/nostrocket_state/hard_state/rockets";
import LoginButtonWithError from "../elements/LoginButtonWithError.svelte";
import { consensusTipState } from "$lib/stores/nostrocket_state/master_state";
import { derived } from "svelte/store";
import { Rocket } from "$lib/stores/nostrocket_state/types";
import { Create1031FromRocket } from "$lib/helpers/rockets";
import { goto } from "$app/navigation";
import { base } from "$app/paths";
$: nameInvalid = false;
$: nameError = "";
let newRocket = new Rocket();
$: {
if (newRocket.Name) {
if (!rocketNameValidator.test(newRocket.Name)) {
nameInvalid = true;
nameError = "Rocket names MUST be 5-20 alphanumeric characters";
} else if (!nameIsUnique(newRocket.Name)) {
nameInvalid = true;
nameError = "Rocket names MUST be unique";
} else {
nameInvalid = false;
nameError = "";
}
}
}
let nostrocket = derived(consensusTipState, ($cts) => {
return $cts.RocketMap.get(nostrocketIgnitionEvent);
});
let currentUserIsInTree = derived(
[nostrocket, currentUser],
([$nr, $currentUser]) => {
if ($currentUser && $nr) {
return $nr.isParticipant($currentUser.pubkey);
}
return false;
}
);
function publishNewRocket(r: Rocket) {
let e = Create1031FromRocket(r);
e.publish()
.then((result) => {
console.log(result);
goto(`${base}/${r.Name}`)
})
.catch((error) => {
console.log(error);
});
}
</script>

<Tile style="padding:0;margin-top:6px;">
<Column lg={8}>
<Row
><Column noGutterRight
><TextInput
placeholder="Name Your Rocket!"
invalid={nameInvalid}
invalidText={nameError}
bind:value={newRocket.Name}
/></Column
><Column noGutterLeft
><Button
disabled={nameInvalid}
icon={SendFilled}
size="field"
on:click={() => {
publishNewRocket(newRocket);
}}>PUBLISH</Button
></Column
></Row
></Column
>
<Row>
<Column lg={5}
><Tile>
{#if newRocket.Name.length > 0}<h3>{newRocket.Name}</h3>
{#if $currentUser}<CommentUser pubkey={$currentUser?.pubkey} />{/if}
<LoginButtonWithError />
{#if !$currentUserIsInTree}<InlineNotification
lowContrast
kind="warning"
title="NOTICE"
subtitle="You must be in the Identity Tree to create a new Rocket!"
/>{/if}
{/if}
</Tile>
</Column>
</Row>
</Tile>
Loading

0 comments on commit 32a8362

Please sign in to comment.