Write notes
This commit is contained in:
parent
d2a1b7f5ac
commit
0725e84d7b
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
||||
</>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user