/
test.tsx
50 lines (44 loc) · 1.28 KB
/
test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { useRef } from "react";
import { useNostrEvents, dateToUnix, useProfile } from "nostr-react";
import PostButton from "@/components/PostButton";
import { nip19 } from "nostr-tools";
const Test = () => {
const now = useRef(new Date()); // Make sure current time isn't re-rendered
const { events } = useNostrEvents({
filter: {
since: dateToUnix(now.current), // all new events from now
kinds: [1],
},
});
const { data: npub } = nip19.decode(
"npub1afn5vtgrygclqkpl573qcnukuyfzcnw3vg799pqw9fqtzx7dl8gseltyrs"
);
const { data: userData, isLoading } = useProfile({
pubkey: npub.toString(),
});
console.log(isLoading);
return (
<>
<div style={{ backgroundColor: "white", color: "black" }}>
<div>
<p>Name: {isLoading ? "Loading..." : userData?.name}</p>
<p>Public key: {isLoading ? "Loading..." : userData?.npub}</p>
<p>Picture URL: {isLoading ? "Loading..." : userData?.picture}</p>
</div>
<div>
<PostButton />
</div>
{userData ? (
events.map((event) => (
<p key={event.id}>
{event.pubkey} posted: {event.content}
</p>
))
) : (
<></>
)}
</div>
</>
);
};
export default Test;