chore: formatting

This commit is contained in:
2024-04-26 14:06:43 +01:00
parent b7d2c599e1
commit 85261eaeab
5 changed files with 78 additions and 74 deletions

View File

@ -8,37 +8,39 @@ import { DisplayAs } from "./DisplayAsSelector";
import { TimelineFragment } from "./TimelineFragment"; import { TimelineFragment } from "./TimelineFragment";
export interface TimelineChunkProps { export interface TimelineChunkProps {
id: string; id: string;
chunk: WindowChunk, chunk: WindowChunk;
builder: (rb: RequestBuilder) => void; builder: (rb: RequestBuilder) => void;
noteFilter?: (ev: NostrEvent) => boolean; noteFilter?: (ev: NostrEvent) => boolean;
noteRenderer?: (ev: NostrEvent) => ReactNode; noteRenderer?: (ev: NostrEvent) => ReactNode;
noteOnClick?: (ev: NostrEvent) => void; noteOnClick?: (ev: NostrEvent) => void;
displayAs?: DisplayAs; displayAs?: DisplayAs;
showDisplayAsSelector?: boolean; showDisplayAsSelector?: boolean;
} }
/** /**
* Simple chunk of a timeline using absoliute time ranges * Simple chunk of a timeline using absoliute time ranges
*/ */
export default function TimelineChunk(props: TimelineChunkProps) { export default function TimelineChunk(props: TimelineChunkProps) {
const sub = useMemo(() => { const sub = useMemo(() => {
const rb = new RequestBuilder(`timeline-chunk:${props.id}:${props.chunk.since}-${props.chunk.until}`); const rb = new RequestBuilder(`timeline-chunk:${props.id}:${props.chunk.since}-${props.chunk.until}`);
props.builder(rb); props.builder(rb);
for (const f of rb.filterBuilders) { for (const f of rb.filterBuilders) {
f.since(props.chunk.since).until(props.chunk.until); f.since(props.chunk.since).until(props.chunk.until);
} }
return rb; return rb;
}, [props.id, props.chunk, props.builder]); }, [props.id, props.chunk, props.builder]);
const feed = useRequestBuilder(sub); const feed = useRequestBuilder(sub);
return <TimelineFragment return (
frag={{ <TimelineFragment
events: feed.filter(a => props.noteFilter?.(a) ?? true), frag={{
refTime: props.chunk.until events: feed.filter(a => props.noteFilter?.(a) ?? true),
}} refTime: props.chunk.until,
noteOnClick={props.noteOnClick} }}
noteRenderer={props.noteRenderer} noteOnClick={props.noteOnClick}
noteRenderer={props.noteRenderer}
/> />
} );
}

View File

@ -39,37 +39,39 @@ const TimelineFollows = (props: TimelineFollowsProps) => {
const { isFollowing, followList } = useFollowsControls(); const { isFollowing, followList } = useFollowsControls();
const { chunks, showMore } = useTimelineChunks({ const { chunks, showMore } = useTimelineChunks({
now: openedAt, now: openedAt,
firstChunkSize: Hour * 2 firstChunkSize: Hour * 2,
}); });
const builder = (rb: RequestBuilder) => { const builder = (rb: RequestBuilder) => {
rb.withFilter() rb.withFilter().authors(followList).kinds([EventKind.TextNote, EventKind.Repost, EventKind.Polls]);
.authors(followList)
.kinds([EventKind.TextNote, EventKind.Repost, EventKind.Polls]);
}; };
const filterEvents = (a: NostrEvent) => const filterEvents = (a: NostrEvent) =>
(props.noteFilter?.(a) ?? true) (props.noteFilter?.(a) ?? true) &&
&& (props.postsOnly ? !a.tags.some(b => b[0] === "e" || b[0] === "a") : true) (props.postsOnly ? !a.tags.some(b => b[0] === "e" || b[0] === "a") : true) &&
&& (isFollowing(a.pubkey) || a.tags.filter(a => a[0] === "t").length < 5); (isFollowing(a.pubkey) || a.tags.filter(a => a[0] === "t").length < 5);
return <> return (
<DisplayAsSelector <>
show={props.showDisplayAsSelector} <DisplayAsSelector
activeSelection={displayAs} show={props.showDisplayAsSelector}
onSelect={(displayAs: DisplayAs) => setDisplayAs(displayAs)} activeSelection={displayAs}
/> onSelect={(displayAs: DisplayAs) => setDisplayAs(displayAs)}
{chunks.map(c => <TimelineChunk />
key={c.until} {chunks.map(c => (
id="follows" <TimelineChunk
chunk={c} key={c.until}
builder={builder} id="follows"
noteFilter={filterEvents} chunk={c}
noteOnClick={props.noteOnClick} builder={builder}
noteRenderer={props.noteRenderer} noteFilter={filterEvents}
/>)} noteOnClick={props.noteOnClick}
<AutoLoadMore onClick={() => showMore()} /> noteRenderer={props.noteRenderer}
</>; />
))}
<AutoLoadMore onClick={() => showMore()} />
</>
);
}; };
export default TimelineFollows; export default TimelineFollows;

