mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-03-26 17:52:18 +01:00
fix small bug with delete event modal
This commit is contained in:
parent
0689e5c561
commit
83135a6490
@ -2,7 +2,6 @@ import { getEventUID } from "../helpers/nostr/events";
|
||||
import { NostrEvent } from "../types/nostr-event";
|
||||
import Subject from "./subject";
|
||||
|
||||
type EventFilter = (event: NostrEvent) => boolean;
|
||||
export default class EventStore {
|
||||
name?: string;
|
||||
events = new Map<string, NostrEvent>();
|
||||
@ -24,9 +23,7 @@ export default class EventStore {
|
||||
if (!existing || event.created_at > existing.created_at) {
|
||||
this.events.set(id, event);
|
||||
this.onEvent.next(event);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
clear() {
|
||||
@ -41,19 +38,17 @@ export default class EventStore {
|
||||
other.onEvent.unsubscribe(this.addEvent, this);
|
||||
}
|
||||
|
||||
getFirstEvent(nth = 0, filter?: EventFilter) {
|
||||
getFirstEvent(nth = 0) {
|
||||
const events = this.getSortedEvents();
|
||||
const filteredEvents = filter ? events.filter(filter) : events;
|
||||
for (let i = 0; i <= nth; i++) {
|
||||
const event = filteredEvents[i];
|
||||
const event = events[i];
|
||||
if (event) return event;
|
||||
}
|
||||
}
|
||||
getLastEvent(nth = 0, filter?: EventFilter) {
|
||||
getLastEvent(nth = 0) {
|
||||
const events = this.getSortedEvents();
|
||||
const filteredEvents = filter ? events.filter(filter) : events;
|
||||
for (let i = nth; i >= 0; i--) {
|
||||
const event = filteredEvents[filteredEvents.length - 1 - i];
|
||||
const event = events[events.length - 1 - i];
|
||||
if (event) return event;
|
||||
}
|
||||
}
|
||||
|
@ -56,14 +56,16 @@ class RelayTimelineLoader {
|
||||
|
||||
let gotEvents = 0;
|
||||
request.onEvent.subscribe((e) => {
|
||||
if (this.handleEvent(e)) {
|
||||
gotEvents++;
|
||||
}
|
||||
this.handleEvent(e);
|
||||
gotEvents++;
|
||||
});
|
||||
request.onComplete.then(() => {
|
||||
this.loading = false;
|
||||
if (gotEvents === 0) this.complete = true;
|
||||
this.log(`Got ${gotEvents} events`);
|
||||
if (gotEvents === 0) {
|
||||
this.complete = true;
|
||||
this.log("Complete");
|
||||
}
|
||||
this.onBlockFinish.next();
|
||||
});
|
||||
|
||||
@ -74,8 +76,8 @@ class RelayTimelineLoader {
|
||||
return this.events.addEvent(event);
|
||||
}
|
||||
|
||||
getLastEvent(nth = 0, filter?: EventFilter) {
|
||||
return this.events.getLastEvent(nth, filter);
|
||||
getLastEvent(nth = 0) {
|
||||
return this.events.getLastEvent(nth);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +193,7 @@ export class TimelineLoader {
|
||||
let triggeredLoad = false;
|
||||
for (const [relay, loader] of this.relayTimelineLoaders) {
|
||||
if (loader.complete || loader.loading) continue;
|
||||
const event = loader.getLastEvent(this.loadNextBlockBuffer, this.eventFilter);
|
||||
const event = loader.getLastEvent(this.loadNextBlockBuffer);
|
||||
if (!event || event.created_at >= this.cursor) {
|
||||
loader.loadNextBlock();
|
||||
triggeredLoad = true;
|
||||
|
@ -8,7 +8,9 @@ export const PIN_LIST_KIND = 10001;
|
||||
export const MUTE_LIST_KIND = 10000;
|
||||
|
||||
export function getListName(event: NostrEvent) {
|
||||
if (event.kind === 3) return "Following";
|
||||
if (event.kind === Kind.Contacts) return "Following";
|
||||
if (event.kind === PIN_LIST_KIND) return "Pins";
|
||||
if (event.kind === MUTE_LIST_KIND) return "Mute";
|
||||
return event.tags.find((t) => t[0] === "title")?.[1] || event.tags.find(isDTag)?.[1];
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ import useEventRelays from "../hooks/use-event-relays";
|
||||
import { useWriteRelayUrls } from "../hooks/use-client-relays";
|
||||
import { RelayFavicon } from "../components/relay-favicon";
|
||||
import { ExternalLinkIcon } from "../components/icons";
|
||||
import { getEventCoordinate, isReplaceable } from "../helpers/nostr/events";
|
||||
import { getEventCoordinate, getEventUID, isReplaceable } from "../helpers/nostr/events";
|
||||
import NostrPublishAction from "../classes/nostr-publish-action";
|
||||
import { Tag } from "../types/nostr-event";
|
||||
|
||||
@ -65,7 +65,7 @@ export default function DeleteEventProvider({ children }: PropsWithChildren) {
|
||||
const [defer, setDefer] = useState<Deferred<void>>();
|
||||
const [reason, setReason] = useState("");
|
||||
|
||||
const eventRelays = useEventRelays(event?.id);
|
||||
const eventRelays = useEventRelays(event && getEventUID(event));
|
||||
const writeRelays = useWriteRelayUrls(eventRelays);
|
||||
|
||||
const deleteEvent = useCallback((event: Event) => {
|
||||
@ -94,7 +94,6 @@ export default function DeleteEventProvider({ children }: PropsWithChildren) {
|
||||
};
|
||||
const signed = await signingService.requestSignature(draft, account);
|
||||
const pub = new NostrPublishAction("Delete", writeRelays, signed);
|
||||
await pub.onComplete;
|
||||
defer?.resolve();
|
||||
} catch (e) {
|
||||
if (e instanceof Error) toast({ status: "error", description: e.message });
|
||||
|
@ -24,7 +24,7 @@ function ListsPage() {
|
||||
const noteLists = lists.filter((event) => event.kind === NOTE_LIST_KIND);
|
||||
|
||||
return (
|
||||
<Flex direction="column" p="2" gap="2">
|
||||
<Flex direction="column" pt="2" pb="10" gap="2" px={["2", "2", 0]}>
|
||||
<Flex gap="2">
|
||||
<Button as={RouterLink} to="/lists/browse">
|
||||
Browse Lists
|
||||
@ -51,13 +51,17 @@ function ListsPage() {
|
||||
<ListCard cord={`${MUTE_LIST_KIND}:${account.pubkey}`} />
|
||||
<ListCard cord={`${PIN_LIST_KIND}:${account.pubkey}`} />
|
||||
</SimpleGrid>
|
||||
<Heading size="md">People lists</Heading>
|
||||
<Divider />
|
||||
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2">
|
||||
{peopleLists.map((event) => (
|
||||
<ListCard key={getEventUID(event)} event={event} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
{peopleLists.length > 0 && (
|
||||
<>
|
||||
<Heading size="md">People lists</Heading>
|
||||
<Divider />
|
||||
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2">
|
||||
{peopleLists.map((event) => (
|
||||
<ListCard key={getEventUID(event)} event={event} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
</>
|
||||
)}
|
||||
{noteLists.length > 0 && (
|
||||
<>
|
||||
<Heading size="md">Bookmark lists</Heading>
|
||||
|
@ -1,15 +1,16 @@
|
||||
import { useOutletContext } from "react-router-dom";
|
||||
import { SimpleGrid } from "@chakra-ui/react";
|
||||
import { Divider, Flex, Heading, SimpleGrid } from "@chakra-ui/react";
|
||||
|
||||
import { useAdditionalRelayContext } from "../../providers/additional-relay-context";
|
||||
import useTimelineLoader from "../../hooks/use-timeline-loader";
|
||||
import useSubject from "../../hooks/use-subject";
|
||||
import { NOTE_LIST_KIND, PEOPLE_LIST_KIND } from "../../helpers/nostr/lists";
|
||||
import { MUTE_LIST_KIND, NOTE_LIST_KIND, PEOPLE_LIST_KIND, PIN_LIST_KIND } from "../../helpers/nostr/lists";
|
||||
import { getEventUID, truncatedId } from "../../helpers/nostr/events";
|
||||
import ListCard from "../lists/components/list-card";
|
||||
import IntersectionObserverProvider from "../../providers/intersection-observer";
|
||||
import { useTimelineCurserIntersectionCallback } from "../../hooks/use-timeline-cursor-intersection-callback";
|
||||
import TimelineActionAndStatus from "../../components/timeline-page/timeline-action-and-status";
|
||||
import { Kind } from "nostr-tools";
|
||||
|
||||
export default function UserListsTab() {
|
||||
const { pubkey } = useOutletContext() as { pubkey: string };
|
||||
@ -20,19 +21,47 @@ export default function UserListsTab() {
|
||||
kinds: [PEOPLE_LIST_KIND, NOTE_LIST_KIND],
|
||||
});
|
||||
|
||||
const events = useSubject(timeline.timeline);
|
||||
const lists = useSubject(timeline.timeline);
|
||||
const callback = useTimelineCurserIntersectionCallback(timeline);
|
||||
|
||||
const peopleLists = lists.filter((event) => event.kind === PEOPLE_LIST_KIND);
|
||||
const noteLists = lists.filter((event) => event.kind === NOTE_LIST_KIND);
|
||||
|
||||
return (
|
||||
<IntersectionObserverProvider callback={callback}>
|
||||
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2" py="2" px={["2", "2", 0]}>
|
||||
<ListCard cord={`3:${pubkey}`} />
|
||||
<ListCard cord={`10000:${pubkey}`} />
|
||||
{events.map((event) => (
|
||||
<ListCard key={getEventUID(event)} event={event} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
<TimelineActionAndStatus timeline={timeline} />
|
||||
<Flex gap="2" pt="2" pb="10" px={["2", "2", 0]} direction="column">
|
||||
<Heading size="md">Special lists</Heading>
|
||||
<Divider />
|
||||
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2">
|
||||
<ListCard cord={`${Kind.Contacts}:${pubkey}`} />
|
||||
<ListCard cord={`${MUTE_LIST_KIND}:${pubkey}`} />
|
||||
<ListCard cord={`${PIN_LIST_KIND}:${pubkey}`} />
|
||||
</SimpleGrid>
|
||||
|
||||
{peopleLists.length > 0 && (
|
||||
<>
|
||||
<Heading size="md">People lists</Heading>
|
||||
<Divider />
|
||||
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2">
|
||||
{peopleLists.map((event) => (
|
||||
<ListCard key={getEventUID(event)} event={event} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
</>
|
||||
)}
|
||||
|
||||
{noteLists.length > 0 && (
|
||||
<>
|
||||
<Heading size="md">Bookmark lists</Heading>
|
||||
<Divider />
|
||||
<SimpleGrid columns={{ base: 1, lg: 2, xl: 3 }} spacing="2">
|
||||
{noteLists.map((event) => (
|
||||
<ListCard key={getEventUID(event)} event={event} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
</>
|
||||
)}
|
||||
</Flex>
|
||||
</IntersectionObserverProvider>
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user