mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 05:54:19 +01:00
fix: clear events when filter is updated
This commit is contained in:
@@ -78,6 +78,12 @@ const useThrottledEvents = ({
|
|||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const stopTimer = () => {
|
||||||
|
if (timeoutId != null) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const addEvent = (event: NostrEvent) => {
|
const addEvent = (event: NostrEvent) => {
|
||||||
const diffSec = event.created_at - epoch();
|
const diffSec = event.created_at - epoch();
|
||||||
if (diffSec > SecondsToIgnore) return;
|
if (diffSec > SecondsToIgnore) return;
|
||||||
@@ -101,6 +107,11 @@ const useThrottledEvents = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const clearEvents = () => {
|
||||||
|
setEvents([]);
|
||||||
|
stopTimer();
|
||||||
|
};
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (eose()) {
|
if (eose()) {
|
||||||
reflectDelayedEvents();
|
reflectDelayedEvents();
|
||||||
@@ -108,12 +119,10 @@ const useThrottledEvents = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
onCleanup(() => {
|
onCleanup(() => {
|
||||||
if (timeoutId != null) {
|
stopTimer();
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { events, setEvents, addEvent };
|
return { events, setEvents, addEvent, clearEvents };
|
||||||
};
|
};
|
||||||
|
|
||||||
const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
|
const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
|
||||||
@@ -125,7 +134,11 @@ const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
|
|||||||
const eoseLimit = () => propsProvider()?.eoseLimit ?? 25;
|
const eoseLimit = () => propsProvider()?.eoseLimit ?? 25;
|
||||||
const limit = () => propsProvider()?.limit ?? 50;
|
const limit = () => propsProvider()?.limit ?? 50;
|
||||||
|
|
||||||
const { events, setEvents, addEvent } = useThrottledEvents({ eose, eoseLimit, limit });
|
const { events, addEvent, clearEvents, setEvents } = useThrottledEvents({
|
||||||
|
eose,
|
||||||
|
eoseLimit,
|
||||||
|
limit,
|
||||||
|
});
|
||||||
|
|
||||||
createEffect(
|
createEffect(
|
||||||
on(
|
on(
|
||||||
@@ -161,6 +174,7 @@ const useSubscription = (propsProvider: () => UseSubscriptionProps | null) => {
|
|||||||
let subscribing = true;
|
let subscribing = true;
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
||||||
|
clearEvents();
|
||||||
setEose(false);
|
setEose(false);
|
||||||
|
|
||||||
const sub = pool().subscribeMany(
|
const sub = pool().subscribeMany(
|
||||||
|
|||||||
Reference in New Issue
Block a user