mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-09 02:05:28 +00:00
Add Redux and reducers.
Load i18n files and add dayjs.
This commit is contained in:
33
src/redux/reducers/drafts.ts
Normal file
33
src/redux/reducers/drafts.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
export type Drafts = { [key: string]: string };
|
||||
|
||||
export type DraftAction =
|
||||
| { type: undefined }
|
||||
| {
|
||||
type: "SET_DRAFT";
|
||||
channel: string;
|
||||
content: string;
|
||||
}
|
||||
| {
|
||||
type: "CLEAR_DRAFT";
|
||||
channel: string;
|
||||
}
|
||||
| {
|
||||
type: "RESET";
|
||||
};
|
||||
|
||||
export function drafts(state: Drafts = {}, action: DraftAction): Drafts {
|
||||
switch (action.type) {
|
||||
case "SET_DRAFT":
|
||||
return {
|
||||
...state,
|
||||
[action.channel]: action.content
|
||||
};
|
||||
case "CLEAR_DRAFT":
|
||||
const { [action.channel]: _, ...newState } = state;
|
||||
return newState;
|
||||
case "RESET":
|
||||
return {};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user