Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade React v17 / react-intl / minor fixes #7

Merged
merged 9 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ yarn-debug.log*
yarn-error.log*

.vscode/*
.idea
stats.html
269 changes: 173 additions & 96 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"polished": "^4.0.5",
"qs": "^6.9.4",
"rc-upload": "^3.2.0",
"react": "^16.12.0",
"react": "^17",
"react-cookie": "^4.0.3",
"react-dom": "^16.12.0",
"react-dom": "^17",
"react-filepond": "^7.0.1",
"react-intl": "^3.12.0",
"react-intl": "^5",
"react-redux": "^7.2.0",
"react-resize-detector": "^4.2.1",
"react-router-dom": "^5.1.2",
Expand Down Expand Up @@ -78,10 +78,10 @@
"@types/classnames": "^2.2.9",
"@types/jwt-decode": "^2.2.1",
"@types/lodash-es": "^4.14.149",
"@types/node": "^18",
"@types/node": "^20",
"@types/qs": "^6.9.5",
"@types/react": "^16",
"@types/react-dom": "^16",
"@types/react": "<18",
"@types/react-dom": "<18",
"@types/react-filepond": "^5.0.5",
"@types/react-redux": "^7.1.7",
"@types/react-resize-detector": "^4.2.0",
Expand All @@ -106,7 +106,8 @@
"vite-plugin-imp": "^2.4.0"
},
"overrides": {
"@types/react": "^16",
"@types/react-dom": "^16"
"typescript": "^5.3",
"react": "^17",
"react-dom": "^17"
}
}
4 changes: 4 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Index from './pages/Index';
import Login from './pages/Login';
import Register from './pages/Register';
import ResetPassword from './pages/ResetPassword';
import { NotFoundPage } from './pages/404';
import { AppState } from './store';
import style from './style';

Expand Down Expand Up @@ -164,6 +165,9 @@ const App: React.FC = () => {
<Admin />
</Route>
)}
<Route path="/*">
<NotFoundPage />
</Route>
</Switch>
)}
</>
Expand Down
4 changes: 3 additions & 1 deletion src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
};

/** 成功的响应 */
export interface BasicSuccessResult<T = any> {

Check warning on line 64 in src/apis/index.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected any. Specify a different type
type: typeof resultTypes.SUCCESS;
data: T;
headers: any;

Check warning on line 67 in src/apis/index.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected any. Specify a different type
}

/** 基础错误响应结果的数据 */
Expand Down Expand Up @@ -125,7 +125,9 @@
| CancelFailureResult
| OtherFailureResult;

