Merge remote-tracking branch 'upstream/main' into refactor/typescript

# Conflicts:
#	src/common/component/ForwardModal/index.tsx
#	src/common/component/GoogleLoginButton.tsx
#	src/common/component/ManageMembers.tsx
#	src/routes/settingChannel/Overview.tsx
#	src/routes/settingChannel/index.tsx
This commit is contained in:
HD
2022-06-29 17:04:22 +08:00
44 changed files with 207 additions and 292 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
// const BASE_URL = `${location.origin}/api`;
const BASE_URL = `https://dev.rustchat.com/api`;
export const CACHE_VERSION = `0.3.0`;
const BASE_URL = `https://dev.voce.chat/api`;
export const CACHE_VERSION = `0.3.1`;
export const ContentTypes = {
text: "text/plain",
markdown: "text/markdown",
@@ -27,6 +27,7 @@ export const vapidKey = `BGXCn-5YRXSFw38Q9lUKJ5bibL212-yIQn1pCvthGhp6_KwA29FO1Ax
export const tokenHeader = "X-API-Key";
export const FILE_SLICE_SIZE = 1000 * 200 * 8; //200kb
export const FILE_IMAGE_SIZE = 1000 * 10000 * 8; //10mb
export const KEY_LOGIN_USER = "VOCECHAT_LOGIN_USER";
export const KEY_TOKEN = "VOCECHAT_TOKEN";
export const KEY_EXPIRE = "VOCECHAT_TOKEN_EXPIRE";
export const KEY_REFRESH_TOKEN = "VOCECHAT_REFRESH_TOKEN";
+1 -2
View File
@@ -2,7 +2,7 @@ import { createApi } from "@reduxjs/toolkit/query/react";
// import toast from "react-hot-toast";
import { KEY_UID } from "../config";
import baseQuery from "./base.query";
import { resetAuthData, setUid } from "../slices/auth.data";
import { resetAuthData } from "../slices/auth.data";
import { updateMute } from "../slices/footprint";
import { fullfillContacts } from "../slices/contacts";
import BASE_URL, { ContentTypes } from "../config";
@@ -41,7 +41,6 @@ export const contactApi = createApi({
const markedContacts = contacts.map((u) => {
return u.uid == matchedUser.uid ? { ...u, online: true } : u;
});
dispatch(setUid(matchedUser.uid));
dispatch(fullfillContacts(markedContacts));
}
} catch {
+1 -1
View File
@@ -132,7 +132,7 @@ export const messageApi = createApi({
async onQueryStarted(id, { dispatch, queryFulfilled, getState }) {
try {
const { data } = await queryFulfilled;
const loginUid = getState().authData.uid;
const loginUid = getState().authData.user.uid;
const messages = normalizeArchiveData(data, id, loginUid);
dispatch(populateFavorite({ id, messages }));
} catch (err) {
+4 -7
View File
@@ -1,6 +1,6 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import BASE_URL from "../config";
import { updateInfo, StoredServer } from "../slices/server";
import { updateInfo } from "../slices/server";
import baseQuery from "./base.query";
import { RootState } from "../store";
import { User } from "../../types/auth";
@@ -22,16 +22,13 @@ export const serverApi = createApi({
reducerPath: "serverApi",
baseQuery,
endpoints: (builder) => ({
getServer: builder.query<StoredServer, void>({
getServer: builder.query<Server, void>({
query: () => ({ url: `admin/system/organization` }),
transformResponse: (data: Server) => {
const logo = `${BASE_URL}/resource/organization/logo?t=${+new Date()}`;
return { ...data, logo };
},
async onQueryStarted(data, { dispatch, queryFulfilled }) {
try {
const { data: server } = await queryFulfilled;
dispatch(updateInfo(server));
const logo = `${BASE_URL}/resource/organization/logo?t=${+new Date()}`;
dispatch(updateInfo({ ...server, logo }));
} catch {
console.log("get server info error");
}
+17 -24
View File
@@ -1,20 +1,25 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { KEY_EXPIRE, KEY_PWA_INSTALLED, KEY_REFRESH_TOKEN, KEY_TOKEN, KEY_UID } from "../config";
import {
KEY_EXPIRE,
KEY_PWA_INSTALLED,
KEY_LOGIN_USER,
KEY_REFRESH_TOKEN,
KEY_TOKEN,
KEY_UID
} from "../config";
import { AuthData, AuthToken, User } from "../../types/auth";
interface State {
initialized: boolean;
uid: string | null;
user: User | null;
user: User | undefined;
token: string | null;
expireTime: number;
refreshToken: string | null;
}
const loginUser = localStorage.getItem(KEY_LOGIN_USER) || "";
const initialState: State = {
initialized: true,
uid: null,
user: null,
user: loginUser ? JSON.parse(loginUser) : undefined,
token: localStorage.getItem(KEY_TOKEN),
expireTime: Number(localStorage.getItem(KEY_EXPIRE) || +new Date()),
refreshToken: localStorage.getItem(KEY_REFRESH_TOKEN)
@@ -22,8 +27,7 @@ const initialState: State = {
const emptyState: State = {
initialized: true,
uid: null,
user: null,
user: undefined,
token: null,
expireTime: +new Date(),
refreshToken: null
@@ -34,22 +38,17 @@ const authDataSlice = createSlice({
initialState,
reducers: {
setAuthData(state, { payload }: PayloadAction<AuthData>) {
const {
initialized = true,
user: { uid },
token,
refresh_token,
expired_in = 0
} = payload;
const { initialized = true, user, token, refresh_token, expired_in = 0 } = payload;
const { uid } = user;
state.initialized = initialized;
state.uid = `${uid}`;
state.user = payload.user;
state.user = user;
state.token = token;
state.refreshToken = refresh_token;
// 当前时间往后推expire时长
const expireTime = +new Date() + Number(expired_in) * 1000;
state.expireTime = expireTime;
// set local data
localStorage.setItem(KEY_LOGIN_USER, JSON.stringify(user));
localStorage.setItem(KEY_EXPIRE, `${expireTime}`);
localStorage.setItem(KEY_TOKEN, token);
localStorage.setItem(KEY_REFRESH_TOKEN, refresh_token);
@@ -65,16 +64,11 @@ const authDataSlice = createSlice({
return emptyState;
},
setUid(state, action: PayloadAction<string>) {
state.uid = action.payload;
console.log("set uid original");
},
updateInitialized(state, action: PayloadAction<boolean>) {
state.initialized = action.payload;
},
updateToken(state, action: PayloadAction<AuthToken>) {
const { token, refresh_token, expired_in } = action.payload;
console.log("refresh token");
state.token = token;
const et = +new Date() + Number(expired_in) * 1000;
state.expireTime = et;
@@ -86,6 +80,5 @@ const authDataSlice = createSlice({
}
});
export const { updateInitialized, setAuthData, resetAuthData, setUid, updateToken } =
authDataSlice.actions;
export const { updateInitialized, setAuthData, resetAuthData, updateToken } = authDataSlice.actions;
export default authDataSlice.reducer;
+4 -1
View File
@@ -39,11 +39,14 @@ const serverSlice = createSlice({
},
updateInfo(state, action: PayloadAction<Partial<StoredServer>>) {
const values = action.payload || {};
const tmp = { ...state, ...values };
console.log("ssss", tmp);
// todo: check and remove old logic
// Object.keys(values).forEach((_key) => {
// state[_key] = values[_key];
// });
state = { ...state, ...values };
return { ...state, ...values };
}
}
});