View File

@ -1,30 +1,30 @@
import { useState } from "react"; import { useState } from "react";
export interface WindowChunk { export interface WindowChunk {
since: number; since: number;
until: number; until: number;
} }
export default function useTimelineChunks(opt: { window?: number; firstChunkSize?: number, now: number }) { export default function useTimelineChunks(opt: { window?: number; firstChunkSize?: number; now: number }) {
const [windowSize] = useState(opt.window ?? (60 * 60 * 2)); const [windowSize] = useState(opt.window ?? 60 * 60 * 2);
const [windows, setWindows] = useState(1); const [windows, setWindows] = useState(1);
const chunks: Array<WindowChunk> = []; const chunks: Array<WindowChunk> = [];
for (let x = 0; x < windows; x++) { for (let x = 0; x < windows; x++) {
// offset from now going backwards in time // offset from now going backwards in time
const offset = opt.now - (windowSize * (x - 1)); const offset = opt.now - windowSize * (x - 1);
const size = x === 0 && opt.firstChunkSize ? opt.firstChunkSize : windowSize; const size = x === 0 && opt.firstChunkSize ? opt.firstChunkSize : windowSize;
chunks.push({ chunks.push({
since: offset - size, since: offset - size,
until: offset until: offset,
}); });
} }
return { return {
now: opt.now, now: opt.now,
chunks, chunks,
showMore: () => { showMore: () => {
setWindows(s => s + 1); setWindows(s => s + 1);
}, },
}; };
} }

View File

@ -21,7 +21,7 @@ export interface ConnectionTypeEvents {
unknownMessage: (obj: Array<any>) => void; unknownMessage: (obj: Array<any>) => void;
} }
export interface ConnectionSubscription { } export interface ConnectionSubscription {}
/** /**
* Basic relay connection * Basic relay connection
@ -100,7 +100,8 @@ export type ConnectionBuilder<T extends ConnectionType> = (
*/ */
export class DefaultConnectionPool<T extends ConnectionType = Connection> export class DefaultConnectionPool<T extends ConnectionType = Connection>
extends EventEmitter<ConnectionPoolEvents> extends EventEmitter<ConnectionPoolEvents>
implements ConnectionPool { implements ConnectionPool
{
#system: SystemInterface; #system: SystemInterface;
#log = debug("ConnectionPool"); #log = debug("ConnectionPool");

View File

@ -154,7 +154,6 @@ export class RequestBuilder {
return acc; return acc;
}, new Map<string, Array<FlatReqFilter>>()); }, new Map<string, Array<FlatReqFilter>>());
const ret = []; const ret = [];
for (const [k, v] of relayMerged.entries()) { for (const [k, v] of relayMerged.entries()) {
const filters = system.optimizer.flatMerge(v); const filters = system.optimizer.flatMerge(v);