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
ref={ref}
className="h-full w-full flex-nowrap overflow-x-auto !overflow-y-hidden scrollbar-none focus:outline-none"
initialItemSize={420}
itemSize={420}
tabIndex={0}
horizontal
onKeyDown={(e) => {

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

View File

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

View File

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

View File

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

View File

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