pull/149/head
Philipp Heckel 2022-03-08 21:18:15 -05:00
parent 28e6f8a0f6
commit 8c8a1685b2
1 changed files with 7 additions and 4 deletions

View File

@ -136,14 +136,17 @@ const useConnectionListeners = () => {
}; };
const useAutoSubscribe = (subscriptions, selected) => { const useAutoSubscribe = (subscriptions, selected) => {
const [autoSubscribed, setAutoSubscribed] = useState(false); const [hasRun, setHasRun] = useState(false);
const params = useParams(); const params = useParams();
useEffect(() => { useEffect(() => {
const loaded = subscriptions !== null && subscriptions !== undefined; const loaded = subscriptions !== null && subscriptions !== undefined;
const eligible = loaded && params.topic && !selected && !autoSubscribed; if (!loaded || hasRun) {
return;
}
setHasRun(true);
const eligible = params.topic && !selected;
if (eligible) { if (eligible) {
setAutoSubscribed(true);
const baseUrl = (params.baseUrl) ? expandSecureUrl(params.baseUrl) : window.location.origin; const baseUrl = (params.baseUrl) ? expandSecureUrl(params.baseUrl) : window.location.origin;
console.log(`[App] Auto-subscribing to ${topicUrl(baseUrl, params.topic)}`); console.log(`[App] Auto-subscribing to ${topicUrl(baseUrl, params.topic)}`);
(async () => { (async () => {
@ -151,7 +154,7 @@ const useAutoSubscribe = (subscriptions, selected) => {
poller.pollInBackground(subscription); // Dangle! poller.pollInBackground(subscription); // Dangle!
})(); })();
} }
}, [params, subscriptions, selected, autoSubscribed]); }, [params, subscriptions, selected, hasRun]);
}; };
const updateTitle = (newNotificationsCount) => { const updateTitle = (newNotificationsCount) => {