Convert dropdown_menu
state to Typescript (#25585)
This commit is contained in:
parent
b93ffb74bb
commit
4b7bc1f07c
9 changed files with 69 additions and 41 deletions
33
app/javascript/mastodon/reducers/dropdown_menu.ts
Normal file
33
app/javascript/mastodon/reducers/dropdown_menu.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { createReducer } from '@reduxjs/toolkit';
|
||||
|
||||
import { closeDropdownMenu, openDropdownMenu } from '../actions/dropdown_menu';
|
||||
|
||||
interface DropdownMenuState {
|
||||
openId: string | null;
|
||||
keyboard: boolean;
|
||||
scrollKey: string | null;
|
||||
}
|
||||
|
||||
const initialState: DropdownMenuState = {
|
||||
openId: null,
|
||||
keyboard: false,
|
||||
scrollKey: null,
|
||||
};
|
||||
|
||||
export const dropdownMenuReducer = createReducer(initialState, (builder) => {
|
||||
builder
|
||||
.addCase(
|
||||
openDropdownMenu,
|
||||
(state, { payload: { id, keyboard, scrollKey } }) => {
|
||||
state.openId = id;
|
||||
state.keyboard = keyboard;
|
||||
state.scrollKey = scrollKey;
|
||||
},
|
||||
)
|
||||
.addCase(closeDropdownMenu, (state, { payload: { id } }) => {
|
||||
if (state.openId === id) {
|
||||
state.openId = null;
|
||||
state.scrollKey = null;
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue