refactor: more TS code

This commit is contained in:
Tristan Yang
2022-07-08 19:13:49 +08:00
parent 678b8515ca
commit 9f1b115c73
55 changed files with 421 additions and 338 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import {
KEY_TOKEN,
KEY_UID
} from "../config";
import { AuthData, AuthToken, User } from "../../types/auth";
import { AuthData, AuthToken, RenewTokenResponse, User } from "../../types/auth";
interface State {
initialized: boolean;
@@ -67,7 +67,7 @@ const authDataSlice = createSlice({
updateInitialized(state, action: PayloadAction<boolean>) {
state.initialized = action.payload;
},
updateToken(state, action: PayloadAction<AuthToken>) {
updateToken(state, action: PayloadAction<RenewTokenResponse>) {
const { token, refresh_token, expired_in } = action.payload;
state.token = token;
const et = +new Date() + Number(expired_in) * 1000;
+1 -1
View File
@@ -53,7 +53,7 @@ const channelsSlice = createSlice({
},
updateChannel(state, action: PayloadAction<UpdateChannelDTO>) {
const ignoreInPublic = ["add_member", "remove_member"];
const { gid, operation, members = [], ...rest } = action.payload;
const { gid, operation = "", members = [], ...rest } = action.payload;
const currChannel = state.byId[gid];
if (!currChannel || (currChannel.is_public && ignoreInPublic.includes(operation))) return;
switch (operation) {
+1 -1
View File
@@ -59,7 +59,7 @@ const uiSlice = createSlice({
},
updateRememberedNavs(
state,
action: PayloadAction<{ key?: "chat" | "user"; path: string | null } | undefined>
action: PayloadAction<{ key?: "chat" | "user"; path?: string | null } | undefined>
) {
const { key = "chat", path = null } = action.payload || {};
state.rememberedNavs[key] = path;
+1 -1
View File
@@ -1,7 +1,7 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { isNull, omitBy } from "lodash";
import BASE_URL from "../config";
import { User } from "../../types/auth";
import { User } from "../../types/user";
import { UserLog, UserState } from "../../types/sse";
export interface StoredUser extends User {