Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/routes/FavouriteHistoryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,30 @@ function FavouriteHistoryPage() {

const getImages = async () => {
try {
// ### TO DO ###
// #############
const response = await axios.get(
`https://api.thecatapi.com/v1/favourites?sub_id=${userId}`,
{
headers: {
"Content-Type": "application/json",
"x-api-key":
"live_ZTJIhVxMYYZVZAzD7evB7nXOEAjLguOs8ny2ybFvKgH6yMMun7mZsBDRjPOx9HTf",
},
}
);

const data = response.data;
const imageSet = [];

data.map((e) => {
imageSet.push({
id: e.image.id,
url: e.image.url,
isFavourite: true,
favouriteId: e.id,
});
});

setImages(imageSet);
} catch (err) {
console.log(err);
}
Expand Down
68 changes: 62 additions & 6 deletions src/routes/MainPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,82 @@ function HomePage() {

const getImages = async () => {
try {
// ### TO DO ###
// #############
const response = await axios.get(
"https://api.thecatapi.com/v1/images/search?limit=8&size=small",
{
headers: {
"Content-Type": "application/json",
"x-api-key":
"live_ZTJIhVxMYYZVZAzD7evB7nXOEAjLguOs8ny2ybFvKgH6yMMun7mZsBDRjPOx9HTf",
},
}
);

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);
}
};

const favouritingImage = async (imgId) => {
try {
// ### TO DO ###
// #############
const response = await axios.post(
"https://api.thecatapi.com/v1/favourites",
{
image_id: imgId,
sub_id: userId,
},
{
headers: {
"Content-Type": "application/json",
"x-api-key":
"live_ZTJIhVxMYYZVZAzD7evB7nXOEAjLguOs8ny2ybFvKgH6yMMun7mZsBDRjPOx9HTf",
},
}
);

const newImages = [...images];
const idx = newImages.findIndex((e) => e.id === imgId);
newImages[idx].isFavourite = true;
newImages[idx].favouriteId = response.data.id;

setImages(newImages);
} catch (err) {
console.log(err);
}
};

const unFavouritingImage = async (favouriteId) => {
try {
// ### TO DO ###
// #############
const newImages = [...images];
const idx = newImages.findIndex((e) => e.favouriteId === favouriteId);
newImages[idx].isFavourite = false;
newImages[idx].favouriteId = null;

setImages(newImages);

const response = await axios.delete(
`https://api.thecatapi.com/v1/favourites/${favouriteId}`,
{
headers: {
"Content-Type": "application/json",
"x-api-key":
"live_GKblu8slVg2fFDula9hfgUUWLXlaX6aCWLZpv8pAyFb6Cyhxzq9CkhlwW88Erb0z",
},
}
);
} catch (err) {
console.log(err);
}
Expand Down
14 changes: 9 additions & 5 deletions src/routes/VoteHistoryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ function VoteHistoryPage() {

const getImages = async () => {
try {
let response;
// ### TO DO ###
// #############
const response = await axios.get("https://api.thecatapi.com/v1/votes", {
headers: {
"Content-Type": "application/json",
"x-api-key":
"live_ZTJIhVxMYYZVZAzD7evB7nXOEAjLguOs8ny2ybFvKgH6yMMun7mZsBDRjPOx9HTf",
},
});
const data = response.data;
const imageSet = [];

Expand Down Expand Up @@ -64,8 +68,8 @@ function VoteHistoryPage() {
<img
key={img.url}
src={img.url}
className={`object-cover w-full h-full border-[3px] border-[#FF6841] rounded-xl
### FILL ME ###
className={`object-cover w-full h-full border-[3px] rounded-xl
${img.value === 1 ? "border-[#ff4141]" : "border-[#3457e4]"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ‚Όν•­μ—°μ‚°μžλ₯Ό μ΄μš©ν•΄ 잘 μ²˜λ¦¬ν–ˆλ„€μš” κ΅Ώ!

`}
/>
</div>
Expand Down
58 changes: 54 additions & 4 deletions src/routes/VotePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
Expand All @@ -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);
}
Expand All @@ -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

Choose a reason for hiding this comment

The 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">
Expand All @@ -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)}
Copy link

Choose a reason for hiding this comment

The 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>
Expand Down