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

fix: can't show tag description in tag edit page #664

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Changes from 1 commit
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
15 changes: 12 additions & 3 deletions ui/src/pages/Tags/Edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ const Index = () => {

const { data } = useTagInfo({ id: tagId });
const { data: revisions = [] } = useQueryRevisions(data?.tag_id);
initFormData.displayName.value = data?.display_name || '';
initFormData.slugName.value = data?.slug_name || '';
initFormData.description.value = data?.original_text || '';
const [formData, setFormData] = useState<FormDataItem>(initFormData);
const [immData, setImmData] = useState(initFormData);
const [contentChanged, setContentChanged] = useState(false);
Expand All @@ -85,6 +82,18 @@ const Index = () => {
when: contentChanged,
});

useEffect(() => {
setFormData({
...formData,
displayName: { ...formData.displayName, value: data?.display_name || '' },
slugName: { ...formData.slugName, value: data?.slug_name || '' },
description: {
...formData.description,
value: data?.original_text || '',
},
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have overlooked immData. immData is used to record the initial value. When the user changes the content and leaves the page, there will be a prompt; therefore, you need to add an assignment operation to immData here;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shuashuai , updated. There's one thing makes me confused that for below codes.

    useEffect(() => {
    ....
    if (!display_name || !slug_name || !original_text) {
      return;
    }
    ....
    }

Seems it'll never go into this condition branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shuashuai , updated. There's one thing makes me confused that for below codes.

    useEffect(() => {
    ....
    if (!display_name || !slug_name || !original_text) {
      return;
    }
    ....
    }

Seems it'll never go into this condition branch.

Yes, you can remove this condition now! In addition, for the previous assignment operation, you can simplify the code and use an object to assign the value. Try to reduce the number of lines of code! Thank you for your thoughts and suggestions!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved. please help to review and let me know if any comment. thanks!

}, [data]);

useEffect(() => {
const { displayName, slugName, description, editSummary } = formData;
const {
Expand Down