update repost

This commit is contained in:
Ren Amamiya
2023-06-18 15:55:07 +07:00
parent 7ec284d4a5
commit d87ca7b75b
9 changed files with 79 additions and 71 deletions

View File

@@ -10,8 +10,12 @@ export function Kind1({
}: { content: any; truncate?: boolean }) {
return (
<>
<div className="select-text whitespace-pre-line break-words text-base text-zinc-100">
{truncate ? truncateContent(content.original, 100) : content.parsed}
<div
className={`select-text whitespace-pre-line break-words text-base text-zinc-100 ${
truncate ? "line-clamp-3" : ""
}`}
>
{content.parsed}
</div>
{Array.isArray(content.images) && content.images.length ? (
<ImagePreview urls={content.images} />

View File

@@ -1,49 +1,18 @@
import { NDKEvent, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { RepostIcon } from "@shared/icons";
import { RelayContext } from "@shared/relayProvider";
import { useActiveAccount } from "@stores/accounts";
import { dateToUnix } from "@utils/date";
import { useComposer } from "@stores/composer";
import { compactNumber } from "@utils/number";
import { useContext, useState } from "react";
export function NoteRepost({
id,
pubkey,
reposts,
}: { id: string; pubkey: string; reposts: number }) {
const ndk = useContext(RelayContext);
const account = useActiveAccount((state: any) => state.account);
const [count, setCount] = useState(reposts);
const submitEvent = (e: any) => {
e.stopPropagation();
const signer = new NDKPrivateKeySigner(account.privkey);
ndk.signer = signer;
const event = new NDKEvent(ndk);
// build event
event.content = "";
event.kind = 6;
event.created_at = dateToUnix();
event.pubkey = account.pubkey;
event.tags = [
["e", id],
["p", pubkey],
];
// publish event
event.publish();
// update state
setCount(count + 1);
};
const setRepost = useComposer((state: any) => state.setRepost);
return (
<button
type="button"
onClick={(e) => submitEvent(e)}
onClick={() => setRepost(id, pubkey)}
className="w-20 group inline-flex items-center gap-1.5"
>
<RepostIcon
@@ -52,7 +21,7 @@ export function NoteRepost({
className="text-zinc-400 group-hover:text-blue-400"
/>
<span className="text-base leading-none text-zinc-400 group-hover:text-zinc-100">
{compactNumber.format(count)}
{compactNumber.format(reposts)}
</span>
</button>
);