chore: small fixes

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

View File

@ -48,7 +48,7 @@ export function HomeScreen() {
<VList <VList
ref={ref} ref={ref}
className="h-full w-full flex-nowrap overflow-x-auto !overflow-y-hidden scrollbar-none focus:outline-none" className="h-full w-full flex-nowrap overflow-x-auto !overflow-y-hidden scrollbar-none focus:outline-none"
initialItemSize={420} itemSize={420}
tabIndex={0} tabIndex={0}
horizontal horizontal
onKeyDown={(e) => { onKeyDown={(e) => {

View File

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

View File

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

View File

@ -107,13 +107,13 @@ export function NoteZap() {
<Dialog.Trigger asChild> <Dialog.Trigger asChild>
<button <button
type="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" /> <ZapIcon className="size-5 group-hover:text-blue-500" />
</button> </button>
</Dialog.Trigger> </Dialog.Trigger>
<Dialog.Portal> <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"> <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="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"> <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} ) : null}
<div className="inline-flex items-center gap-10"> <div className="inline-flex items-center gap-10">
<Note.Reply /> <Note.Reply />
<Note.Reaction />
<Note.Repost /> <Note.Repost />
<Note.Zap /> <Note.Zap />
</div> </div>

View File

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

View File

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

View File

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

View File

@ -175,6 +175,15 @@ const LumeProvider = ({ children }: PropsWithChildren<object>) => {
const contacts = await user.follows(); const contacts = await user.follows();
storage.account.contacts = [...contacts].map((user) => user.pubkey); 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 // init nostr fetcher

View File

@ -1,11 +1,11 @@
import { Column, useStorage } from "@lume/ark"; import { Column, useStorage } from "@lume/ark";
import { TimelineIcon } from "@lume/icons"; import { TimelineIcon } from "@lume/icons";
import { IColumn } from "@lume/types"; import { IColumn } from "@lume/types";
import { EventRoute, UserRoute } from "@lume/ui";
import { NDKEvent, NDKKind } from "@nostr-dev-kit/ndk"; import { NDKEvent, NDKKind } from "@nostr-dev-kit/ndk";
import { useQueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query";
import { useRef } from "react"; import { useRef } from "react";
import { HomeRoute } from "./home"; import { HomeRoute } from "./home";
import { EventRoute, UserRoute } from "@lume/ui";
export function Timeline({ column }: { column: IColumn }) { export function Timeline({ column }: { column: IColumn }) {
const colKey = `timeline-${column.id}`; const colKey = `timeline-${column.id}`;
@ -14,11 +14,12 @@ export function Timeline({ column }: { column: IColumn }) {
const since = useRef(Math.floor(Date.now() / 1000)); const since = useRef(Math.floor(Date.now() / 1000));
const refreshTimeline = async (events: NDKEvent[]) => { const refreshTimeline = async (events: NDKEvent[]) => {
const uniqEvents = new Set(events);
await queryClient.setQueryData( await queryClient.setQueryData(
[colKey], [colKey],
(prev: { pageParams: number; pages: Array<NDKEvent[]> }) => ({ (prev: { pageParams: number; pages: Array<NDKEvent[]> }) => ({
...prev, ...prev,
pages: [[...events], ...prev.pages], pages: [[...uniqEvents], ...prev.pages],
}), }),
); );
}; };

View File

@ -17,7 +17,7 @@ export interface Account {
pubkey: string; pubkey: string;
is_active: number; is_active: number;
contacts: string[]; contacts: string[];
relayList: NDKRelayList; relayList: string[];
} }
export interface WidgetGroup { export interface WidgetGroup {

View File

@ -121,7 +121,7 @@ export function Navigation() {
: "text-black/50 dark:text-neutral-400", : "text-black/50 dark:text-neutral-400",
)} )}
> >
<NwcIcon className="size-6" /> <NwcIcon className="size-6 rotate-12" />
</div> </div>
)} )}
</NavLink> </NavLink>

View File

@ -57,9 +57,7 @@ export function ReplyList({
</div> </div>
</div> </div>
) : ( ) : (
data.map((event) => ( data.map((event) => <Reply key={event.id} event={event} />)
<Reply key={event.id} event={event} rootEvent={eventId} />
))
)} )}
</div> </div>
); );