From 57cbb08eea17061fcc0f8d59a280db6fc6ad5f4d Mon Sep 17 00:00:00 2001 From: ArthurNNN Date: Wed, 7 Apr 2021 19:23:21 +0200 Subject: [PATCH 1/4] gallery v1.0 --- app.html | 51 ++++++++++++++++++++++++--------------------------- app.js | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/app.html b/app.html index 06cc807..22fd0cf 100644 --- a/app.html +++ b/app.html @@ -1,32 +1,29 @@ - - - Gallery - - -
-

- Gallery -

-

Share all your photos right here

-
- -
- +
+ + - - - - - +
+ +
+ + + + + \ No newline at end of file diff --git a/app.js b/app.js index 0da6bde..90c7c32 100644 --- a/app.js +++ b/app.js @@ -12,4 +12,28 @@ fetch('url').then(ResolveFuntion, RejectFuntion) */ +fetch(URL) + .then(function (response) { + console.log(response); + return response.json(); + }) + .then(function (data) { + console.log(data); + let divR = document.createElement("div"); + divR.className = "row"; + app.appendChild(divR); + data.forEach(item => { + let divC = document.createElement("div"); + divC.className = "column"; + let img = document.createElement("img"); + img.src = item.url; + divC.appendChild(img); + divR.appendChild(divC); + }); + }); + const app = document.querySelector("#app"); + + + + From d82ab0ed4bb8ace0dc3795f6810a5a9c5a1c37d3 Mon Sep 17 00:00:00 2001 From: ArthurNNN Date: Wed, 7 Apr 2021 19:26:20 +0200 Subject: [PATCH 2/4] gallery v1.1 --- app.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 90c7c32..f13b3dd 100644 --- a/app.js +++ b/app.js @@ -14,14 +14,9 @@ fetch('url').then(ResolveFuntion, RejectFuntion) fetch(URL) .then(function (response) { - console.log(response); return response.json(); }) .then(function (data) { - console.log(data); - let divR = document.createElement("div"); - divR.className = "row"; - app.appendChild(divR); data.forEach(item => { let divC = document.createElement("div"); divC.className = "column"; @@ -34,6 +29,8 @@ fetch(URL) const app = document.querySelector("#app"); - +let divR = document.createElement("div"); +divR.className = "row"; +app.appendChild(divR); From d95a77e79406753e922e6b72875769e7f1f9ccba Mon Sep 17 00:00:00 2001 From: ArthurNNN Date: Wed, 7 Apr 2021 19:37:35 +0200 Subject: [PATCH 3/4] gallery v1.1 refactoring --- app.html | 3 --- app.js | 13 +++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app.html b/app.html index 22fd0cf..3aee824 100644 --- a/app.html +++ b/app.html @@ -19,9 +19,6 @@

-
- -
diff --git a/app.js b/app.js index f13b3dd..81d1aa9 100644 --- a/app.js +++ b/app.js @@ -12,11 +12,16 @@ fetch('url').then(ResolveFuntion, RejectFuntion) */ +const app = document.querySelector("#app"); +let divR = document.createElement("div"); +divR.className = "row"; +app.appendChild(divR); + fetch(URL) - .then(function (response) { + .then((response) => { return response.json(); }) - .then(function (data) { + .then((data) => { data.forEach(item => { let divC = document.createElement("div"); divC.className = "column"; @@ -27,10 +32,6 @@ fetch(URL) }); }); -const app = document.querySelector("#app"); -let divR = document.createElement("div"); -divR.className = "row"; -app.appendChild(divR); From a66b68cd067f7d8d936f12bed1a466fe7d618e3e Mon Sep 17 00:00:00 2001 From: ArthurNNN Date: Tue, 20 Apr 2021 15:21:25 +0200 Subject: [PATCH 4/4] Gallery add errors check and p-element with a title and an author --- app.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 81d1aa9..4adceae 100644 --- a/app.js +++ b/app.js @@ -19,7 +19,13 @@ app.appendChild(divR); fetch(URL) .then((response) => { - return response.json(); + if (response.status >= 200 && response.status <= 299) { + return response.json(); + } else { + throw new Error( + `Encountered something unexpected: ${response.status} ${response.statusText}` + ); + } }) .then((data) => { data.forEach(item => { @@ -27,11 +33,14 @@ fetch(URL) divC.className = "column"; let img = document.createElement("img"); img.src = item.url; + let p = document.createElement("p"); + p.textContent = item.author + " - " + item.title; divC.appendChild(img); + divC.appendChild(p); divR.appendChild(divC); }); - }); - - - - + }) + .catch((error) => { + // Handle the error + console.log(error); + }); \ No newline at end of file