implement parseTextNote

This commit is contained in:
Shusui MOYATANI
2023-02-21 20:39:37 +09:00
parent 2aa85b3ed9
commit 57969c2c09
20 changed files with 605 additions and 79 deletions

View File

@@ -6,8 +6,10 @@ import NotePostForm from '@/components/NotePostForm';
import SideBar from '@/components/SideBar';
import TextNote from '@/components/TextNote';
import useCommands from '@/clients/useCommands';
import useConfig from '@/clients/useConfig';
import useSubscription from '@/clients/useSubscription';
import useShortcutKeys from '@/hooks/useShortcutKeys';
import useFollowings from '@/clients/useFollowings';
/*
type UseRelayProps = { pubkey: string };
@@ -21,61 +23,57 @@ const publish = async (pool, event) => {
*/
// const relays = ['ws://localhost:8008'];
//
// 'wss://relay.damus.io',
// 'wss://nos.lol',
// 'wss://brb.io',
// 'wss://relay.snort.social',
// 'wss://relay.current.fyi',
// 'wss://relay.nostr.wirednet.jp',
const relayUrls = ['wss://relay-jp.nostr.wirednet.jp', 'wss://nostr.h3z.jp/'];
const pubkey = 'npub1jcsr6e38dcepf65nkmrc54mu8jd8y70eael9rv308wxpwep6sxwqgsscyc';
const pubkeyHex = '96203d66276e3214ea93b6c78a577c3c9a7279f9ee7e51b22f3b8c17643a819c';
const Home: Component = () => {
useShortcutKeys({
onShortcut: (s) => console.log(s),
});
const { publishTextNote } = useCommands();
useShortcutKeys({
onShortcut: (s) => console.log(s),
});
const { events } = useSubscription({
relayUrls,
const Home: Component = () => {
const [config] = useConfig();
const commands = useCommands();
const { followings } = useFollowings(() => ({
relayUrls: config().relayUrls,
pubkey: pubkeyHex,
}));
const { events: myPosts } = useSubscription(() => ({
relayUrls: config().relayUrls,
filters: [
{
kinds: [1],
authors: [pubkeyHex],
limit: 100,
since: Math.floor(Date.now() / 1000) - 48 * 60 * 60,
},
],
});
}));
const { events: followingsPosts } = useSubscription(() => ({
relayUrls: config().relayUrls,
filters: [
{
kinds: [1],
authors: followings()?.map((f) => f.pubkey) ?? [pubkeyHex],
limit: 100,
since: Math.floor(Date.now() / 1000) - 12 * 60 * 60,
},
],
}));
const handlePost = ({ content }) => {
publishTextNote({ relayUrls, pubkey: pubkeyHex, content });
commands.publishTextNote({ relayUrls: config().relayUrls, pubkey: pubkeyHex, content });
};
return (
<div class="flex h-screen w-screen flex-row overflow-hidden">
<SideBar postForm={() => <NotePostForm onPost={handlePost} />} />
<div class="flex flex-row overflow-x-scroll">
<Column width="widest">
<For each={events()}>
{(ev) => <TextNote content={ev.content} createdAt={new Date(ev.created_at * 1000)} />}
</For>
<div class="flex flex-row overflow-y-hidden overflow-x-scroll">
<Column name="ホーム" width="widest">
<For each={followingsPosts()}>{(ev) => <TextNote event={ev} />}</For>
</Column>
<Column width="medium">
<For each={events()}>
{(ev) => <TextNote content={ev.content} createdAt={new Date(ev.created_at * 1000)} />}
</For>
</Column>
<Column width="narrow">
<For each={events()}>
{(ev) => <TextNote content={ev.content} createdAt={new Date(ev.created_at * 1000)} />}
</For>
</Column>
<Column width="narrow">
<For each={events()}>
{(ev) => <TextNote content={ev.content} createdAt={new Date(ev.created_at * 1000)} />}
</For>
<Column name="自分の投稿" width="medium">
<For each={myPosts()}>{(ev) => <TextNote event={ev} />}</For>
</Column>
</div>
</div>