Write notes

This commit is contained in:
Kieran 2022-12-28 16:29:42 +00:00
parent d2a1b7f5ac
commit 0725e84d7b
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 32 additions and 4 deletions

View File

@ -162,4 +162,17 @@ export default class Event {
ev.Content = JSON.stringify(obj);
return ev;
}
/**
* Create a new TextNote event
* @param {String} pubKey
* @param {String} message
* @returns
*/
static NewNote(pubKey, message) {
let ev = Event.ForPubKey(pubKey);
ev.Kind = EventKind.TextNote;
ev.Content = message;
return ev;
}
}

View File

@ -1,22 +1,37 @@
import "./Root.css";
import Timeline from "./Timeline";
import { useSelector } from "react-redux";
import { useContext, useState } from "react";
import Event from "../nostr/Event";
import { NostrContext } from "..";
export default function RootPage() {
const login = useSelector(s => s.login.privateKey);
const system = useContext(NostrContext);
const pubKey = useSelector(s => s.login.publicKey);
const privKey = useSelector(s => s.login.privateKey);
const [note, setNote] = useState("");
async function sendNote() {
let ev = Event.NewNote(pubKey, note);
await ev.Sign(privKey);
console.debug("Sending note: ", ev);
system.BroadcastEvent(ev);
setNote("");
}
function noteSigner() {
return (
<div className="send-note">
<input type="text" placeholder="Sup?"></input>
<div className="btn">Send</div>
<input type="text" placeholder="Sup?" value={note} onChange={(e) => setNote(e.target.value)}></input>
<div className="btn" onClick={() => sendNote()}>Send</div>
</div>
);
}
return (
<>
{login ? noteSigner() : null}
{pubKey ? noteSigner() : null}
<Timeline></Timeline>
</>
);