Write notes
This commit is contained in:
@ -162,4 +162,17 @@ export default class Event {
|
|||||||
ev.Content = JSON.stringify(obj);
|
ev.Content = JSON.stringify(obj);
|
||||||
return ev;
|
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 "./Root.css";
|
||||||
import Timeline from "./Timeline";
|
import Timeline from "./Timeline";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
import { useContext, useState } from "react";
|
||||||
|
import Event from "../nostr/Event";
|
||||||
|
import { NostrContext } from "..";
|
||||||
|
|
||||||
export default function RootPage() {
|
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() {
|
function noteSigner() {
|
||||||
return (
|
return (
|
||||||
<div className="send-note">
|
<div className="send-note">
|
||||||
<input type="text" placeholder="Sup?"></input>
|
<input type="text" placeholder="Sup?" value={note} onChange={(e) => setNote(e.target.value)}></input>
|
||||||
<div className="btn">Send</div>
|
<div className="btn" onClick={() => sendNote()}>Send</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{login ? noteSigner() : null}
|
{pubKey ? noteSigner() : null}
|
||||||
<Timeline></Timeline>
|
<Timeline></Timeline>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user