This commit is contained in:
Ren Amamiya
2023-06-26 21:08:36 +07:00
parent b2dd231f00
commit 2f553d8039
13 changed files with 192 additions and 161 deletions

View File

@@ -1,12 +1,10 @@
import { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { usePublish } from "@libs/ndk";
import { Button } from "@shared/button";
import { ImageUploader } from "@shared/composer/imageUploader";
import { TrashIcon } from "@shared/icons";
import { MentionNote } from "@shared/notes/mentions/note";
import { RelayContext } from "@shared/relayProvider";
import { useComposer } from "@stores/composer";
import { dateToUnix } from "@utils/date";
import { useCallback, useContext, useMemo, useState } from "react";
import { useCallback, useMemo, useState } from "react";
import { Node, Transforms, createEditor } from "slate";
import { withHistory } from "slate-history";
import {
@@ -61,7 +59,7 @@ const ImagePreview = ({
};
export function Post({ pubkey, privkey }: { pubkey: string; privkey: string }) {
const ndk = useContext(RelayContext);
const publish = usePublish();
const [repost, toggle] = useComposer((state: any) => [
state.repost,
state.toggle,
@@ -86,29 +84,24 @@ export function Post({ pubkey, privkey }: { pubkey: string; privkey: string }) {
}, []);
const submit = () => {
// serialize content
const serializedContent = serialize(content);
const signer = new NDKPrivateKeySigner(privkey);
ndk.signer = signer;
const event = new NDKEvent(ndk);
event.content = serializedContent;
event.created_at = dateToUnix();
event.pubkey = pubkey;
let tags: string[][] = [];
let kind: number;
if (repost.id && repost.pubkey) {
event.kind = 6;
event.tags = [
kind = 6;
tags = [
["e", repost.id],
["p", repost.pubkey],
];
} else {
event.kind = 1;
event.tags = [];
kind = 1;
tags = [];
}
// publish event
event.publish();
// serialize content
const serializedContent = serialize(content);
// publish message
publish({ content: serializedContent, kind, tags });
// close modal
toggle(false);

View File

@@ -34,7 +34,10 @@ export function LinkPreview({ urls }: { urls: string[] }) {
) : (
<>
<Image
src={data.images[0]}
src={
data.images?.[0] ||
"https://void.cat/d/XTmrMkpid8DGLjv1AzdvcW"
}
fallback="https://void.cat/d/XTmrMkpid8DGLjv1AzdvcW"
alt={urls[0]}
className="w-full h-44 object-cover rounded-t-lg"

View File

@@ -1,15 +1,13 @@
import { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { usePublish } from "@libs/ndk";
import { Button } from "@shared/button";
import { Image } from "@shared/image";
import { RelayContext } from "@shared/relayProvider";
import { DEFAULT_AVATAR } from "@stores/constants";
import { dateToUnix } from "@utils/date";
import { useAccount } from "@utils/hooks/useAccount";
import { useProfile } from "@utils/hooks/useProfile";
import { useContext, useState } from "react";
import { useState } from "react";
export function NoteReplyForm({ id }: { id: string }) {
const ndk = useContext(RelayContext);
const publish = usePublish();
const { account } = useAccount();
const { status, user } = useProfile(account.npub);
@@ -17,19 +15,10 @@ export function NoteReplyForm({ id }: { id: string }) {
const [value, setValue] = useState("");
const submitEvent = () => {
const signer = new NDKPrivateKeySigner(account.privkey);
ndk.signer = signer;
const event = new NDKEvent(ndk);
// build event
event.content = value;
event.kind = 1;
event.created_at = dateToUnix();
event.pubkey = account.pubkey;
event.tags = [["e", id]];
const tags = [["e", id]];
// publish event
event.publish();
publish({ content: value, kind: 1, tags });
// reset form
setValue("");

View File

@@ -46,7 +46,7 @@ export function User({
</Popover.Button>
<div className="flex flex-wrap items-baseline gap-1">
<h5
className={`text-zinc-200 font-medium leading-none truncate ${
className={`text-zinc-100 font-semibold leading-none truncate ${
size === "small" ? "max-w-[7rem]" : "max-w-[10rem]"
}`}
>