refactor: 调整代码与翻译

pull/13/head
moonrailgun 4 years ago
parent 698da6b27b
commit 55c432ad62

@ -2,11 +2,9 @@ import { io, Socket } from 'socket.io-client';
import _isNil from 'lodash/isNil';
import { getServiceUrl } from '../manager/service';
import { isDevelopment } from '../utils/environment';
import { showErrorToasts, showGlobalLoading, showToasts } from '../manager/ui';
import { showErrorToasts, showGlobalLoading } from '../manager/ui';
import { t } from '../i18n';
let socket: Socket;
class SocketEventError extends Error {
name = 'SocketEventError';
}
@ -43,7 +41,7 @@ export class AppSocket {
}
get connected(): boolean {
return socket.connected;
return this.socket.connected;
}
async request<T = unknown>(
@ -75,7 +73,7 @@ export class AppSocket {
/**
* Socket
*/
closeFn: unknown = null; // 全局loading关闭函数
private closeFn: unknown = null; // 全局loading关闭函数
setupSocketStatusTip() {
const socket = this.socket;
@ -129,36 +127,37 @@ export class AppSocket {
}
}
let _socket: Socket;
/**
* Socket
* Socket
* @param token Token
*/
export function createSocket(token: string): Promise<AppSocket> {
if (!_isNil(socket)) {
socket.close();
if (!_isNil(_socket)) {
_socket.close();
}
return new Promise((resolve, reject) => {
socket = io(getServiceUrl(), {
_socket = io(getServiceUrl(), {
transports: ['websocket'],
auth: {
token,
},
forceNew: true,
});
socket.once('connect', () => {
_socket.once('connect', () => {
// 连接成功
const appSocket = new AppSocket(socket);
const appSocket = new AppSocket(_socket);
appSocket.setupSocketStatusTip();
resolve(appSocket);
});
socket.once('error', () => {
_socket.once('error', () => {
reject();
});
if (isDevelopment) {
socket.onAny((...args) => {
_socket.onAny((...args) => {
console.log('Receive Notify:', args);
});
}

@ -118,6 +118,7 @@
"kf22210a": "Loading plugin list",
"kf48ae58": "Group information not found",
"kf5d66247": "Panel Name",
"kf6d7f23d": "Connecting to chat server...",
"kf7d829eb": "Wait to process",
"kf87f3059": "Plugin Store",
"kfa01c850": "No private message found",

@ -118,6 +118,7 @@
"kf22210a": "正在加载插件列表",
"kf48ae58": "找不到群组信息",
"kf5d66247": "面板名",
"kf6d7f23d": "正在连接到聊天服务器...",
"kf7d829eb": "待处理",
"kf87f3059": "插件中心",
"kfa01c850": "找不到私信会话",

@ -5,6 +5,7 @@ import {
useAsync,
userActions,
loginWithToken,
t,
} from 'tailchat-shared';
import React from 'react';
import { LoadingSpinner } from '../../components/LoadingSpinner';
@ -72,7 +73,7 @@ export const MainProvider: React.FC = React.memo((props) => {
if (loading) {
return (
<div className="fixed inset-0 flex items-center justify-center bg-gray-700 text-white text-xl">
<LoadingSpinner tip="正在连接到聊天服务器..." />
<LoadingSpinner tip={t('正在连接到聊天服务器...')} />
</div>
);
}

Loading…
Cancel
Save