Skip to content

Commit

Permalink
Merge branch 'fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
wildcatco committed Aug 9, 2023
2 parents 1068be1 + ab59e8a commit 2e02021
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/apis/hooks/posts/useEditPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ export default function useEditPost() {
mutationFn: async (data: EditPostRequest) => {
const res = await axiosInstance.patch<EditPostResponse>(
`/worries/${data.id}`,
data
data,
);
return res.data;
},
onSuccess: (data) => {
queryClient.refetchQueries({
queryKey: ['posts'],
});
queryClient.refetchQueries({
queryKey: ['post', data.id],
});
Expand Down
15 changes: 12 additions & 3 deletions src/pages/edit/EditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import LoadingSpinner from '@/components/ui/LoadingSpinner';
import Popup from '@/components/ui/modal/Popup';
import withAuth from '@/components/withAuth';
import { PostFormData } from '@/types/post';
import { useQueryClient } from '@tanstack/react-query';

function EditPage() {
const queryClient = useQueryClient();
const params = useParams();
const [modalOpen, setModalOpen] = useState(false);
const navigate = useNavigate();
Expand All @@ -33,7 +35,7 @@ function EditPage() {
categoryId !== post.worryCategory.id ||
images.length !== post.worryFiles.length ||
!post.worryFiles.every((file) =>
images.map((image) => image.url).includes(file.url)
images.map((image) => image.url).includes(file.url),
))
) {
setHasChanges(true);
Expand Down Expand Up @@ -71,7 +73,14 @@ function EditPage() {

useEffect(() => {
if (isSuccess && data) {
navigate(`/feed/${data.id}`);
queryClient
.refetchQueries({
queryKey: ['posts'],
})
.then(() => {
const to = localStorage.getItem('navAfterEdit');
navigate(`/feed/${data.id}${to ? `/${to}` : ''}`);
});
}
}, [isSuccess, data]);

Expand All @@ -84,7 +93,7 @@ function EditPage() {
1000 -
new Date(createdAt).getTime()) /
1000 /
3600
3600,
);
}
};
Expand Down
6 changes: 5 additions & 1 deletion src/pages/feed/FeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function FeedPage() {
});
const { chooseOption } = useChooseOption();
const [selectedVoteOptionId, setSelectedVoteOptionId] = useAtom(
selectedVoteOptionIdAtom
selectedVoteOptionIdAtom,
);
const setVoteAnimationId = useSetAtom(voteAnimationIdAtom);
const scrollRef = useScrollRestoration<HTMLUListElement>('feed');
Expand All @@ -50,6 +50,10 @@ function FeedPage() {
setSelectedVoteOptionId(null);
}, []);

useEffect(() => {
localStorage.setItem('navAfterEdit', route || '');
}, []);

return (
<div className="flex h-full flex-col">
<TopAppBar
Expand Down

0 comments on commit 2e02021

Please sign in to comment.