bug: use bounded until
This commit is contained in:
parent
e7d24b8c7d
commit
077b1d02b2
@ -16,7 +16,7 @@ export interface TimelineProps {
|
|||||||
* A list of notes by pubkeys
|
* A list of notes by pubkeys
|
||||||
*/
|
*/
|
||||||
export default function Timeline({ global, pubkeys, postsOnly = false }: TimelineProps) {
|
export default function Timeline({ global, pubkeys, postsOnly = false }: TimelineProps) {
|
||||||
const { main, others, loadMore } = useTimelineFeed(pubkeys, global);
|
const { main, others, loadMore, until } = useTimelineFeed(pubkeys, global);
|
||||||
|
|
||||||
const mainFeed = useMemo(() => {
|
const mainFeed = useMemo(() => {
|
||||||
return main?.sort((a, b) => b.created_at - a.created_at)?.filter(a => postsOnly ? !a.tags.some(b => b[0] === "e") : true);
|
return main?.sort((a, b) => b.created_at - a.created_at)?.filter(a => postsOnly ? !a.tags.some(b => b[0] === "e") : true);
|
||||||
@ -37,7 +37,7 @@ export default function Timeline({ global, pubkeys, postsOnly = false }: Timelin
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{mainFeed.map(eventElement)}
|
{mainFeed.map(eventElement)}
|
||||||
{mainFeed.length > 0 ? <LoadMore onLoadMore={loadMore} /> : null}
|
{mainFeed.length > 0 ? <LoadMore key={until} onLoadMore={loadMore} /> : null}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
@ -5,8 +5,7 @@ import { Subscriptions } from "../nostr/Subscriptions";
|
|||||||
import useSubscription from "./Subscription";
|
import useSubscription from "./Subscription";
|
||||||
|
|
||||||
export default function useTimelineFeed(pubKeys: HexKey | Array<HexKey>, global: boolean = false) {
|
export default function useTimelineFeed(pubKeys: HexKey | Array<HexKey>, global: boolean = false) {
|
||||||
const TimeRange = 60 * 60; // 1 hr
|
const [until, setUntil] = useState<number>();
|
||||||
const [since, setSince] = useState<number>(Math.floor(new Date().getTime() / 1000) - TimeRange);
|
|
||||||
const [trackingEvents, setTrackingEvent] = useState<u256[]>([]);
|
const [trackingEvents, setTrackingEvent] = useState<u256[]>([]);
|
||||||
|
|
||||||
const subTab = global ? "global" : "follows";
|
const subTab = global ? "global" : "follows";
|
||||||
@ -23,11 +22,11 @@ export default function useTimelineFeed(pubKeys: HexKey | Array<HexKey>, global:
|
|||||||
sub.Id = `timeline:${subTab}`;
|
sub.Id = `timeline:${subTab}`;
|
||||||
sub.Authors = global ? undefined : new Set(pubKeys);
|
sub.Authors = global ? undefined : new Set(pubKeys);
|
||||||
sub.Kinds = new Set([EventKind.TextNote, EventKind.Repost]);
|
sub.Kinds = new Set([EventKind.TextNote, EventKind.Repost]);
|
||||||
sub.Since = since;
|
sub.Limit = 20;
|
||||||
sub.Until = since + TimeRange;
|
sub.Until = until;
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
}, [pubKeys, global, since]);
|
}, [pubKeys, global, until]);
|
||||||
|
|
||||||
const main = useSubscription(sub, { leaveOpen: true });
|
const main = useSubscription(sub, { leaveOpen: true });
|
||||||
|
|
||||||
@ -62,7 +61,10 @@ export default function useTimelineFeed(pubKeys: HexKey | Array<HexKey>, global:
|
|||||||
main: main.notes,
|
main: main.notes,
|
||||||
others: others.notes,
|
others: others.notes,
|
||||||
loadMore: () => {
|
loadMore: () => {
|
||||||
setSince(s => s - TimeRange);
|
let now = Math.floor(new Date().getTime() / 1000);
|
||||||
}
|
let oldest = main.notes.reduce((acc, v) => acc = v.created_at < acc ? v.created_at : acc, now);
|
||||||
|
setUntil(oldest);
|
||||||
|
},
|
||||||
|
until
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user