chore: formatting
This commit is contained in:
parent
b7d2c599e1
commit
85261eaeab
@ -8,37 +8,39 @@ import { DisplayAs } from "./DisplayAsSelector";
|
||||
import { TimelineFragment } from "./TimelineFragment";
|
||||
|
||||
export interface TimelineChunkProps {
|
||||
id: string;
|
||||
chunk: WindowChunk,
|
||||
builder: (rb: RequestBuilder) => void;
|
||||
noteFilter?: (ev: NostrEvent) => boolean;
|
||||
noteRenderer?: (ev: NostrEvent) => ReactNode;
|
||||
noteOnClick?: (ev: NostrEvent) => void;
|
||||
displayAs?: DisplayAs;
|
||||
showDisplayAsSelector?: boolean;
|
||||
id: string;
|
||||
chunk: WindowChunk;
|
||||
builder: (rb: RequestBuilder) => void;
|
||||
noteFilter?: (ev: NostrEvent) => boolean;
|
||||
noteRenderer?: (ev: NostrEvent) => ReactNode;
|
||||
noteOnClick?: (ev: NostrEvent) => void;
|
||||
displayAs?: DisplayAs;
|
||||
showDisplayAsSelector?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple chunk of a timeline using absoliute time ranges
|
||||
*/
|
||||
export default function TimelineChunk(props: TimelineChunkProps) {
|
||||
const sub = useMemo(() => {
|
||||
const rb = new RequestBuilder(`timeline-chunk:${props.id}:${props.chunk.since}-${props.chunk.until}`);
|
||||
props.builder(rb);
|
||||
for (const f of rb.filterBuilders) {
|
||||
f.since(props.chunk.since).until(props.chunk.until);
|
||||
}
|
||||
return rb;
|
||||
}, [props.id, props.chunk, props.builder]);
|
||||
const sub = useMemo(() => {
|
||||
const rb = new RequestBuilder(`timeline-chunk:${props.id}:${props.chunk.since}-${props.chunk.until}`);
|
||||
props.builder(rb);
|
||||
for (const f of rb.filterBuilders) {
|
||||
f.since(props.chunk.since).until(props.chunk.until);
|
||||
}
|
||||
return rb;
|
||||
}, [props.id, props.chunk, props.builder]);
|
||||
|
||||
const feed = useRequestBuilder(sub);
|
||||
const feed = useRequestBuilder(sub);
|
||||
|
||||
return <TimelineFragment
|
||||
frag={{
|
||||
events: feed.filter(a => props.noteFilter?.(a) ?? true),
|
||||
refTime: props.chunk.until
|
||||
}}
|
||||
noteOnClick={props.noteOnClick}
|
||||
noteRenderer={props.noteRenderer}
|
||||
return (
|
||||
<TimelineFragment
|
||||
frag={{
|
||||
events: feed.filter(a => props.noteFilter?.(a) ?? true),
|
||||
refTime: props.chunk.until,
|
||||
}}
|
||||
noteOnClick={props.noteOnClick}
|
||||
noteRenderer={props.noteRenderer}
|
||||
/>
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -39,37 +39,39 @@ const TimelineFollows = (props: TimelineFollowsProps) => {
|
||||
const { isFollowing, followList } = useFollowsControls();
|
||||
const { chunks, showMore } = useTimelineChunks({
|
||||
now: openedAt,
|
||||
firstChunkSize: Hour * 2
|
||||
firstChunkSize: Hour * 2,
|
||||
});
|
||||
|
||||
const builder = (rb: RequestBuilder) => {
|
||||
rb.withFilter()
|
||||
.authors(followList)
|
||||
.kinds([EventKind.TextNote, EventKind.Repost, EventKind.Polls]);
|
||||
rb.withFilter().authors(followList).kinds([EventKind.TextNote, EventKind.Repost, EventKind.Polls]);
|
||||
};
|
||||
|
||||
const filterEvents = (a: NostrEvent) =>
|
||||
(props.noteFilter?.(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);
|
||||
(props.noteFilter?.(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);
|
||||
|
||||
return <>
|
||||
<DisplayAsSelector
|
||||
show={props.showDisplayAsSelector}
|
||||
activeSelection={displayAs}
|
||||
onSelect={(displayAs: DisplayAs) => setDisplayAs(displayAs)}
|
||||
/>
|
||||
{chunks.map(c => <TimelineChunk
|
||||
key={c.until}
|
||||
id="follows"
|
||||
chunk={c}
|
||||
builder={builder}
|
||||
noteFilter={filterEvents}
|
||||
noteOnClick={props.noteOnClick}
|
||||
noteRenderer={props.noteRenderer}
|
||||
/>)}
|
||||
<AutoLoadMore onClick={() => showMore()} />
|
||||
</>;
|
||||
return (
|
||||
<>
|
||||
<DisplayAsSelector
|
||||
show={props.showDisplayAsSelector}
|
||||
activeSelection={displayAs}
|
||||
onSelect={(displayAs: DisplayAs) => setDisplayAs(displayAs)}
|
||||
/>
|
||||
{chunks.map(c => (
|
||||
<TimelineChunk
|
||||
key={c.until}
|
||||
id="follows"
|
||||
chunk={c}
|
||||
builder={builder}
|
||||
noteFilter={filterEvents}
|
||||
noteOnClick={props.noteOnClick}
|
||||
noteRenderer={props.noteRenderer}
|
||||
/>
|
||||
))}
|
||||
<AutoLoadMore onClick={() => showMore()} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TimelineFollows;
|
||||
|
@ -1,30 +1,30 @@
|
||||
import { useState } from "react";
|
||||
|
||||
export interface WindowChunk {
|
||||
since: number;
|
||||
until: number;
|
||||
since: number;
|
||||
until: number;
|
||||
}
|
||||
|
||||
export default function useTimelineChunks(opt: { window?: number; firstChunkSize?: number, now: number }) {
|
||||
const [windowSize] = useState(opt.window ?? (60 * 60 * 2));
|
||||
const [windows, setWindows] = useState(1);
|
||||
export default function useTimelineChunks(opt: { window?: number; firstChunkSize?: number; now: number }) {
|
||||
const [windowSize] = useState(opt.window ?? 60 * 60 * 2);
|
||||
const [windows, setWindows] = useState(1);
|
||||
|
||||
const chunks: Array<WindowChunk> = [];
|
||||
for (let x = 0; x < windows; x++) {
|
||||
// offset from now going backwards in time
|
||||
const offset = opt.now - (windowSize * (x - 1));
|
||||
const size = x === 0 && opt.firstChunkSize ? opt.firstChunkSize : windowSize;
|
||||
chunks.push({
|
||||
since: offset - size,
|
||||
until: offset
|
||||
});
|
||||
}
|
||||
const chunks: Array<WindowChunk> = [];
|
||||
for (let x = 0; x < windows; x++) {
|
||||
// offset from now going backwards in time
|
||||
const offset = opt.now - windowSize * (x - 1);
|
||||
const size = x === 0 && opt.firstChunkSize ? opt.firstChunkSize : windowSize;
|
||||
chunks.push({
|
||||
since: offset - size,
|
||||
until: offset,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
now: opt.now,
|
||||
chunks,
|
||||
showMore: () => {
|
||||
setWindows(s => s + 1);
|
||||
},
|
||||
};
|
||||
return {
|
||||
now: opt.now,
|
||||
chunks,
|
||||
showMore: () => {
|
||||
setWindows(s => s + 1);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export interface ConnectionTypeEvents {
|
||||
unknownMessage: (obj: Array<any>) => void;
|
||||
}
|
||||
|
||||
export interface ConnectionSubscription { }
|
||||
export interface ConnectionSubscription {}
|
||||
|
||||
/**
|
||||
* Basic relay connection
|
||||
@ -100,7 +100,8 @@ export type ConnectionBuilder<T extends ConnectionType> = (
|
||||
*/
|
||||
export class DefaultConnectionPool<T extends ConnectionType = Connection>
|
||||
extends EventEmitter<ConnectionPoolEvents>
|
||||
implements ConnectionPool {
|
||||
implements ConnectionPool
|
||||
{
|
||||
#system: SystemInterface;
|
||||
#log = debug("ConnectionPool");
|
||||
|
||||
|
@ -154,7 +154,6 @@ export class RequestBuilder {
|
||||
return acc;
|
||||
}, new Map<string, Array<FlatReqFilter>>());
|
||||
|
||||
|
||||
const ret = [];
|
||||
for (const [k, v] of relayMerged.entries()) {
|
||||
const filters = system.optimizer.flatMerge(v);
|
||||
|
Loading…
x
Reference in New Issue
Block a user