Add Redux and reducers.

Load i18n files and add dayjs.
This commit is contained in:
Paul
2021-06-18 17:57:08 +01:00
parent 0cba2b362d
commit 27eeb3acd2
25 changed files with 1506 additions and 53 deletions

View File

@@ -0,0 +1,46 @@
export type TypingUser = { id: string, started: number };
export type Typing = { [key: string]: TypingUser[] };
export type TypingAction =
| { type: undefined }
| {
type: "TYPING_START";
channel: string;
user: string;
}
| {
type: "TYPING_STOP";
channel: string;
user: string;
}
| {
type: "RESET";
};
export function typing(state: Typing = {}, action: TypingAction): Typing {
switch (action.type) {
case "TYPING_START":
return {
...state,
[action.channel]: [
...(state[action.channel] ?? []).filter(
x => x.id !== action.user
),
{
id: action.user,
started: + new Date()
}
]
};
case "TYPING_STOP":
return {
...state,
[action.channel]:
state[action.channel]?.filter(x => x.id !== action.user) ?? []
};
case "RESET":
return {};
default:
return state;
}
}