This is an automated email from the ASF dual-hosted git repository.
shuai pushed a commit to branch feat/1.3.1/ui
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/1.3.1/ui by this push:
new 3e5622f0 fix: usePrompt page jumps abnormally when filling in questions
3e5622f0 is described below
commit 3e5622f04f16f0c71d656a9c047ee429e606f156
Author: shuai <[email protected]>
AuthorDate: Thu Apr 18 10:04:36 2024 +0800
fix: usePrompt page jumps abnormally when filling in questions
---
ui/package.json | 4 ++--
ui/pnpm-lock.yaml | 40 ++++++++++++++++++------------------
ui/src/hooks/usePrompt/index.tsx | 1 +
ui/src/pages/Questions/Ask/index.tsx | 16 +++++++--------
4 files changed, 31 insertions(+), 30 deletions(-)
diff --git a/ui/package.json b/ui/package.json
index 82599040..61937d2a 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -37,7 +37,7 @@
"react-dom": "^18.2.0",
"react-helmet-async": "^1.3.0",
"react-i18next": "^11.18.3",
- "react-router-dom": "^6.8.1",
+ "react-router-dom": "^6.22.3",
"semver": "^7.3.8",
"swr": "^1.3.0",
"zustand": "^4.1.1"
@@ -87,7 +87,7 @@
"typescript": "^4.9.5",
"yaml-loader": "^0.8.0"
},
- "packageManager": "[email protected]",
+ "packageManager": "pnpm@^9",
"engines": {
"node": ">=16.17",
"pnpm": ">=8"
diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml
index ed5e09a5..d4a6cccb 100644
--- a/ui/pnpm-lock.yaml
+++ b/ui/pnpm-lock.yaml
@@ -72,8 +72,8 @@ importers:
specifier: ^11.18.3
version: 11.18.6([email protected])([email protected])([email protected])
react-router-dom:
- specifier: ^6.8.1
- version: 6.8.1([email protected])([email protected])
+ specifier: ^6.22.3
+ version: 6.22.3([email protected])([email protected])
semver:
specifier: ^7.3.8
version: 7.3.8
@@ -2642,9 +2642,9 @@ packages:
react: 18.2.0
dev: false
- /@remix-run/[email protected]:
- resolution: {integrity:
sha512-t54ONhl/h75X94SWsHGQ4G/ZrCEguKSRQr7DrjTciJXW0YU1QhlwYeycvK5JgkzlxmvrK7wq1NB/PLtHxoiDcA==}
- engines: {node: '>=14'}
+ /@remix-run/[email protected]:
+ resolution: {integrity:
sha512-Oy8rmScVrVxWZVOpEF57ovlnhpZ8CCPlnIIumVcV9nFdiSIrus99+Lw78ekXyGvVDlIsFJbSfmSovJUhCWYV3w==}
+ engines: {node: '>=14.0.0'}
dev: false
/@restart/[email protected]([email protected]):
@@ -4706,7 +4706,7 @@ packages:
hasBin: true
dependencies:
caniuse-lite: 1.0.30001610
- electron-to-chromium: 1.4.736
+ electron-to-chromium: 1.4.738
node-releases: 2.0.14
update-browserslist-db: 1.0.13([email protected])
dev: true
@@ -5741,8 +5741,8 @@ packages:
/[email protected]:
resolution: {integrity:
sha512-x+JnqyluoJv8I0U9gVe+Sk2st8vF0CzMt78SXxuoWCooLLY2k5VerIBdpvG7ql6GKI4dzNnPjmqgDJ76EdaAKw==}
- /[email protected]:
- resolution: {integrity:
sha512-Rer6wc3ynLelKNM4lOCg7/zPQj8tPOCB2hzD32PX9wd3hgRRi9MxEbmkFCokzcEhRVMiOVLjnL9ig9cefJ+6+Q==}
+ /[email protected]:
+ resolution: {integrity:
sha512-lwKft2CLFztD+vEIpesrOtCrko/TFnEJlHFdRhazU7Y/jx5qc4cqsocfVrBg4So4gGe9lvxnbLIoev47WMpg+A==}
dev: true
/[email protected]:
@@ -5775,7 +5775,7 @@ packages:
resolution: {integrity:
sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==}
engines: {node: '>=10.13.0'}
dependencies:
- graceful-fs: 4.2.11
+ graceful-fs: 4.2.10
tapable: 2.2.1
/[email protected]:
@@ -8413,7 +8413,7 @@ packages:
dependencies:
universalify: 2.0.0
optionalDependencies:
- graceful-fs: 4.2.11
+ graceful-fs: 4.2.10
/[email protected]:
resolution: {integrity:
sha512-pfog5gdDxPdV4eP7Kg87M8/bHgshlZ5pybl+yKxAnCZ5O7lCIn7Ixydj03wOlnDQesky2BPyA91SQ+5Y/mNwzw==}
@@ -10332,26 +10332,26 @@ packages:
resolution: {integrity:
sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==}
engines: {node: '>=0.10.0'}
- /[email protected]([email protected])([email protected]):
- resolution: {integrity:
sha512-67EXNfkQgf34P7+PSb6VlBuaacGhkKn3kpE51+P6zYSG2kiRoumXEL6e27zTa9+PGF2MNXbgIUHTVlleLbIcHQ==}
- engines: {node: '>=14'}
+ /[email protected]([email protected])([email protected]):
+ resolution: {integrity:
sha512-7ZILI7HjcE+p31oQvwbokjk6OA/bnFxrhJ19n82Ex9Ph8fNAq+Hm/7KchpMGlTgWhUxRHMMCut+vEtNpWpowKw==}
+ engines: {node: '>=14.0.0'}
peerDependencies:
react: '>=16.8'
react-dom: '>=16.8'
dependencies:
- '@remix-run/router': 1.3.2
+ '@remix-run/router': 1.15.3
react: 18.2.0
react-dom: 18.2.0([email protected])
- react-router: 6.8.1([email protected])
+ react-router: 6.22.3([email protected])
dev: false
- /[email protected]([email protected]):
- resolution: {integrity:
sha512-Jgi8BzAJQ8MkPt8ipXnR73rnD7EmZ0HFFb7jdQU24TynGW1Ooqin2KVDN9voSC+7xhqbbCd2cjGUepb6RObnyg==}
- engines: {node: '>=14'}
+ /[email protected]([email protected]):
+ resolution: {integrity:
sha512-dr2eb3Mj5zK2YISHK++foM9w4eBnO23eKnZEDs7c880P6oKbrjz/Svg9+nxqtHQK+oMW4OtjZca0RqPglXxguQ==}
+ engines: {node: '>=14.0.0'}
peerDependencies:
react: '>=16.8'
dependencies:
- '@remix-run/router': 1.3.2
+ '@remix-run/router': 1.15.3
react: 18.2.0
dev: false
@@ -12163,7 +12163,7 @@ packages:
engines: {node: '>=10.13.0'}
dependencies:
glob-to-regexp: 0.4.1
- graceful-fs: 4.2.11
+ graceful-fs: 4.2.10
/[email protected]:
resolution: {integrity:
sha512-8wrBCMtVhqcXP2Sup1ctSkga6uc2Bx0IIvKyT7yTFier5AXHooSI+QyQQAtTb7+E0IUCCKyTFmXqdqgum2XWGg==}
diff --git a/ui/src/hooks/usePrompt/index.tsx b/ui/src/hooks/usePrompt/index.tsx
index 7655adce..095dbd53 100644
--- a/ui/src/hooks/usePrompt/index.tsx
+++ b/ui/src/hooks/usePrompt/index.tsx
@@ -36,6 +36,7 @@ const usePromptWithUnload = ({
beforeUnload = true,
}: PromptProps) => {
const { t } = useTranslation('translation', { keyPrefix: 'prompt' });
+
usePrompt({
when,
message: `${t('leave_page')} ${t('changes_not_save')}`,
diff --git a/ui/src/pages/Questions/Ask/index.tsx
b/ui/src/pages/Questions/Ask/index.tsx
index 367ccfca..68ef0ed6 100644
--- a/ui/src/pages/Questions/Ask/index.tsx
+++ b/ui/src/pages/Questions/Ask/index.tsx
@@ -88,7 +88,7 @@ const Ask = () => {
const [formData, setFormData] = useState<FormDataItem>(initFormData);
const [immData, setImmData] = useState<FormDataItem>(initFormData);
const [checked, setCheckState] = useState(false);
- const contentChangedRef = useRef(false);
+ const [blockState, setBlockState] = useState(false);
const [focusType, setForceType] = useState('');
const [hasDraft, setHasDraft] = useState(false);
const resetForm = () => {
@@ -166,9 +166,9 @@ const Ask = () => {
tags.value.map((v) => v.slug_name),
)
) {
- contentChangedRef.current = true;
+ setBlockState(true);
} else {
- contentChangedRef.current = false;
+ setBlockState(false);
}
return;
}
@@ -189,15 +189,15 @@ const Ask = () => {
},
callback: () => setHasDraft(true),
});
- contentChangedRef.current = true;
+ setBlockState(true);
} else {
removeDraft();
- contentChangedRef.current = false;
+ setBlockState(false);
}
}, [formData]);
usePromptWithUnload({
- when: contentChangedRef.current,
+ when: blockState,
});
const { data: revisions = [] } = useQueryRevisions(qid);
@@ -278,7 +278,6 @@ const Ask = () => {
};
const submitModifyQuestion = (params) => {
- contentChangedRef.current = false;
const ep = {
...params,
id: qid,
@@ -306,7 +305,6 @@ const Ask = () => {
};
const submitQuestion = async (params) => {
- contentChangedRef.current = false;
const imgCode = saveCaptcha?.getCaptcha();
if (imgCode?.verify) {
params.captcha_code = imgCode.captcha_code;
@@ -362,6 +360,7 @@ const Ask = () => {
if (isEdit) {
if (!editCaptcha) {
+ setBlockState(false);
submitModifyQuestion(params);
return;
}
@@ -370,6 +369,7 @@ const Ask = () => {
});
} else {
if (!saveCaptcha) {
+ setBlockState(false);
submitQuestion(params);
return;
}