refactor: eslint v9

This commit is contained in:
Tristan Yang
2025-02-10 15:06:50 +08:00
parent 45e9530de4
commit 82761ee73e
41 changed files with 3902 additions and 4690 deletions
+33 -33
View File
@@ -5,15 +5,15 @@ const prices: Price[] = [
{
type: "payment",
limit: 999999,
pid: "price_1MbF30GGoUDRyc3jwOg30dVQ"
pid: "price_1MbF30GGoUDRyc3jwOg30dVQ",
},
{
type: "booking"
}
type: "booking",
},
];
const official_dev = `https://dev.voce.chat`;
const local_dev = `https://dev.voce.chat`;
// const local_dev = `http://localhost:3881`;
// const local_dev = `http://localhost:3412`;
const dev_origin = process.env.REACT_APP_OFFICIAL_DEMO ? official_dev : local_dev;
// const local_dev = `https://im.ttt.td`;
@@ -56,7 +56,7 @@ export const getLicensePriceList = () => {
title: "Test VoceChat Enterprise",
limit: 99999,
pid: "price_1LkQGpGGoUDRyc3jGTh3GYHw",
desc: "test price"
desc: "test price",
},
{
title: "VoceChat Pro",
@@ -65,8 +65,8 @@ export const getLicensePriceList = () => {
pid: "price_1MMNNCGGoUDRyc3jSIGIsb3C",
desc: "test subscription price",
type: "subscription",
sub_dur: "year" //day month year
}
sub_dur: "year", //day month year
},
]
: ps;
};
@@ -84,14 +84,14 @@ export const ContentTypes = {
audio: "vocechat/audio",
archive: "vocechat/archive",
formData: "multipart/form-data",
json: "application/json"
json: "application/json",
};
export const MessageTypes = {
text: "text/plain",
markdown: "text/markdown",
audio: "vocechat/audio",
file: "vocechat/file",
archive: "vocechat/archive"
archive: "vocechat/archive",
};
export const firebaseConfig = {
apiKey: "AIzaSyCc3VuCJZgzQLIH2wrYdQzsUOc1DuZiIOA",
@@ -100,11 +100,11 @@ export const firebaseConfig = {
storageBucket: "vocechatdev.appspot.com",
messagingSenderId: "526613312184",
appId: "1:526613312184:web:d13c92582baf470d487a4d",
measurementId: "G-82RQ3YSCP7"
measurementId: "G-82RQ3YSCP7",
};
export const ChatPrefixes = {
channel: "#",
dm: "@"
dm: "@",
};
export const vapidKey = `BOmzyZhw-DcIGYQ77mzQUVqLlcvn0bm_76P_kc7rpwRxzXNbui-JP8iPyEQYfyoxyJeq43Ud4IiIsJSMNHNujn0`;
export const tokenHeader = "X-API-Key";
@@ -129,84 +129,84 @@ export const Emojis = ["👍", "❤️", "😄", "👀", "👎", "🎉", "🙁",
export const getInviteLinkExpireList = () => [
{
label: i18n.t("auth:invite_expire.min30"),
value: 30 * 60
value: 30 * 60,
},
{
label: i18n.t("auth:invite_expire.h1"),
value: 60 * 60
value: 60 * 60,
},
{
label: i18n.t("auth:invite_expire.h6"),
value: 6 * 60 * 60
value: 6 * 60 * 60,
},
{
label: i18n.t("auth:invite_expire.h12"),
value: 12 * 60 * 60
value: 12 * 60 * 60,
},
{
label: i18n.t("auth:invite_expire.d1"),
value: 24 * 60 * 60
value: 24 * 60 * 60,
},
{
label: i18n.t("auth:invite_expire.d7"),
value: 7 * 24 * 60 * 60
value: 7 * 24 * 60 * 60,
},
{
label: i18n.t("auth:invite_expire.d30"),
value: 30 * 24 * 60 * 60
}
value: 30 * 24 * 60 * 60,
},
];
export const getInviteLinkTimesList = () => [
{
label: i18n.t("auth:invite_times.no_limit"),
value: 10000000
value: 10000000,
},
{
label: i18n.t("auth:invite_times.time1"),
value: 1
value: 1,
},
{
label: i18n.t("auth:invite_times.times5"),
value: 5
value: 5,
},
{
label: i18n.t("auth:invite_times.times10"),
value: 10
value: 10,
},
{
label: i18n.t("auth:invite_times.times25"),
value: 25
value: 25,
},
{
label: i18n.t("auth:invite_times.times50"),
value: 50
value: 50,
},
{
label: i18n.t("auth:invite_times.times100"),
value: 100
}
value: 100,
},
];
export const getEmailNotifyDelayList = () => [
{
label: i18n.t("setting:overview.server_msg_notify.delay_5_min"),
value: 5 * 60
value: 5 * 60,
},
{
label: i18n.t("setting:overview.server_msg_notify.delay_15_min"),
value: 15 * 60
value: 15 * 60,
},
{
label: i18n.t("setting:overview.server_msg_notify.delay_1_hour"),
value: 60 * 60
value: 60 * 60,
},
{
label: i18n.t("setting:overview.server_msg_notify.delay_3_hour"),
value: 3 * 60 * 60
value: 3 * 60 * 60,
},
{
label: i18n.t("setting:overview.server_msg_notify.delay_12_hour"),
value: 12 * 60 * 60
}
value: 12 * 60 * 60,
},
];
export const KEY_ADMIN_SEE_CHANNEL_MEMBERS = `only_admin_can_see_channel_members`;
export const KEY_MSG_URL_PREVIEW = `enable_msg_url_preview`;
-1
View File
@@ -33,7 +33,6 @@ import { updateCallInfo, upsertVoiceList } from "../slices/voice";
import { RootState } from "../store";
import baseQuery from "./base.query";
import { GetFilesDTO, VoceChatFile } from "@/types/resource";
import { IPData } from "@/types/common";
export const serverApi = createApi({
reducerPath: "serverApi",
+1 -1
View File
@@ -59,7 +59,7 @@ const uiSlice = createSlice({
...rest
} = action.payload;
window.MSG_SOUND = msgSound;
return { ...state, msgSound, ...rest };
return { ...state, msgSound,fileListView, ...rest };
},
setReady(state, action: PayloadAction<boolean>) {
state.ready = action.payload;
+2 -1
View File
@@ -4,7 +4,6 @@ import clsx from "clsx";
import { useAppSelector } from "@/app/store";
import useExpiredResMap from "@/hooks/useExpiredResMap";
import { formatBytes, fromNowTime, getFileIcon } from "@/utils";
import IconDownload from "@/assets/icons/download.svg";
import {
AudioPreview,
CodePreview,
@@ -95,6 +94,8 @@ const FileBox: FC<Props> = ({
setFetchError(true);
}
} catch (e) {
console.warn(e);
setFetchError(true);
}
};
@@ -1,7 +1,6 @@
import { useState } from "react";
import clsx from "clsx";
import IconDownload from "@/assets/icons/download.svg";
import IconAudio from "@/assets/icons/file.audio.svg";
import { formatBytes } from "../../utils";
import ExpiredMessage from "./ExpiredMessage";
@@ -2,7 +2,6 @@ import { SyntheticEvent, useState } from "react";
import { Orbit } from "@uiball/loaders";
import clsx from "clsx";
import IconDownload from "@/assets/icons/download.svg";
import IconVideo from "@/assets/icons/file.video.svg";
import { formatBytes } from "../../utils";
import ExpiredMessage from "./ExpiredMessage";
@@ -10,7 +10,7 @@ type Props = {
};
const ViewPassword = ({ uid, onClose }: Props) => {
const { isLoading, data } = useGetUserByAdminQuery(uid ?? 0, { skip: !uid });
const { data } = useGetUserByAdminQuery(uid ?? 0, { skip: !uid });
console.log({ data });
if (!uid) return null;
@@ -26,7 +26,6 @@ const PinMessageModal: FC<Props> = ({ closeModal, mid = 0, gid = 0 }) => {
closeModal();
toast.success(t("tip.pin"));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSuccess]);
if (!mid) return null;
@@ -27,7 +27,7 @@ export function ComboboxItem<TData extends Data = NoData>({
item,
onRenderItem
}: ComboboxContentItemProps<TData>) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { props } = useComboboxItem({ item, index, combobox, onRenderItem });
return (
@@ -51,7 +51,7 @@ export function ComboboxContent<TData extends Data = NoData>(props: ComboboxCont
const activeComboboxStore = useActiveComboboxStore()!;
const state = useComboboxContentState({ items, combobox });
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { menuProps, targetRange } = useComboboxContent(state);
return (
+2 -3
View File
@@ -1,5 +1,4 @@
import { FC } from "react";
import { Helmet } from "react-helmet";
import { useAppSelector } from "@/app/store";
import { useGetServerQuery } from "@/app/services/server";
import { shallowEqual } from "react-redux";
@@ -9,10 +8,10 @@ const Meta: FC<Props> = () => {
useGetServerQuery();
const { name, logo } = useAppSelector((store) => store.server, shallowEqual);
return (
<Helmet>
<>
{name && <title>{name} Web App</title>}
{logo && <link rel="icon" href={`${logo}?ts=${new Date().getTime()}`} />}
</Helmet>
</>
);
};
export default Meta;
+3 -1
View File
@@ -14,7 +14,7 @@ export type VoiceMessageProps = {
url: string;
secure_url: string;
};
// 全局存储Voice信息
// 全局存储 Voice 信息
const VoiceMap: { [key: string]: WaveSurfer | null } = {};
const VoiceMessage = ({ file_path }: { file_path: string }) => {
const containerRef = useRef(null);
@@ -56,6 +56,8 @@ const VoiceMessage = ({ file_path }: { file_path: string }) => {
});
VoiceMap[file_path] = wave;
} catch (error) {
console.error(error);
setStatus("error");
}
};
-1
View File
@@ -22,7 +22,6 @@ const Radio: FC<Props> = ({
onChange = undefined
}) => {
const id = useId();
const [fallbackValue, setFallbackValue] = useState(defaultValue);
const _value = value !== VALUE_NOT_SET ? value : fallbackValue;
return (
+3 -1
View File
@@ -18,7 +18,9 @@ const useServerExtSetting = (config?: { successTip?: boolean; key?: string }) =>
let setting = {};
try {
setting = JSON.parse(jsonSetting);
} catch (error) {}
} catch (error) {
console.warn(error);
}
const defaultValueMap = {
string: "",
boolean: false
+1 -1
View File
@@ -98,7 +98,7 @@ const handler = (
// }
});
// 推给 PC 端
console.info("{{NEW_MSG}}")
console.info("{{NEW_MSG}}");
break;
}
case "reply":
-1
View File
@@ -19,7 +19,6 @@ import VoiceChat from "../VoiceChat";
import Dashboard from "../VoiceChat/Dashboard";
import Members from "./Members";
import PinList from "./PinList";
import { getJSONField } from "@/utils";
import { KEY_ADMIN_SEE_CHANNEL_MEMBERS } from "@/app/config";
import useServerExtSetting from "@/hooks/useServerExtSetting";
+1 -1
View File
@@ -1,4 +1,4 @@
import { FC, ReactElement, useEffect, useRef } from "react";
import { FC, ReactElement, useEffect } from "react";
import { useDrop } from "react-dnd";
import { NativeTypes } from "react-dnd-html5-backend";
import { toast } from "react-hot-toast";
-21
View File
@@ -11,27 +11,6 @@ import View from "./View";
import { useLazyGetFilesQuery } from "@/app/services/server";
import { shallowEqual } from "react-redux";
const checkFilter = (data, filter, channelMessage) => {
let selected = true;
const { mid, from_uid, properties } = data;
const { name: nameFilter, from: fromFilter, channel: channelFilter } = filter;
const name = properties ? properties.name : "";
if (fromFilter && fromFilter != from_uid) {
selected = false;
}
if (channelFilter && channelMessage[channelFilter].findIndex((id) => id == mid) == -1) {
selected = false;
}
if (nameFilter) {
let str = ["", ...nameFilter.toLowerCase(), ""].join(".*");
let reg = new RegExp(str);
if (!reg.test(name)) {
selected = false;
}
}
return selected;
};
function Files() {
const [getFiles, { data }] = useLazyGetFilesQuery();
const listContainerRef = useRef<HTMLDivElement>();
-1
View File
@@ -16,7 +16,6 @@ import InvitePrivate from "./invitePrivate";
import LazyIt from "./lazy";
import InviteInMobile from "./reg/InviteInMobile";
import usePrefetchData from "@/hooks/usePrefetchData";
import ServerVersionChecker from "@/components/ServerVersionChecker";
const RegBasePage = lazy(() => import("./reg"));
const RegWithUsernamePage = lazy(() => import("./reg/RegWithUsername"));
+3 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-undef */
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import MetaMaskOnboarding from "@metamask/onboarding";
@@ -82,6 +82,8 @@ export default function MetamaskLoginButton({
});
setAccounts(tmps);
} catch (error) {
console.error(error);
// toast.error(error.message);
window.ethereum.request({
method: "wallet_requestPermissions",
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-undef */
import { FC, useState } from "react";
import { useTranslation } from "react-i18next";
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-undef */
import { ChangeEvent, FormEvent, useEffect, useState } from "react";
import toast from "react-hot-toast";
import { useTranslation } from "react-i18next";
-3
View File
@@ -1,5 +1,4 @@
import React, { useState } from "react";
import { Helmet } from "react-helmet";
import { useTranslation } from "react-i18next";
import { useWizard, Wizard } from "react-use-wizard";
import clsx from "clsx";
@@ -53,9 +52,7 @@ export default function OnboardingPage() {
const [serverName, setServerName] = useState("");
return (
<>
<Helmet>
<title>{t("onboarding.title") || ""}</title>
</Helmet>
<div className="h-screen bg-neutral-100 dark:bg-neutral-900 overflow-y-auto">
<Wizard header={<Navigator />}>
<WelcomePage />
+1 -1
View File
@@ -1,4 +1,4 @@
import { FC, MouseEvent } from "react";
import { FC } from "react";
import { Trans, useTranslation } from "react-i18next";
import BASE_URL from "@/app/config";
+1 -1
View File
@@ -1,4 +1,4 @@
import { ChangeEvent, useEffect, useRef, useState } from "react";
import { ChangeEvent, useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
@@ -3,7 +3,6 @@
import { useTranslation } from "react-i18next";
import SettingBlock from "@/components/SettingBlock";
import StyledRadio from "@/components/styled/Radio";
import { useAppSelector } from "../../../app/store";
import { shallowEqual, useDispatch } from "react-redux";
import { updateMsgSoundSetting } from "@/app/slices/ui";
@@ -5,7 +5,7 @@ import { useTranslation } from "react-i18next";
import StyledRadio from "../../../components/styled/Radio";
type Props = {};
const WhoCanSignUpSetting = (props: Props) => {
const WhoCanSignUpSetting = ({}: Props) => {
const { t } = useTranslation("setting");
const { values: loginConfig, updateConfig: updateLoginConfig } = useConfig("login");
const handleUpdateWhoCanSignUp = (value: WhoCanSignUp) => {
@@ -20,6 +20,8 @@ const RemoveConfirmModal: FC<Props> = ({ closeModal }) => {
try {
await removeCurrentAccount();
} catch (error) {
console.error(error);
toast.error("Remove Account Failed!");
}
};
+1 -1
View File
@@ -1,4 +1,4 @@
/* eslint-disable no-restricted-globals */
// This service worker can be customized!
// See https://developers.google.com/web/tools/workbox/modules
+6 -18
View File
@@ -390,13 +390,8 @@ export const compareVersion = (
return 0;
};
/*!
* Get the contrasting color for any hex color
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
* Derived from work by Brian Suda, https://24ways.org/2010/calculating-color-contrast/
* @param {String} A hexcolor value
* @return {String} The contrasting color (black or white)
*/
// Get the contrasting color for any hex color
export const getContrastColor = (hexcolor: string) => {
if (!hexcolor) return "";
// If a leading # is provided, remove it
@@ -479,16 +474,6 @@ export const transformInviteLink = (link: string) => {
export const reloadCurrentPage = () => {
if (isElectronContext()) {
// // 改变 theme color 然后 electron reload(约定)
// const metaThemeColor = document.querySelector("meta[name=theme-color]");
// if (metaThemeColor) {
// metaThemeColor.setAttribute("content", "#123456");
// } else {
// const meta = document.createElement("meta");
// meta.name = "theme-color";
// meta.content = "#123456";
// document.head.appendChild(meta);
// }
// reload 两次 electron webview bug?
setTimeout(() => {
location.reload();
@@ -511,7 +496,8 @@ export const getJSONField = (json: string | null, field: string) => {
try {
const obj = json ? JSON.parse(json) : {};
return obj[field];
} catch (error) {
} catch (err) {
console.warn(err);
return undefined;
}
};
@@ -521,6 +507,8 @@ export const upsertJSON = (json: string | null, obj: object) => {
const result = Object.assign({}, jsonObj, obj);
return JSON.stringify(result);
} catch (error) {
console.error(error);
return JSON.stringify(obj);
}
};
+1 -1
View File
@@ -1,7 +1,7 @@
import BASE_URL from "@/app/config";
import { useAppSelector } from "@/app/store";
import { compareVersion } from "@/utils";
import React, { useEffect } from "react";
import { useEffect } from "react";
type Props = {};
+4 -2
View File
@@ -1,6 +1,4 @@
/* eslint-disable @typescript-eslint/indent */
import { memo, useEffect, useRef, useState } from "react";
import { useAppSelector } from "../../app/store";
import Message from "./Message";
import { shallowEqual } from "react-redux";
@@ -26,6 +24,10 @@ const MessageFeed = ({ hostId }: Props) => {
// 自己发送的消息
if (lastIsMyself && lastMsg.sending) {
container.scrollTop = container.scrollHeight;
}
// 在可视区域附近
if (deltaHeight <= triggerScrollHeight) {
+2 -2
View File
@@ -1,4 +1,4 @@
import { ChangeEvent, memo, useEffect, useRef, useState } from "react";
import { ChangeEvent, memo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import clsx from "clsx";
@@ -17,7 +17,7 @@ type Props = {
let isComposing = false;
const MessageInput = (props: Props) => {
const inputRef = useRef<HTMLInputElement>(null);
const { uploadFile, isUploading, isSuccess: uploadSuccess } = useUploadFile();
const { uploadFile, isUploading } = useUploadFile();
const { t } = useTranslation("widget");
const { color } = useWidget();
const { from, to } = props;