Skip to content

Commit 62bcbd2

Browse files
committed
Form data and image publishing
1 parent e9db037 commit 62bcbd2

File tree

9 files changed

+48
-17
lines changed

9 files changed

+48
-17
lines changed

index.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<head>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<link rel="stylesheet" href="./styles/styles.css">
76
<link rel="stylesheet" href="./styles/elements.css">
7+
<link rel="stylesheet" href="./styles/styles.css">
88
<link id="currentTheme" rel="stylesheet" href="./styles/lightTheme.css">
99
<link rel='stylesheet' href='https://cdn-uicons.flaticon.com/uicons-regular-rounded/css/uicons-regular-rounded.css'>
1010
<link rel="preconnect" href="https://fonts.googleapis.com">
@@ -19,9 +19,16 @@ <h1>Random cats app</h1>
1919
<p>
2020
Random cat viewer, choose the image you like the most and mark it as your favorite one
2121
</p>
22-
<button type="button" id="switchTheme">
23-
<i class="fi fi-rr-swatchbook"></i> theme
24-
</button>
22+
<div class="buttonActions">
23+
<button type="button" id="switchTheme">
24+
<i class="fi fi-rr-swatchbook"></i> theme
25+
</button>
26+
<button type="button" id="githubButton">
27+
<a href="https://github.com/danielbatres/api-rest-fundamentals-javascript" target="_blank">
28+
<i class="fi fi-rr-code-compare"></i> Repositorio
29+
</a>
30+
</button>
31+
</div>
2532
<section id="uploadingCat">
2633
<h2></h2>
2734
<form id="uploadingForm">

javascript/api.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ async function postFavorite(imageId) {
2626
});
2727

2828
if (!checkResponse(response)) return;
29-
30-
loadFavoriteCats();
3129
}
3230

3331
async function removeFavorite(id) {
@@ -39,8 +37,19 @@ async function removeFavorite(id) {
3937
});
4038

4139
if (!checkResponse(response)) return;
40+
}
41+
42+
async function uploadPhoto() {
43+
const formData = new FormData(form);
44+
45+
const response = await fetch(API_IMAGE_UPLOAD, {
46+
method: "POST",
47+
headers: {
48+
'X-API-KEY': API_KEY
49+
},
50+
body: formData,
51+
});
4252

43-
loadFavoriteCats();
4453
}
4554

4655
async function checkResponse(response) {

javascript/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const API_KEY = "live_l0ii654AjIwmoMG0NEH0vOPDbD5FllJPEqXF8HIB8nFxMXHhoq37OXCLnk
22
const BASE_API_URL = "https://api.thecatapi.com/v1/";
33
const API_URL = `${BASE_API_URL}images/search?limit=18`;
44
const API_FAVOURITES_API = `${BASE_API_URL}favourites`;
5+
const API_IMAGE_UPLOAD = `${BASE_API_URL}images/upload`;
56
const link = document.getElementById("currentTheme");
67
const form = document.getElementById('uploadingForm');
78
const catsReference = document.getElementById("cats");

javascript/dynamicContent.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ function addCatImage(sourceImage, imageId, isFavorite) {
3030
const removeFavoriteButton = document.createElement("button");
3131
removeFavoriteButton.type = "button";
3232
removeFavoriteButton.textContent = "Remove cat from favorites";
33-
removeFavoriteButton.onclick = () => removeFavorite(imageId);
33+
removeFavoriteButton.onclick = () => {
34+
removeFavorite(imageId);
35+
36+
if (!isRandom) {
37+
loadFavoriteCats();
38+
}
39+
};
3440

3541
options.appendChild(removeFavoriteButton);
3642
}
@@ -53,7 +59,7 @@ function removeLoadingCards() {
5359
function addLoadingCards() {
5460
isLoading = true;
5561

56-
for (let i = 0; i < 10; i++) {
62+
for (let i = 0; i < 20; i++) {
5763
addLoadingCard();
5864
}
5965
}

main.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ async function loadFavoriteCats() {
1818
loadData(data, true);
1919
}
2020

21-
async function uploadPhoto() {
22-
const formData = new FormData(form);
23-
24-
console.log(formData.get('file'));
25-
}
26-
2721
function setTheme() {
2822
isLightThemeColor = !isLightThemeColor;
2923

styles/darkTheme.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:root {
2-
--background-color: rgb(17, 17, 17);
2+
--background-color: rgb(19, 19, 19);
33
--title-color: rgb(255, 255, 255);
44
--text-color: rgb(112, 112, 112);
55
--light-color: rgb(66, 66, 66);

styles/elements.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ ul li {
1313
font-weight: 300;
1414
}
1515

16+
a {
17+
text-decoration: none;
18+
color: var(--background-color);
19+
font-weight: 400;
20+
}
21+
1622
button {
1723
padding: 8px 10px;
1824
border-radius: 8px;
@@ -22,6 +28,7 @@ button {
2228
font-family: var(--font-family);
2329
font-weight: 400;
2430
text-transform: capitalize;
31+
cursor: pointer;
2532
}
2633

2734
ul {

styles/lightTheme.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
:root {
22
--background-color: rgb(255, 255, 255);
33
--title-color: rgb(27, 27, 27);
4-
--text-color: rgb(66, 66, 66);
4+
--text-color: rgb(143, 143, 143);
55
--light-color: rgb(212, 212, 212);
66
--first-loading-color: #f0f0f0;
77
--second-loading-color: #c4c4c4;

styles/styles.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ body {
2727
padding: 20px 10px;
2828
}
2929

30+
.buttonActions {
31+
display: flex;
32+
justify-content: right;
33+
gap: 8px;
34+
padding: 10px 0;
35+
}
36+
3037
#cats {
3138
display: grid;
3239
grid-template-columns: repeat(4, 1fr);

0 commit comments

Comments
 (0)