mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-10 10:35:27 +00:00
Add Redux and reducers.
Load i18n files and add dayjs.
This commit is contained in:
46
src/redux/reducers/typing.ts
Normal file
46
src/redux/reducers/typing.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user