diff --git a/src/routes/VoteHistoryPage.jsx b/src/routes/VoteHistoryPage.jsx index 2f12755..144934c 100644 --- a/src/routes/VoteHistoryPage.jsx +++ b/src/routes/VoteHistoryPage.jsx @@ -15,9 +15,16 @@ function VoteHistoryPage() { const getImages = async () => { try { - let response; // ### TO DO ### - // ############# + let response = await axios.get("https://api.thecatapi.com/v1/votes", { + headers: { + "x-api-key": + "live_5xeBiFG48vOmeu9XXpYOu4Zs9dKtcIgRkFJcKZWigEXma3ckAjkA7V3pKxSjMcHO", + }, + params: { + sub_id: userId, + }, + }); const data = response.data; const imageSet = []; @@ -60,13 +67,18 @@ function VoteHistoryPage() {
{images.map((img) => ( -
+
Voted Cat 0 ? "blue" : "red", + borderStyle: "solid", + }} />
))} diff --git a/src/routes/VotePage.jsx b/src/routes/VotePage.jsx index c77d27f..a7213ab 100644 --- a/src/routes/VotePage.jsx +++ b/src/routes/VotePage.jsx @@ -14,14 +14,40 @@ function VotePage() { require("../assets/images/thumbs-down-icon.png") ); + const [hoverThumbsUp, setHoverThumbsUp] = useState(false); + const [hoverThumbsDown, setHoverThumbsDown] = useState(false); + + const [images, setImages] = useState([]); useEffect(() => { getImage(); }, []); const getImage = async () => { try { - // ### TO DO ### - // ############# + const response = await axios.get( + "https://api.thecatapi.com/v1/images/search?limit=1&size=large", + { + headers: { + "Content-Type": "application/json", + "x-api-key": + "live_5xeBiFG48vOmeu9XXpYOu4Zs9dKtcIgRkFJcKZWigEXma3ckAjkA7V3pKxSjMcHO", + }, + } + ); + + const data = response.data; + const imageSet = []; + + data.map((e) => { + imageSet.push({ + id: e.id, + url: e.url, + isFavourite: false, + favouriteId: null, + }); + }); + + setImages(imageSet); } catch (err) { console.log(err); } @@ -29,8 +55,22 @@ function VotePage() { const vote = async (val) => { try { - // ### TO DO ### - // ############# + const response = await axios.post( + "https://api.thecatapi.com/v1/votes", + { + image_id: images[0].id, + sub_id: userId, + value: val, + }, + { + headers: { + "Content-Type": "application/json", + "x-api-key": + "live_5xeBiFG48vOmeu9XXpYOu4Zs9dKtcIgRkFJcKZWigEXma3ckAjkA7V3pKxSjMcHO", + }, + } + ); + getImage(); } catch (err) { console.log(err); } @@ -63,6 +103,8 @@ function VotePage() {
0 ? images[0].url : "default-placeholder.png"} + alt="Cat" className="w-3/5 h-full border-[3px] rounded-xl border-[#FF6841]" />
@@ -70,11 +112,21 @@ function VotePage() { src={thumbsUpImage} className="w-20 h-20 cursor-pointer" // ### thumbsUpImage Event ### + style={{ filter: hoverThumbsUp ? "hue-rotate(180deg)" : "none" }} + onMouseEnter={() => setHoverThumbsUp(true)} + onMouseLeave={() => setHoverThumbsUp(false)} + onClick={() => vote(1)} /> setHoverThumbsDown(true)} + onMouseLeave={() => setHoverThumbsDown(false)} + onClick={() => vote(-1)} />