Commit f604b3f2 authored by Daniel Puchala's avatar Daniel Puchala
Browse files

feat: correct ui rerender after deleting a review

parent 2c127902
......@@ -42,7 +42,7 @@ export const Movie = () => {
const { id } = useParams();
const { data: movie, error: movieError } = useSWR(`movies/${id}`, fetcher)
const { data: reviews, error: reviewError } = useSWR(`reviews/search/${id}`, fetcher)
const { data: reviews, error: reviewError, mutate: mutateReviews } = useSWR(`reviews/search/${id}`, fetcher)
const { data: recommended, error: recommendedError } = useSWR(`movies/${id}/recommended`, fetcher)
if (movieError) return <div>failed to load</div>;
......@@ -94,6 +94,7 @@ export const Movie = () => {
userId={+review.user.id}
text={review.text}
userName={review.user.name}
mutate={mutateReviews}
key={review.id}
/>
)}
......
import { getToken, getUser } from '../services/auth';
import instance from '../models/axios';
import { KeyedMutator } from 'swr/dist/types';
export interface ReviewProps {
id: number,
......@@ -7,9 +8,10 @@ export interface ReviewProps {
text: string,
averageRating: number,
userName: string,
mutate: KeyedMutator<any>,
}
export const Review = ({id, userId, text, averageRating, userName}: ReviewProps) => {
export const Review = ({id, userId, text, averageRating, userName, mutate}: ReviewProps) => {
const user = getUser();
const deleteReview = async () => {
......@@ -18,6 +20,7 @@ export const Review = ({id, userId, text, averageRating, userName}: ReviewProps)
'Authorization': getToken()
};
await instance.delete(`reviews/${id}`, { headers });
await mutate();
alert('Review deleted');
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment