Skip to content
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useUpdateStateAfterSave } from '~/client/services/page-operation';
import { apiPost } from '~/client/util/apiv1-client';
import { toastError, toastSuccess } from '~/client/util/toastr';
import { useTagEditModalStatus, useTagEditModalActions, type TagEditModalStatus } from '~/states/ui/modal/tag-edit';
import { useSWRxTagsInfo } from '~/stores/page';

import { TagsInput } from './TagsInput';

Expand All @@ -28,8 +29,8 @@ const TagEditModalSubstance: React.FC<TagEditModalSubstanceProps> = (props: TagE
const pageId = tagEditModalData.pageId;
const revisionId = tagEditModalData.revisionId;
const updateStateAfterSave = useUpdateStateAfterSave(pageId);

const [tags, setTags] = useState<string[]>([]);
const { mutate: mutateTags } = useSWRxTagsInfo(pageId);
const [tags, setTags] = useState<string[]>(initTags ?? []);

// use to take initTags when redirect to other page
useEffect(() => {
Expand All @@ -46,6 +47,9 @@ const TagEditModalSubstance: React.FC<TagEditModalSubstanceProps> = (props: TagE
const handleSubmit = useCallback(async() => {
try {
await apiPost('/tags.update', updateTagsData);
if (mutateTags != null) {
await mutateTags();
}
Copy link
Member

Choose a reason for hiding this comment

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

  • これだと何が mutate されているか分かりにくいです
  • String.prototype.includes() だと意図しないキーがマッチして無駄な再検証が走る可能性があります (本来やりたいことは tag の再検証のみ)
  • useSWRxTagsInfo から提供される mutate を使って実装してみてほしいです
    • updateStateAfterSave の中に mutate に実装しても良さそうです

Copy link
Member

@miya miya Dec 10, 2025

Choose a reason for hiding this comment

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

mutateTags って nullable じゃなさそうなので null check は不要そう

Copy link
Member

@miya miya Dec 10, 2025

Choose a reason for hiding this comment

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

あと、これは非同期でも良さそうなので await もいらないかも (更新が成功したら即時トースターをだしたいので)

updateStateAfterSave?.();

toastSuccess('updated tags successfully');
Expand All @@ -54,7 +58,7 @@ const TagEditModalSubstance: React.FC<TagEditModalSubstanceProps> = (props: TagE
catch (err) {
toastError(err);
}
}, [closeTagEditModal, updateTagsData, updateStateAfterSave]);
}, [updateTagsData, mutateTags, updateStateAfterSave, closeTagEditModal]);

// Memoized tags update handler
const handleTagsUpdate = useCallback((newTags: string[]) => {
Expand All @@ -67,7 +71,7 @@ const TagEditModalSubstance: React.FC<TagEditModalSubstanceProps> = (props: TagE
{t('tag_edit_modal.edit_tags')}
</ModalHeader>
<ModalBody>
<TagsInput tags={initTags} onTagsUpdated={handleTagsUpdate} autoFocus />
<TagsInput tags={tags} onTagsUpdated={handleTagsUpdate} autoFocus />
</ModalBody>
<ModalFooter>
<button type="button" data-testid="tag-edit-done-btn" className="btn btn-primary" onClick={handleSubmit}>
Expand Down
Loading