mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-07-18 08:12:22 +02:00
small timeline fixes
This commit is contained in:
@ -25,6 +25,9 @@ export default class EventStore {
|
|||||||
this.onEvent.next(event);
|
this.onEvent.next(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
getEvent(id:string){
|
||||||
|
return this.events.get(id)
|
||||||
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.events.clear();
|
this.events.clear();
|
||||||
|
@ -17,15 +17,12 @@ function addToQuery(filter: NostrRequestFilter, query: NostrQuery) {
|
|||||||
return { ...filter, ...query };
|
return { ...filter, ...query };
|
||||||
}
|
}
|
||||||
|
|
||||||
const BLOCK_SIZE = 20;
|
const BLOCK_SIZE = 30;
|
||||||
|
|
||||||
type EventFilter = (event: NostrEvent) => boolean;
|
export class RelayTimelineLoader {
|
||||||
|
|
||||||
class RelayTimelineLoader {
|
|
||||||
relay: string;
|
relay: string;
|
||||||
query: NostrRequestFilter;
|
query: NostrRequestFilter;
|
||||||
blockSize = BLOCK_SIZE;
|
blockSize = BLOCK_SIZE;
|
||||||
private name?: string;
|
|
||||||
private log: Debugger;
|
private log: Debugger;
|
||||||
|
|
||||||
loading = false;
|
loading = false;
|
||||||
@ -35,12 +32,11 @@ class RelayTimelineLoader {
|
|||||||
|
|
||||||
onBlockFinish = new Subject<void>();
|
onBlockFinish = new Subject<void>();
|
||||||
|
|
||||||
constructor(relay: string, query: NostrRequestFilter, name: string, log?: Debugger) {
|
constructor(relay: string, query: NostrRequestFilter, log?: Debugger) {
|
||||||
this.relay = relay;
|
this.relay = relay;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
this.log = log || logger.extend(this.name);
|
this.log = log || logger.extend(relay);
|
||||||
this.events = new EventStore(relay);
|
this.events = new EventStore(relay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +72,9 @@ class RelayTimelineLoader {
|
|||||||
return this.events.addEvent(event);
|
return this.events.addEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFirstEvent(nth = 0) {
|
||||||
|
return this.events.getFirstEvent(nth);
|
||||||
|
}
|
||||||
getLastEvent(nth = 0) {
|
getLastEvent(nth = 0) {
|
||||||
return this.events.getLastEvent(nth);
|
return this.events.getLastEvent(nth);
|
||||||
}
|
}
|
||||||
@ -98,7 +97,7 @@ export class TimelineLoader {
|
|||||||
private log: Debugger;
|
private log: Debugger;
|
||||||
private subscription: NostrMultiSubscription;
|
private subscription: NostrMultiSubscription;
|
||||||
|
|
||||||
private relayTimelineLoaders = new Map<string, RelayTimelineLoader>();
|
relayTimelineLoaders = new Map<string, RelayTimelineLoader>();
|
||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -131,7 +130,7 @@ export class TimelineLoader {
|
|||||||
|
|
||||||
for (const relay of this.relays) {
|
for (const relay of this.relays) {
|
||||||
if (!this.relayTimelineLoaders.has(relay)) {
|
if (!this.relayTimelineLoaders.has(relay)) {
|
||||||
const loader = new RelayTimelineLoader(relay, this.query, this.name, this.log.extend(relay));
|
const loader = new RelayTimelineLoader(relay, this.query, this.log.extend(relay));
|
||||||
this.relayTimelineLoaders.set(relay, loader);
|
this.relayTimelineLoaders.set(relay, loader);
|
||||||
this.events.connect(loader.events);
|
this.events.connect(loader.events);
|
||||||
loader.onBlockFinish.subscribe(this.updateLoading, this);
|
loader.onBlockFinish.subscribe(this.updateLoading, this);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useInterval } from "react-use";
|
import { useInterval } from "react-use";
|
||||||
import { TimelineLoader } from "../classes/timeline-loader";
|
import { TimelineLoader } from "../classes/timeline-loader";
|
||||||
import { useIntersectionMapCallback } from "../providers/intersection-observer";
|
import { useIntersectionMapCallback } from "../providers/intersection-observer";
|
||||||
import { getEventUID } from "../helpers/nostr/events";
|
import { NostrEvent } from "../types/nostr-event";
|
||||||
|
|
||||||
export function useTimelineCurserIntersectionCallback(timeline: TimelineLoader) {
|
export function useTimelineCurserIntersectionCallback(timeline: TimelineLoader) {
|
||||||
// if the cursor is set too far ahead and the last block did not overlap with the cursor
|
// if the cursor is set too far ahead and the last block did not overlap with the cursor
|
||||||
@ -13,15 +13,20 @@ export function useTimelineCurserIntersectionCallback(timeline: TimelineLoader)
|
|||||||
return useIntersectionMapCallback<string>(
|
return useIntersectionMapCallback<string>(
|
||||||
(map) => {
|
(map) => {
|
||||||
// find oldest event that is visible
|
// find oldest event that is visible
|
||||||
for (let i = timeline.timeline.value.length - 1; i >= 0; i--) {
|
let oldestEvent: NostrEvent | undefined = undefined;
|
||||||
const event = timeline.timeline.value[i];
|
for (const [id, intersection] of map) {
|
||||||
|
if (!intersection.isIntersecting) continue;
|
||||||
if (map.get(getEventUID(event))?.isIntersecting) {
|
const event = timeline.events.getEvent(id);
|
||||||
timeline.setCursor(event.created_at);
|
if (!event) continue;
|
||||||
timeline.loadNextBlocks();
|
if (!oldestEvent || event.created_at < oldestEvent.created_at) {
|
||||||
return;
|
oldestEvent = event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (oldestEvent) {
|
||||||
|
timeline.setCursor(oldestEvent.created_at);
|
||||||
|
timeline.loadNextBlocks();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[timeline],
|
[timeline],
|
||||||
);
|
);
|
||||||
|
@ -45,11 +45,9 @@ export type PeopleListProviderProps = PropsWithChildren & {
|
|||||||
initList?: ListId;
|
initList?: ListId;
|
||||||
};
|
};
|
||||||
export default function PeopleListProvider({ children, initList = "following" }: PeopleListProviderProps) {
|
export default function PeopleListProvider({ children, initList = "following" }: PeopleListProviderProps) {
|
||||||
const [params, setParams] = useSearchParams({
|
const [params, setParams] = useSearchParams();
|
||||||
people: initList,
|
|
||||||
});
|
|
||||||
|
|
||||||
const selected = params.get("people") as ListId;
|
const selected = params.get("people") || (initList as ListId);
|
||||||
const setSelected = useCallback(
|
const setSelected = useCallback(
|
||||||
(value: ListId) => {
|
(value: ListId) => {
|
||||||
setParams((p) => ({ ...searchParamsToJson(p), people: value }));
|
setParams((p) => ({ ...searchParamsToJson(p), people: value }));
|
||||||
|
Reference in New Issue
Block a user