Skip to content

Commit cca0e17

Browse files
committed
Rewrite browser reducer in RTK
1 parent 31e59ed commit cca0e17

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

ui/frontend/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = {
7171
'compileActions.ts',
7272
'editor/AceEditor.tsx',
7373
'editor/SimpleEditor.tsx',
74+
'reducers/browser.ts',
7475
'reducers/client.ts',
7576
'reducers/code.ts',
7677
'reducers/crates.ts',

ui/frontend/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ node_modules
2222
!compileActions.ts
2323
!editor/AceEditor.tsx
2424
!editor/SimpleEditor.tsx
25+
!reducers/browser.ts
2526
!reducers/client.ts
2627
!reducers/code.ts
2728
!reducers/crates.ts

ui/frontend/actions.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export enum ActionType {
5959
ChangeBacktrace = 'CHANGE_BACKTRACE',
6060
SelectText = 'SELECT_TEXT',
6161
NotificationSeen = 'NOTIFICATION_SEEN',
62-
BrowserWidthChanged = 'BROWSER_WIDTH_CHANGED',
6362
}
6463

6564
export const initializeApplication = () => createAction(ActionType.InitializeApplication);
@@ -200,9 +199,6 @@ const notificationSeen = (notification: Notification) =>
200199

201200
export const seenRustSurvey2022 = () => notificationSeen(Notification.RustSurvey2022);
202201

203-
export const browserWidthChanged = (isSmall: boolean) =>
204-
createAction(ActionType.BrowserWidthChanged, { isSmall });
205-
206202
function parseChannel(s?: string): Channel | null {
207203
switch (s) {
208204
case 'stable':
@@ -306,7 +302,6 @@ export type Action =
306302
| ReturnType<typeof changeMonacoTheme>
307303
| ReturnType<typeof selectText>
308304
| ReturnType<typeof notificationSeen>
309-
| ReturnType<typeof browserWidthChanged>
310305
| ReturnType<typeof editCode>
311306
| ReturnType<typeof addCrateType>
312307
| ReturnType<typeof navigateToIndex>

ui/frontend/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { v4 } from 'uuid';
1111
import {
1212
selectText,
1313
reExecuteWithBacktrace,
14-
browserWidthChanged,
1514
} from './actions';
1615
import { configureRustErrors } from './highlighting';
1716
import PageSwitcher from './PageSwitcher';
@@ -25,6 +24,7 @@ import { performVersionsLoad } from './reducers/versions';
2524
import { performCratesLoad } from './reducers/crates';
2625
import { gotoPosition } from './reducers/position';
2726
import { addImport, editCode, enableFeatureGate } from './reducers/code';
27+
import { browserWidthChanged } from './reducers/browser';
2828

2929
const store = configureStore(window);
3030

ui/frontend/reducers/browser.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import { Action, ActionType } from '../actions';
1+
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
22

3-
const DEFAULT: State = {
3+
const initialState: State = {
44
isSmall: true,
55
};
66

77
export type State = {
88
isSmall: boolean;
99
};
1010

11-
export default function code(state = DEFAULT, action: Action): State {
12-
switch (action.type) {
13-
case ActionType.BrowserWidthChanged:
14-
return { ...state, isSmall: action.isSmall };
11+
const slice = createSlice({
12+
name: 'browser',
13+
initialState,
14+
reducers: {
15+
browserWidthChanged: (state, action: PayloadAction<boolean>) => {
16+
state.isSmall = action.payload;
17+
},
18+
},
19+
});
1520

16-
default:
17-
return state;
18-
}
19-
}
21+
export const { browserWidthChanged } = slice.actions;
22+
23+
export default slice.reducer;

0 commit comments

Comments
 (0)