mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-12-11 02:09:53 -06:00
Fixed boundToMercureHub HOC so that it clears updates intervals when unmounted
This commit is contained in:
parent
fa074f91be
commit
cfb165d240
@ -22,12 +22,18 @@ export function boundToMercureHub<T = {}>(
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onMessage = (visit: CreateVisit) => interval ? pendingUpdates.add(visit) : createNewVisits([ visit ]);
|
const onMessage = (visit: CreateVisit) => interval ? pendingUpdates.add(visit) : createNewVisits([ visit ]);
|
||||||
|
|
||||||
interval && setInterval(() => {
|
bindToMercureTopic(mercureInfo, getTopicForProps(props), onMessage, loadMercureInfo);
|
||||||
|
|
||||||
|
if (!interval) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timer = setInterval(() => {
|
||||||
createNewVisits([ ...pendingUpdates ]);
|
createNewVisits([ ...pendingUpdates ]);
|
||||||
pendingUpdates.clear();
|
pendingUpdates.clear();
|
||||||
}, interval * 1000 * 60);
|
}, interval * 1000 * 60);
|
||||||
|
|
||||||
bindToMercureTopic(mercureInfo, getTopicForProps(props), onMessage, loadMercureInfo);
|
return () => clearInterval(timer);
|
||||||
}, [ mercureInfo ]);
|
}, [ mercureInfo ]);
|
||||||
|
|
||||||
return <WrappedComponent {...props} />;
|
return <WrappedComponent {...props} />;
|
||||||
|
|||||||
@ -37,9 +37,11 @@ const RealTimeUpdates = (
|
|||||||
/>
|
/>
|
||||||
{realTimeUpdates.enabled && (
|
{realTimeUpdates.enabled && (
|
||||||
<small className="form-text text-muted">
|
<small className="form-text text-muted">
|
||||||
{realTimeUpdates.interval !== undefined && realTimeUpdates.interval > 0 &&
|
{realTimeUpdates.interval !== undefined && realTimeUpdates.interval > 0 && (
|
||||||
<span>Updates will be reflected in the UI every <b>{realTimeUpdates.interval}</b> minutes.</span>
|
<span>
|
||||||
}
|
Updates will be reflected in the UI every <b>{realTimeUpdates.interval}</b> minute{realTimeUpdates.interval > 1 && 's'}.
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{!realTimeUpdates.interval && 'Updates will be reflected in the UI as soon as they happen.'}
|
{!realTimeUpdates.interval && 'Updates will be reflected in the UI as soon as they happen.'}
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user