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,48 @@
import { Auth } from "revolt.js/dist/api/objects";
export interface AuthState {
accounts: {
[key: string]: {
session: Auth.Session;
};
};
active?: string;
}
export type AuthAction =
| { type: undefined }
| {
type: "LOGIN";
session: Auth.Session;
}
| {
type: "LOGOUT";
user_id?: string;
};
export function auth(
state = { accounts: {} } as AuthState,
action: AuthAction
): AuthState {
switch (action.type) {
case "LOGIN":
return {
accounts: {
...state.accounts,
[action.session.user_id]: {
session: action.session
}
},
active: action.session.user_id
};
case "LOGOUT":
const accounts = Object.assign({}, state.accounts);
action.user_id && delete accounts[action.user_id];
return {
accounts
};
default:
return state;
}
}