0
0
Fork 0
misskey-tools/src/frontend/store/slices/screen.ts
2021-09-14 04:11:43 +09:00

39 lines
986 B
TypeScript

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { LOCALSTORAGE_KEY_THEME } from '../../const';
import { Theme } from '../../misc/theme';
import { Modal } from '../../modal/modal';
interface ScreenState {
modal: Modal | null;
modalShown: boolean;
theme: Theme;
}
const initialState: ScreenState = {
modal: null,
modalShown: false,
theme: localStorage[LOCALSTORAGE_KEY_THEME] ?? 'system',
};
export const screenSlice = createSlice({
name: 'screen',
initialState,
reducers: {
showModal: (state, action: PayloadAction<Modal>) => {
state.modal = action.payload;
state.modalShown = true;
},
hideModal: (state) => {
state.modal = null;
state.modalShown = false;
},
changeTheme: (state, action: PayloadAction<Theme>) => {
state.theme = action.payload;
localStorage[LOCALSTORAGE_KEY_THEME] = action.payload;
},
},
});
export const { showModal, hideModal, changeTheme } = screenSlice.actions;
export default screenSlice.reducer;