export const request = <T = any>(axiosConfig: AxiosRequestConfig) => {
export const request = <T = any>(

Check warning on line 128 in src/apis/index.ts

View workflow job for this annotation

GitHub Actions / check-pr

Unexpected any. Specify a different type
axiosConfig: AxiosRequestConfig,
): Promise<BasicSuccessResult<T>> => {
return instance({
// param=value1&param=value2,去除 query 中数组的 [] 结尾
paramsSerializer: function (params) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Tooltip, TooltipProps } from './Tooltip';
interface ButtonProps {
tooltipProps?: TooltipProps;
loading?: boolean;
disibled?: boolean;
disabled?: boolean;
type?: 'button' | 'link';
linkProps?: React.DetailedHTMLProps<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
Expand All @@ -38,7 +38,7 @@ export const Button: FC<ButtonProps> = ({
color = style.primaryColor,
colorDisibled = style.primaryColorLightest,
loading = false,
disibled = false,
disabled = false,
onClick,
className,
children,
Expand Down Expand Up @@ -73,7 +73,7 @@ export const Button: FC<ButtonProps> = ({
return (
<div
className={classNames('Button', className, {
'Button--disibled': disibled || loading,
'Button--disibled': disabled || loading,
'Button--noChildren': !children,
})}
css={css`
Expand All @@ -98,7 +98,7 @@ export const Button: FC<ButtonProps> = ({
color: ${color};
margin-right: 10px;
}
${disibled || loading || clickEffect()}
${disabled || loading || clickEffect()}
&.Button--disibled {
cursor: not-allowed;
user-select: none;
Expand All @@ -120,7 +120,7 @@ export const Button: FC<ButtonProps> = ({
}
}
`}
onClick={disibled || loading ? undefined : onClick}
onClick={disabled || loading ? undefined : onClick}
>
{tooltipProps ? (
<Tooltip {...tooltipProps}>{buttonContent}</Tooltip>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Form: FC<FormProps & AntdFormProps> = ({ ...props }) => {
/** 处理 Form 值变动 */
const handleValuesChange = (changedValues: Store, values: Store) => {
// 当值变动时消除错误
for (let key in changedValues) {
for (const key in changedValues) {
props.form?.setFields([{ name: key, errors: [] }]);
}
if (props.onValuesChange) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageSourceViewerGod/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const Source: FC<SourceProps> = ({
(state: AppState) => state.project.currentProject,
);

let statusLine = checkTranslationState(source);
const statusLine = checkTranslationState(source);

const handleSourcePositionTypeChange = (checked: boolean) => {
dispatch(
Expand Down
2 changes: 1 addition & 1 deletion src/components/LanguageSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const LanguageSelect: FC<LanguageSelectProps> = ({
useEffect(() => {
setLoading(true);
apis.getLanguages().then((result) => {
let options = result.data.map((item) => {
const options = result.data.map((item) => {
item = toLowerCamelCase(item);
const option: SelectOption = {
label: item.i18nName,
Expand Down
6 changes: 3 additions & 3 deletions src/components/Movable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ const MovableItemWithoutRef: React.ForwardRefRenderFunction<
* @param size 组件的大小
*/
const moveWithMargins: MoveWithMargins = (margins) => {
let position: Position = { x: 0, y: 0 };
const position: Position = { x: 0, y: 0 };
// 计算 x 轴上百分比
if (margins.x.edge === 'left') {
// 根据左边定位
Expand Down Expand Up @@ -910,7 +910,7 @@ const MovableItemWithoutRef: React.ForwardRefRenderFunction<
} {
// 将光标位置放入数组
const pointers = [];
for (let key in pointersRef.current) {
for (const key in pointersRef.current) {
pointers.push(pointersRef.current[key]);
}
// 计算两个光标距离
Expand Down Expand Up @@ -1235,7 +1235,7 @@ const MovableItemWithoutRef: React.ForwardRefRenderFunction<
onZoomEnd(stateRef.current);
}
// 更新初始移动状态
for (let id in pointersRef.current) {
for (const id in pointersRef.current) {
startMoveInfoRef.current = {
...pointersRef.current[id],
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const Output: FC<OutputProps> = ({ index, output, className }) => {
<div className="Output__Bottom">
<Button
className="Output__DownloadButton"
disibled={output.status === OUTPUT_STATUS.ERROR}
disabled={output.status === OUTPUT_STATUS.ERROR}
loading={
![OUTPUT_STATUS.SUCCEEDED, OUTPUT_STATUS.ERROR].includes(
output.status,
Expand Down
2 changes: 1 addition & 1 deletion src/components/TeamInsightProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export const TeamInsightProjectList: FC<TeamInsightProjectListProps> = ({
<div>
<CustomButton
className="TeamInsightProjectList__OutputDownloadButton"
disibled={output.status === OUTPUT_STATUS.ERROR}
disabled={output.status === OUTPUT_STATUS.ERROR}
loading={
![
OUTPUT_STATUS.SUCCEEDED,
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ interface UseTitle {
* @param prefix 前缀
* @param suffix 后缀
* @param hyphen 站点名和前缀/后缀之间的连字符
* @param deps
*/
export const useTitle: UseTitle = (
{ prefix = '', suffix = '', hyphen = ' · ' }: UseTitleParams = {},
deps = [],
) => {
): void => {
const { formatMessage } = useIntl();
if (prefix !== '') prefix = prefix + hyphen;
if (suffix !== '') suffix = hyphen + suffix;
Expand Down
30 changes: 16 additions & 14 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ConfigProvider } from 'antd';
import Bowser from 'bowser';
import 'pepjs'; // 指针事件垫片
import React from 'react';
import React, { StrictMode } from 'react';
import ReactDOM from 'react-dom';
import { IntlProvider } from 'react-intl'; // i18n
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -65,7 +65,7 @@ store.dispatch(setOSName(osName));
for (const hotKeyName in hotKeyInitialState) {
const name = hotKeyName as keyof HotKeyState;
for (const index of [0, 1]) {
let loadedHotKey = loadHotKey({ name, index });
const loadedHotKey = loadHotKey({ name, index });
if (loadedHotKey !== 'disibled') {
let option;
if (loadedHotKey) {
Expand All @@ -79,17 +79,19 @@ for (const hotKeyName in hotKeyInitialState) {
}
// 渲染 APP
ReactDOM.render(
<Provider store={store}>
<IntlProvider locale={locale} messages={intlMessages}>
<ConfigProvider
locale={antdLocale}
form={{ validateMessages: antdValidateMessages }}
>
<Router>
<App />
</Router>
</ConfigProvider>
</IntlProvider>
</Provider>,
<StrictMode>
<Provider store={store}>
<IntlProvider locale={locale} messages={intlMessages}>
<ConfigProvider
locale={antdLocale}
form={{ validateMessages: antdValidateMessages }}
>
<Router>
<App />
</Router>
</ConfigProvider>
</IntlProvider>
</Provider>
</StrictMode>,
document.getElementById('root'),
);
20 changes: 20 additions & 0 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useTitle } from '../hooks';
import { useHistory } from 'react-router-dom';
import { FC, useEffect } from 'react';

export const NotFoundPage: FC = (props) => {
const history = useHistory();
useTitle({
prefix: 'Page not found',
});
useEffect(() => {
const timer = setTimeout(() => {
history.push('/');
}, 3000);

return () => {
clearTimeout(timer);
};
}, []);
return <div>Page not found. You will be redirected shortly</div>;
};
2 changes: 1 addition & 1 deletion src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function toHyphenCase(value: string | { [propNames: string]: any }) {
return stringToHyphenCase(value);
} else {
const newValue: { [key: string]: any } = {};
for (let key in value) {
for (const key in value) {
newValue[stringToHyphenCase(key)] = value[key];
}
return newValue;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function toHyphenCase(value: string | { [propNames: string]: any }) {
return stringToHyphenCase(value);
} else {
const newValue: { [key: string]: any } = {};
for (let key in value) {
for (const key in value) {
newValue[stringToHyphenCase(key)] = value[key];
}
return newValue;
Expand Down Expand Up @@ -50,7 +50,7 @@ function toUnderScoreCase(
return value.map((v: any) => toUnderScoreCase(v));
} else if (isPlainObject(value)) {
const newValue: { [key: string]: any } = {};
for (let key in value) {
for (const key in value) {
if (isPlainObject(value[key])) {
// 递归处理所以子对象
newValue[stringToUnderScoreCase(key)] = toUnderScoreCase(value[key]);
Expand Down Expand Up @@ -94,7 +94,7 @@ function toLowerCamelCase(
return value.map((v: any) => toLowerCamelCase(v));
} else if (isPlainObject(value)) {
const newValue: { [key: string]: any } = {};
for (let key in value) {
for (const key in value) {
if (isPlainObject(value[key])) {
// 递归处理所以子对象
newValue[stringToLowerCamelCase(key)] = toLowerCamelCase(value[key]);
Expand Down Expand Up @@ -125,7 +125,7 @@ interface ToFormErrors {
*/
const toFormErrors: ToFormErrors = (value) => {
const newValue = [];
for (let key in value) {
for (const key in value) {
newValue.push({
name: stringToLowerCamelCase(key),
errors: value[key],
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
"jsx": "react-jsx"
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const backendOrigin = 'http://localhost:13080';
export default defineConfig({
// root: 'src',
build: {
sourcemap: true,
outDir: path.join(__dirname, './build'),
emptyOutDir: true,
rollupOptions: {
Expand Down
Loading