Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/redux/skybrowser/skybrowserMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { api } from '@/api/api';
import { onCloseConnection } from '@/redux/connection/connectionSlice';
import { AppStartListening } from '@/redux/listenerMiddleware';
import { ConnectionStatus } from '@/types/enums';
import { Batcher } from '@/util/batcher';

import {
resetSkyBrowser,
Expand All @@ -26,9 +27,15 @@ export const setupSubscription = createAsyncThunk(
event: 'start_subscription'
});

function updateData(data: Partial<SkyBrowserUpdate>) {
thunkAPI.dispatch(updateSkyBrowser(data));
}

const batcher = new Batcher<SkyBrowserUpdate>(updateData);

(async () => {
for await (const data of skybrowserTopic.iterator()) {
thunkAPI.dispatch(updateSkyBrowser(data as SkyBrowserUpdate));
for await (const data of skybrowserTopic.iterator() as AsyncIterable<SkyBrowserUpdate>) {
batcher.add(data);
}
})();
thunkAPI.dispatch(subscriptionIsSetup());
Expand All @@ -40,7 +47,7 @@ function tearDownSubscription() {
return;
}
skybrowserTopic.talk({
event: 'stop_supscription'
event: 'stop_subscription'
Comment on lines -43 to +50
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

});
skybrowserTopic.cancel();
}
Expand Down
21 changes: 10 additions & 11 deletions src/redux/skybrowser/skybrowserSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ export const skyBrowserSlice = createSlice({
state.isInitialized = true;
return state;
},
updateSkyBrowser: (state, action: PayloadAction<SkyBrowserUpdate>) => {
state.cameraInSolarSystem = action.payload.cameraInSolarSystem;
state.selectedBrowserId = action.payload.selectedBrowserId;
updateSkyBrowser: (state, action: PayloadAction<Partial<SkyBrowserUpdate>>) => {
if (action.payload.cameraInSolarSystem !== undefined) {
state.cameraInSolarSystem = action.payload.cameraInSolarSystem;
}
if (action.payload.selectedBrowserId !== undefined) {
state.selectedBrowserId = action.payload.selectedBrowserId;
}

if (action.payload.browsers && state.selectedBrowserId in action.payload.browsers) {
Comment on lines +49 to 53
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateSkyBrowser now accepts Partial<SkyBrowserUpdate>, but the reducer still resets the entire SkyBrowser state whenever payload.browsers is missing (because the if (action.payload.browsers && ...) falls through to the reset else). With batching/partial updates this can cause the UI to clear on updates that only include selectedBrowserId/cameraInSolarSystem. Adjust the logic so that the reset/validation only happens when payload.browsers is present, and when payload.selectedBrowserId is present without browsers validate it against the existing state.browsers (reset only if the id is invalid).

Copilot uses AI. Check for mistakes.
state.browsers = action.payload.browsers;
Expand All @@ -54,15 +58,10 @@ export const skyBrowserSlice = createSlice({
typeof idx === 'string' ? parseInt(idx) : idx
);
}

// Derived state for easier access
state.browserIds = Object.keys(action.payload.browsers) ?? [];
state.browserColors = state.browserIds.map(
(id) => action.payload.browsers[id].color
);
state.browserNames = state.browserIds.map(
(id) => action.payload.browsers[id].name
);
state.browserIds = Object.keys(state.browsers);
state.browserColors = state.browserIds.map((id) => state.browsers[id].color);
state.browserNames = state.browserIds.map((id) => state.browsers[id].name);
} else {
// If the update is invalid, reset the state
state.selectedBrowserId = '';
Expand Down