Skip to content

Commit

Permalink
BookMark App Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
jbugayev18 committed Aug 4, 2020
1 parent ce6d4b7 commit e9ba9a1
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 158 deletions.
1 change: 1 addition & 0 deletions bookmark App/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Bookmark App</title><link rel="stylesheet" href="src/styles.css"/><link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@1,600&display=swap" rel="stylesheet"/></head><body><div class="container"><header><h1>Bookmark App</h1></header><div class="error-container"></div><main></main></div><script src="index_bundle.js"></script></body></html>
25 changes: 25 additions & 0 deletions bookmark App/index_bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bookmark App/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"start": "webpack-dev-server --open",
"build": "webpack --mode production"
},
"keywords": [],
Expand Down
105 changes: 62 additions & 43 deletions bookmark App/src/api.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
const BASE_URL= "https://thinkful-list-api.herokuapp.com/juliabugayev";

let fetchBookMark = (...args) => {
let error = null;
return fetch(...args)
.then ((response) => {
if (!response.ok) {
error = {code: response.status};
"use strict";
const BookmarkAPI =
"https://thinkful-list-api.herokuapp.com/juliabugayev/bookmarks";

//...arg takes multiple arguments

const apiFetch = function (...args) {
let error;
return fetch(...args)
.then((Response) => {
if (!Response.ok) {
error = { code: Response.status };

if (!Response.headers.get("content-type").includes("json")) {
error.message = Response.statusText;
return Promise.reject(error);
}
return response.json();
}
return Response.json();
})
.then((data) => {
if (error){
error.message = data.message;
return Promise.reject(error);
}
return data;
})
if (error) {
error.message = data.message;
return Promise.reject(error);
}
return data;
});
};

function deleteBookmark(id) {
return apiFetch(`${BookmarkAPI}/${id}`, {
method: "DELETE",
});
}

function updateBookmark(id, updateInfo) {
const update = JSON.stringify(updateInfo);
return apiFetch(`${BookmarkAPI}/${id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: update,
});
}

function addNewBookmark(bookmark) {
const addBookmark = JSON.stringify(bookmark);
return apiFetch(`${BookmarkAPI}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: addBookmark,
});
}

function obtainBookmark() {
return apiFetch(`${BookmarkAPI}`);
}

let bookMarkDelete =(id) => {
return fetchBookMark(`${BASE_URL}/${id}}`,{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},

});
};

let newBookMarkCreate = (bookmark) => {
let newBookMark = JSON.stringify(bookmark);
return fetchBookMark(BASE_URL , {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
});
};

let bookmarkGet = (bookmark) => {
return fetchBookMark(BASE_URL, {
method: 'GET',
headers:{
'Content-Type': 'application/json',
},
});
};
export default {
deleteBookmark,
obtainBookmark,
addNewBookmark,
updateBookmark,
};
Loading

0 comments on commit e9ba9a1

Please sign in to comment.