Skip to content

Commit 843fb0a

Browse files
authored
Merge pull request #20 from aolsenjazz/dev
fix(renderer state): Only reset loopback messages when setProjectName…
2 parents 70e5925 + 3e59019 commit 843fb0a

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/renderer/features/recent-loopback-messages/recent-loopback-messages-slice.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ export const recentLoopbackMessagesSlice = createAppSlice({
3737
if (state[qid].length > 100) state[qid].shift();
3838
},
3939
),
40-
}),
41-
extraReducers: (builder) => {
42-
// on project change, clear recent input events
43-
builder.addCase('projectName/setName', (state) => {
40+
41+
clearAllMessages: create.reducer((state) => {
4442
Array.from(Object.keys(state)).forEach((k) => {
4543
delete state[k];
4644
});
47-
});
48-
},
45+
}),
46+
}),
4947
});
5048

5149
export const selectRecentLoopbackMessages = (state: RootState, id: string) =>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { startAppListening } from '../store/listener-middleware';
2+
import { projectNameSlice } from '../features/project-name/project-name-slice';
3+
import { recentLoopbackMessagesSlice } from '../features/recent-loopback-messages/recent-loopback-messages-slice';
4+
5+
/**
6+
* Listens to changes to the current superset dashboard layout. This callback is invoked whenever
7+
* a gridComponent is added or removed from the layout.
8+
*
9+
* It's currently updating in a not-smart way; whenever an update happens, every IkiDynamicMarkdown
10+
* gridComponent notifies the ContextService to alert us that the layout has changed. Therefore,
11+
* we end up receiving far too many changed events
12+
*/
13+
startAppListening({
14+
actionCreator: projectNameSlice.actions.setName,
15+
effect: async (action, listenerApi) => {
16+
// ignore if the action is dispatched with the same payload
17+
if (action.payload === listenerApi.getState().projectName.name) {
18+
return;
19+
}
20+
21+
listenerApi.dispatch(
22+
recentLoopbackMessagesSlice.actions.clearAllMessages(),
23+
);
24+
},
25+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createListenerMiddleware } from '@reduxjs/toolkit';
2+
3+
import type { AppDispatch, RootState } from './store';
4+
5+
export const listenerMiddleware = createListenerMiddleware();
6+
7+
export const startAppListening = listenerMiddleware.startListening.withTypes<
8+
RootState,
9+
AppDispatch
10+
>();

src/renderer/store/store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { recentLoopbackMessagesSlice } from '../features/recent-loopback-message
1414
import { recentRemoteMessagesSlice } from '../features/recent-remote-messages/recent-remote-messages-slice';
1515
import { projectNameSlice } from '../features/project-name/project-name-slice';
1616

17+
import '../middleware/project-name-listener';
18+
1719
const rootReducer = combineSlices(
1820
connectedDevicesSlice,
1921
configuredDevicesSlice,

0 commit comments

Comments
 (0)