-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64a59f4
commit 39c1629
Showing
17 changed files
with
463 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// import {useLocation, useNavigate} from "react-router-dom"; | ||
// import ButtonSubmitDefault from "../Buttons/ButtonSubmitDefault.jsx"; | ||
// import {useEffect, useState} from "react"; | ||
// import {useSelector} from "react-redux"; | ||
// import useCreateReview from "../../hooks/useCreateReview.jsx"; | ||
// | ||
// const ReviewReadArtist = ({ reviewId }) => { | ||
// const [reviewTitle, setReviewTitle] = useState(''); | ||
// const [reviewBody, setReviewBody] = useState(''); | ||
// const [spotifyId, setSpotifyId] = useState(''); | ||
// const [name, setName] = useState(''); | ||
// const [coverImage, setCoverImage] = useState(''); | ||
// | ||
// const userId = useSelector((state) => state.user.userData); | ||
// const reviews = useSelector((state) => state.reviewArtistData.items); | ||
// const review = reviews.find((review) => review.id === reviewId); | ||
// | ||
// useEffect(() => { | ||
// if (review) { | ||
// setReviewTitle(review.title || ''); | ||
// setReviewBody(review.body || ''); | ||
// setSpotifyId(review.spotifyId || ''); | ||
// setName(review.name || ''); | ||
// setCoverImage(review.coverImage || ''); | ||
// } | ||
// }, [review]); | ||
// | ||
// const [errorReview, setErrorReview] = useState(""); | ||
// const [isLoading, setIsLoading] = useState(false); | ||
// const navigate = useNavigate(); | ||
// const location = useLocation(); | ||
// | ||
// const to = location.state?.from || "/artists"; | ||
// | ||
// const getSubmitData = async (e) => { | ||
// e.preventDefault(); | ||
// setErrorReview(""); | ||
// setIsLoading(true); | ||
// try { | ||
// const data = { spotifyId, coverImage, reviewTitle, reviewBody, reviewType ,userId }; | ||
// const res = await createReview(data); | ||
// if (res === 200) | ||
// navigate(to); | ||
// } catch (error) { | ||
// setErrorReview(error.message || "Failed to register. Please try again."); | ||
// } finally { | ||
// setIsLoading(false); | ||
// } | ||
// }; | ||
// | ||
// return ( | ||
// <div className="flex flex-col justify-start pt-6 items-center min-h-[60vh]"> | ||
// | ||
// <div className="max-w-lg w-[95vw] p-6"> | ||
// <h2 className="text-xl font-semibold text-start mt-2 mb-2">A new review about: "{item.name}"</h2> | ||
// <form onSubmit={getSubmitData}> | ||
// <div className="mb-4"> | ||
// <label htmlFor="reviewTitle" className="block mb-2 text-sm text-accent-content"> | ||
// Review title | ||
// </label> | ||
// <input | ||
// name="reviewTitle" | ||
// id="reviewTitle" | ||
// type="text" | ||
// value={reviewTitle} | ||
// onChange={(e) => setReviewTitle(e.target.value)} | ||
// required | ||
// className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-secondary" | ||
// /> | ||
// </div> | ||
// <div className="mb-2"> | ||
// <label htmlFor="reviewBody" className="block mb-2 text-sm text-accent-content"> | ||
// Review (accepts HTML) | ||
// </label> | ||
// <textarea | ||
// name="reviewBody" | ||
// id="reviewBody" | ||
// value={reviewBody} | ||
// onChange={(e) => setReviewBody(e.target.value)} | ||
// required | ||
// rows={5} | ||
// className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-secondary" | ||
// /> | ||
// </div> | ||
// | ||
// <div className="text-center"> | ||
// {errorReview && <p className="text-error text-sm mt-2">{errorReview}</p>} | ||
// <ButtonSubmitDefault | ||
// buttonName={isLoading ? "Sending review..." : "Send the review"} | ||
// type="submit" | ||
// disabled={isLoading || reviewTitle === "" || reviewBody === ""} | ||
// /> | ||
// </div> | ||
// </form> | ||
// {error && <p className="text-error text-sm mt-2">{error}</p>} | ||
// </div> | ||
// </div> | ||
// ) | ||
// } | ||
// export default ReviewReadArtist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {useLocation, useNavigate} from "react-router-dom"; | ||
import ButtonSubmitDefault from "../Buttons/ButtonSubmitDefault.jsx"; | ||
import {useState} from "react"; | ||
import {useSelector} from "react-redux"; | ||
import useCreateReview from "../../hooks/useCreateReview.jsx"; | ||
|
||
const ReviewWriteArtist = ({ item }) => { | ||
const [reviewTitle, setReviewTitle] = useState(''); | ||
const [reviewBody, setReviewBody] = useState(''); | ||
const spotifyId = item.id; | ||
const name = item.name; | ||
const image = item.images?.[0]; | ||
const coverImage = image?.url; | ||
const userId = useSelector((state) => state.user.userData).id; | ||
const reviewType = 0; // Artist = 0 | ||
|
||
const { createReview, error } = useCreateReview(); | ||
const [errorReview, setErrorReview] = useState(""); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
||
const to = location.state?.from || "/artists"; | ||
|
||
const getSubmitData = async (e) => { | ||
e.preventDefault(); | ||
setErrorReview(""); | ||
setIsLoading(true); | ||
try { | ||
const data = { spotifyId, coverImage, reviewTitle, reviewBody, reviewType ,userId }; | ||
const res = await createReview(data); | ||
if (res === 200) | ||
navigate(to); | ||
} catch (error) { | ||
setErrorReview(error.message || "Failed to register. Please try again."); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col justify-start pt-6 items-center min-h-[60vh]"> | ||
|
||
<div className="max-w-lg w-[95vw] p-6"> | ||
<h2 className="text-xl font-semibold text-start mt-2 mb-2">A new review about: "{item.name}"</h2> | ||
<form onSubmit={getSubmitData}> | ||
<div className="mb-4"> | ||
<label htmlFor="reviewTitle" className="block mb-2 text-sm text-accent-content"> | ||
Review title | ||
</label> | ||
<input | ||
name="reviewTitle" | ||
id="reviewTitle" | ||
type="text" | ||
value={reviewTitle} | ||
onChange={(e) => setReviewTitle(e.target.value)} | ||
required | ||
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-secondary" | ||
/> | ||
</div> | ||
<div className="mb-2"> | ||
<label htmlFor="reviewBody" className="block mb-2 text-sm text-accent-content"> | ||
Review (accepts HTML) | ||
</label> | ||
<textarea | ||
name="reviewBody" | ||
id="reviewBody" | ||
value={reviewBody} | ||
onChange={(e) => setReviewBody(e.target.value)} | ||
required | ||
rows={5} | ||
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-secondary" | ||
/> | ||
</div> | ||
|
||
<div className="text-center"> | ||
{errorReview && <p className="text-error text-sm mt-2">{errorReview}</p>} | ||
<ButtonSubmitDefault | ||
buttonName={isLoading ? "Sending review..." : "Send the review"} | ||
type="submit" | ||
disabled={isLoading || reviewTitle === "" || reviewBody === ""} | ||
/> | ||
</div> | ||
</form> | ||
{error && <p className="text-error text-sm mt-2">{error}</p>} | ||
</div> | ||
</div> | ||
) | ||
} | ||
export default ReviewWriteArtist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {useDispatch} from "react-redux"; | ||
import {useCallback, useState} from "react"; | ||
import {storeReviewArtistData} from "../store/slices/reviewArtistReducer.js"; | ||
import {storeReviewAlbumData} from "../store/slices/reviewAlbumReducer.js"; | ||
import {storeReviewTrackData} from "../store/slices/reviewTrackReducer.js"; | ||
import {Create} from "../axios/reviewAxios.js"; | ||
|
||
const useCreateReview = () => { | ||
const dispatch = useDispatch(); | ||
const [error, setError] = useState(null); | ||
|
||
const createReview = useCallback(async (data) => { | ||
setError(null); | ||
try { | ||
const reviewResponse = await Create(data); | ||
const payload = { | ||
items: [reviewResponse.data], | ||
totalCount: 1, // Increment total count | ||
}; | ||
|
||
switch (data.reviewType) { | ||
case 0: | ||
dispatch(storeReviewArtistData(payload)); | ||
break; | ||
case 1: | ||
dispatch(storeReviewAlbumData(payload)); | ||
break; | ||
case 2: | ||
dispatch(storeReviewTrackData(payload)); | ||
break; | ||
default: | ||
setError("Invalid review type provided."); | ||
return; | ||
} | ||
|
||
return reviewResponse.status; | ||
} catch (error) { | ||
setError(error.message || "An error occurred during login."); | ||
throw error; | ||
} | ||
}, [dispatch]); | ||
|
||
return { createReview, error }; | ||
}; | ||
export default useCreateReview; |
Oops, something went wrong.