-
Notifications
You must be signed in to change notification settings - Fork 0
yunhee-week6-hwdone #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: yunhee-week6
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { getCookie } from "../utils/cookie"; | |
| function VotePage() { | ||
| const navigate = useNavigate(); | ||
| const userId = getCookie("userId"); | ||
|
|
||
| const [image, setImage] = useState([]); | ||
| const [thumbsUpImage, setThumbsUpImage] = useState( | ||
| require("../assets/images/thumbs-up-icon.png") | ||
| ); | ||
|
|
@@ -20,8 +20,24 @@ function VotePage() { | |
|
|
||
| const getImage = async () => { | ||
| try { | ||
| // ### TO DO ### | ||
| // ############# | ||
| const response = await axios.get( | ||
| "https://api.thecatapi.com/v1/images/search?limit=1&size=full", | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-api-key": | ||
| "live_ZTJIhVxMYYZVZAzD7evB7nXOEAjLguOs8ny2ybFvKgH6yMMun7mZsBDRjPOx9HTf", | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| const data = response.data[0]; | ||
|
|
||
| const imageSet = { | ||
| id: data.id, | ||
| url: data.url, | ||
| }; | ||
| setImage(imageSet); | ||
| } catch (err) { | ||
| console.log(err); | ||
| } | ||
|
|
@@ -31,11 +47,39 @@ function VotePage() { | |
| try { | ||
| // ### TO DO ### | ||
| // ############# | ||
| const response = await axios.post( | ||
| "https://api.thecatapi.com/v1/votes", | ||
| { | ||
| image_id: image.id, | ||
| sub_id: userId, | ||
| value: val, | ||
| }, | ||
| { | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-api-key": | ||
| "live_ZTJIhVxMYYZVZAzD7evB7nXOEAjLguOs8ny2ybFvKgH6yMMun7mZsBDRjPOx9HTf", | ||
| }, | ||
| } | ||
| ); | ||
| } catch (err) { | ||
| console.log(err); | ||
| } | ||
| }; | ||
|
|
||
| const handleThumbsUpHover = () => { | ||
| setThumbsUpImage(require("../assets/images/thumbs-up-click.png")); | ||
| }; | ||
| const handleThumbsUpLeave = () => { | ||
| setThumbsUpImage(require("../assets/images/thumbs-up-icon.png")); | ||
| }; | ||
| const handleThumbsDownHover = () => { | ||
| setThumbsDownImage(require("../assets/images/thumbs-down-click.png")); | ||
| }; | ||
| const handleThumbsDownLeave = () => { | ||
| setThumbsDownImage(require("../assets/images/thumbs-down-icon.png")); | ||
| }; | ||
|
Comment on lines
+70
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ν¨μλͺ λ μμ£Ό μ μ§μ κ² κ°μ΅λλ€. |
||
|
|
||
| return ( | ||
| <div className="w-full h-screen flex flex-col justify-center items-center gap-10"> | ||
| <div className="absolute top-[5%] right-[16%] flex gap-5"> | ||
|
|
@@ -62,19 +106,25 @@ function VotePage() { | |
| <div className="w-2/3 h-2/3 py-2 border-4 rounded-2xl border-[#FF6841] flex justify-center items-center"> | ||
| <div className="w-full h-[90%] flex justify-evenly items-center"> | ||
| <img | ||
| // ### ONE CAT IMAGE ### | ||
| src={image.url} | ||
| className="w-3/5 h-full border-[3px] rounded-xl border-[#FF6841]" | ||
| /> | ||
| <div className="w-1/3 flex gap-12 justify-center"> | ||
| <img | ||
| src={thumbsUpImage} | ||
| className="w-20 h-20 cursor-pointer" | ||
| // ### thumbsUpImage Event ### | ||
| onMouseOver={handleThumbsUpHover} | ||
| onMouseOut={handleThumbsUpLeave} | ||
| onClick={() => vote(1)} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ λ ν¬ν μ vote(1); νμ getImage(); νΈμΆμ ν΅ν΄ λ€μ ν¬νν μ΄λ―Έμ§λ₯Ό λΆλ¬μλλ° |
||
| /> | ||
| <img | ||
| src={thumbsDownImage} | ||
| className="w-20 h-20 cursor-pointer" | ||
| // ### thumbsDownImage Event ### | ||
| onMouseOver={handleThumbsDownHover} | ||
| onMouseOut={handleThumbsDownLeave} | ||
| onClick={() => vote(-1)} | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μΌνμ°μ°μλ₯Ό μ΄μ©ν΄ μ μ²λ¦¬νλ€μ κ΅Ώ!