chore: small fixes

This commit is contained in:
2024-01-11 07:56:28 +07:00
parent a5ad4fe05c
commit a8cd34d998
14 changed files with 54 additions and 35 deletions

View File

@@ -389,14 +389,11 @@ export class Ark {
signal?: AbortSignal;
dedup?: boolean;
}) {
const rootIds = new Set();
const dedupQueue = new Set();
const connectedRelays = this.ndk.pool
.connectedRelays()
.map((item) => item.url);
const seenIds = new Set<string>();
const dedupQueue = new Set<string>();
const events = await this.#fetcher.fetchLatestEvents(
connectedRelays,
this.#storage.account.relayList,
filter,
limit,
{
@@ -411,17 +408,19 @@ export class Ark {
if (dedup) {
for (const event of ndkEvents) {
const tags = event.tags.filter((el) => el[0] === "e");
const tags = event.tags
.filter((el) => el[0] === "e")
?.map((item) => item[1]);
if (tags && tags.length > 0) {
const rootId = tags.filter((el) => el[3] === "root")[1] ?? tags[0][1];
if (tags.length) {
for (const tag of tags) {
if (seenIds.has(tag)) {
dedupQueue.add(event.id);
break;
}
if (rootIds.has(rootId)) {
dedupQueue.add(event.id);
break;
seenIds.add(tag);
}
rootIds.add(rootId);
}
}

View File

@@ -19,6 +19,10 @@ export function NoteReply() {
type="button"
onClick={() => {
setEditorValue([
{
type: "paragraph",
children: [{ text: "" }],
},
{
type: "event",
// @ts-expect-error, useless

View File

@@ -1,4 +1,4 @@
import { RepostIcon } from "@lume/icons";
import { LoaderIcon, RepostIcon } from "@lume/icons";
import * as Tooltip from "@radix-ui/react-tooltip";
import { useState } from "react";
import { toast } from "sonner";
@@ -7,17 +7,25 @@ import { useNoteContext } from "../provider";
export function NoteRepost() {
const event = useNoteContext();
const [loading, setLoading] = useState(false);
const [isRepost, setIsRepost] = useState(false);
const submit = async () => {
try {
setLoading(true);
// repost
await event.repost(true);
// update state
setLoading(false);
setIsRepost(true);
// notify
toast.success("You've reposted this post successfully");
} catch (e) {
setLoading(false);
toast.error("Repost failed, try again later");
}
};
@@ -31,12 +39,16 @@ export function NoteRepost() {
onClick={submit}
className="inline-flex items-center justify-center group h-7 w-7 text-neutral-600 dark:text-neutral-400"
>
<RepostIcon
className={twMerge(
"size-5 group-hover:text-blue-600",
isRepost ? "text-blue-500" : "",
)}
/>
{loading ? (
<LoaderIcon className="size-4 animate-spin" />
) : (
<RepostIcon
className={twMerge(
"size-5 group-hover:text-blue-600",
isRepost ? "text-blue-500" : "",
)}
/>
)}
</button>
</Tooltip.Trigger>
<Tooltip.Portal>

View File

@@ -107,13 +107,13 @@ export function NoteZap() {
<Dialog.Trigger asChild>
<button
type="button"
className="inline-flex items-center justify-center group h-7 w-7 text-neutral-600 dark:text-neutral-400"
className="inline-flex items-center justify-center group size-7 text-neutral-600 dark:text-neutral-400"
>
<ZapIcon className="size-5 group-hover:text-blue-500" />
</button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/20 backdrop-blur-sm dark:bg-black/20" />
<Dialog.Overlay className="fixed inset-0 z-50 bg-black/20 backdrop-blur-xl dark:bg-white/20" />
<Dialog.Content className="fixed inset-0 z-50 flex items-center justify-center min-h-full">
<div className="relative w-full max-w-xl bg-white h-min rounded-xl dark:bg-black">
<div className="inline-flex items-center justify-between w-full px-5 py-3 shrink-0">

View File

@@ -40,7 +40,6 @@ export function Reply({
) : null}
<div className="inline-flex items-center gap-10">
<Note.Reply />
<Note.Reaction />
<Note.Repost />
<Note.Zap />
</div>

View File

@@ -69,7 +69,6 @@ export function RepostNote({
<Note.Pin />
<div className="inline-flex items-center gap-10">
<Note.Reply />
<Note.Reaction />
<Note.Repost />
<Note.Zap />
</div>

View File

@@ -22,7 +22,6 @@ export function TextNote({
<Note.Pin />
<div className="inline-flex items-center gap-10">
<Note.Reply />
<Note.Reaction />
<Note.Repost />
<Note.Zap />
</div>

View File

@@ -43,7 +43,6 @@ export function ThreadNote({ eventId }: { eventId: string }) {
<Note.Pin />
<div className="inline-flex items-center gap-10">
<Note.Reply />
<Note.Reaction />
<Note.Repost />
<Note.Zap />
</div>

View File

@@ -175,6 +175,15 @@ const LumeProvider = ({ children }: PropsWithChildren<object>) => {
const contacts = await user.follows();
storage.account.contacts = [...contacts].map((user) => user.pubkey);
const relays = await user.relayList();
if (!relays) storage.account.relayList = ndk.explicitRelayUrls;
storage.account.relayList = [
...relays.readRelayUrls,
...relays.bothRelayUrls,
];
}
// init nostr fetcher