chore: formatting
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user