-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa83161
commit bb9cafa
Showing
5 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<script lang="ts"> | ||
import makeEvent from "$lib/helpers/eventMaker"; | ||
import { rocketNameValidator, simulateEvents } from "../../settings"; | ||
import { currentUser } from "$lib/stores/hot_resources/current-user"; | ||
import { Button, Form, Modal, TextInput } from "carbon-components-svelte"; | ||
import { Rocket } from "carbon-pictograms-svelte"; | ||
import LoginNip07Button from "../elements/LoginNIP07Button.svelte"; | ||
let formOpen = false; | ||
let rocketName = ""; | ||
let formValidation = true; | ||
let nameError = ""; | ||
let nameInvalid = false; | ||
function reset() { | ||
rocketName = ""; | ||
nameError = ""; | ||
} | ||
function onFormSubmit() { | ||
let e = makeEvent({kind:5}) | ||
e.tags.push(["e", rocketName]); | ||
if (!simulateEvents) { | ||
e.publish() | ||
.then((x) => { | ||
console.log(e.rawEvent()); | ||
console.log("published to:", x); | ||
formOpen = false; | ||
reset(); | ||
}) | ||
.catch(() => console.log("failed to publish")); | ||
} else { | ||
console.log("simulation mode, not publishing events"); | ||
e.sign().then(() => { | ||
console.log(e.rawEvent()); | ||
formOpen = false; | ||
reset(); | ||
}); | ||
} | ||
} | ||
function onFormOpen() { | ||
// Hack form assocation | ||
const modal = document.querySelector(".bx--modal"); | ||
const form = modal.querySelector("form"); | ||
const button = modal.querySelector(".bx--btn--primary"); | ||
const id = "I" + Math.random().toString().substring(2); | ||
form.setAttribute("id", id); | ||
button.setAttribute("form", id); | ||
// Reverted by binding update on input change | ||
button.setAttribute("type", "submit"); | ||
} | ||
</script> | ||
|
||
<Button | ||
icon={Rocket} | ||
on:click={() => { | ||
formOpen = true; | ||
}}>Delete an event (kind 5)</Button | ||
> | ||
|
||
<Modal | ||
bind:open={formOpen} | ||
shouldSubmitOnEnter={false} | ||
primaryButtonText="Let's Fucking Go" | ||
secondaryButtonText="Cancel" | ||
primaryButtonIcon={Rocket} | ||
selectorPrimaryFocus=".bx--text-input" | ||
modalHeading="Launch a New Rocket!" | ||
hasForm | ||
on:open={onFormOpen} | ||
on:click:button--secondary={() => (formOpen = false)} | ||
on:submit={() => (formValidation ? onFormSubmit() : null)} | ||
> | ||
<Form on:submit={onFormSubmit}> | ||
{#if !$currentUser} | ||
<LoginNip07Button /> | ||
{/if} | ||
<TextInput | ||
helperText="Use a name that describes the purpose of this new Rocket" | ||
invalid={nameInvalid} | ||
invalidText={nameError} | ||
labelText="Rocket Name" | ||
bind:value={rocketName} | ||
required | ||
/> | ||
</Form> | ||
</Modal> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters