2023-06-30 14:05:57 +00:00
|
|
|
/** @jsx h */
|
2023-09-06 16:29:27 +00:00
|
|
|
import { h, render } from "https://esm.sh/preact@10.17.1";
|
2023-06-30 14:05:57 +00:00
|
|
|
import { Editor } from "./editor.tsx";
|
2023-09-11 15:27:38 +00:00
|
|
|
import { testEventBus } from "./_setup.test.ts";
|
2024-03-23 08:15:56 +00:00
|
|
|
import { InMemoryAccountContext, NostrKind } from "../../libs/nostr.ts/nostr.ts";
|
|
|
|
import { NewIndexedDB } from "./dexie-db.ts";
|
|
|
|
import { Database_View } from "../database.ts";
|
|
|
|
import { prepareEncryptedNostrEvent } from "../../libs/nostr.ts/event.ts";
|
|
|
|
import { fail } from "https://deno.land/std@0.176.0/testing/asserts.ts";
|
|
|
|
import { NostrEvent } from "../../libs/nostr.ts/nostr.ts";
|
|
|
|
|
|
|
|
const indexedDB = NewIndexedDB();
|
|
|
|
if (indexedDB instanceof Error) {
|
|
|
|
fail(indexedDB.message);
|
|
|
|
}
|
|
|
|
const database = await Database_View.New(indexedDB, indexedDB, indexedDB);
|
|
|
|
|
|
|
|
const ctx = InMemoryAccountContext.Generate();
|
|
|
|
const e = await database.addEvent(
|
|
|
|
await prepareEncryptedNostrEvent(ctx, {
|
|
|
|
encryptKey: ctx.publicKey,
|
|
|
|
kind: NostrKind.DIRECT_MESSAGE,
|
|
|
|
tags: [["p", InMemoryAccountContext.Generate().publicKey.hex]],
|
|
|
|
content: "hi",
|
|
|
|
}) as NostrEvent,
|
|
|
|
);
|
|
|
|
if (!e || e instanceof Error) {
|
|
|
|
fail();
|
|
|
|
}
|
2023-06-30 14:05:57 +00:00
|
|
|
|
|
|
|
let vdom = (
|
2023-12-22 06:55:15 +00:00
|
|
|
<div class="border">
|
|
|
|
<Editor
|
2024-03-27 07:38:12 +00:00
|
|
|
replyTo={{
|
|
|
|
eventID: e.id,
|
|
|
|
onEventIDChange: (id) => {
|
|
|
|
console.log(`onReplyToEventIDChange: ${id}`);
|
|
|
|
},
|
|
|
|
}}
|
2023-12-22 06:55:15 +00:00
|
|
|
placeholder="Message @xxx"
|
|
|
|
maxHeight="50vh"
|
|
|
|
emit={testEventBus.emit}
|
2024-03-23 08:15:56 +00:00
|
|
|
getters={{
|
|
|
|
profileGetter: database,
|
|
|
|
getEventByID: database.getEventByID,
|
|
|
|
}}
|
2023-12-22 06:55:15 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2023-06-30 14:05:57 +00:00
|
|
|
);
|
|
|
|
render(vdom, document.body);
|