Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
22019c2
first commit
seficohen1 May 11, 2022
e499a14
Delete script.js
seficohen1 May 11, 2022
f78d32b
files in folders
Dejahar May 11, 2022
55afc55
added json server package
seficohen1 May 11, 2022
3dc9448
merging to main
seficohen1 May 11, 2022
be576cf
new post
Dejahar May 12, 2022
e95e45a
develop branch
Dejahar May 12, 2022
69d369c
adding first layout of the blog and the modal
seficohen1 May 12, 2022
7ac23f3
Merge branch 'develop' of https://github.com/Dejahar/blog-with-api in…
seficohen1 May 12, 2022
1c101c3
card Posts
Dejahar May 12, 2022
bb3ef85
created utility.js
Dejahar May 12, 2022
d72659b
randomiser for pictures
Dejahar May 12, 2022
0ec48d3
modal buttons XL large added
Dejahar May 12, 2022
dfdca00
trying to figure how to attribute each modal to each post
seficohen1 May 12, 2022
dc802ba
added data-bs-postID to our modal buttons
Dejahar May 13, 2022
ed93a9a
modifiyng handle modal and function to retrieve the correct post id
Dejahar May 13, 2022
2fcec54
git ignore
Dejahar May 13, 2022
9bb2038
modular user img, post title, post body
Dejahar May 13, 2022
5bec16a
added handleComments function to read all comments of a post in a col…
seficohen1 May 13, 2022
7ad1aa4
updates
Dejahar May 13, 2022
85643e4
added changes to bootstrap, attemps at reseting the modal, postId add…
Dejahar May 15, 2022
6aa0558
comments now reset when closed
Dejahar May 15, 2022
9623b7f
multiple modals working
Dejahar May 16, 2022
6b4e266
edit modal with post text for edition
Dejahar May 16, 2022
e5cd00a
edit button complete
Dejahar May 16, 2022
898f2c9
delete button and delete function added
Dejahar May 16, 2022
d19712e
removed postId from comments
Dejahar May 16, 2022
ebc7bc2
main merge
Dejahar May 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
157 changes: 157 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous">
</script>
<script type="module" src="./main.js"></script>
<script src="https://kit.fontawesome.com/1c78a02b22.js" crossorigin="anonymous"></script>
<title>Document</title>
</head>

<body>
<header>
<nav class="navbar navbar-light bg-light d-flex">
<div class="container-fluid justify-content-center navbar fixed-top navbar-light bg-light">
<span class="navbar-brand mb-0 h1">Blog-erino</span>
</div>
</nav>
</header>
<article>
<div class="container mt-md-5" id="blog-container">
<div class="row border border-primary " id="posts-container">
<div class="row d-flex justify-content-center" id='card-container'>

<!-- posts main view -->
<div class="card mb-3 " style="max-width: 540px;" id="cardTemplate" hidden>
<div class="row g-0">
<div class="col-md-4">
<img src="" class="img-fluid rounded-start" alt="..." id="cardIMG">
</div>
<div class="col-md-8">
<div class="card-body" id="cardBody">
<h5 class="card-title" id="cardTitle"></h5>
<p class="card-text" id="cardText"></p>
<p class="card-text"><small class="text-muted" id="cardComments"></small></p>
<button type="button" id="modalButton" class="btn btn-primary position-absolute bottom-0 end-1 m-1"
data-bs-postID="" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
Check Post
</button>
<div class="position-absolute bottom-0 end-0 p-1">
<button type="button" id="deleteBtn" class="btn btn-danger" data-bs-toggle="modal"
data-bs-target="#deleteModal" data-bs-postID="">
<img src="./src/assets/icons/icons8-delete-100.png" width="20" />
</button>
<button type="button" id="editBtn" class="btn btn-primary" data-bs-toggle="modal"
data-bs-target="#editModal" data-bs-postID="">
<img src="./src/assets/icons/icons8-edit-50.png" width="20" />
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</article>

<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header p-3 mb-2 bg-primary text-white ">
<h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="modal-body">
...
</div>
<div class="container px-3 py-3">
<div class="row gx-0">
<div class="col">
<img id="userImg" class="rounded-circle p-2" src="" alt="...">
</div>
<div class="col px-0 py-5">
<h6 class="modal-user" id="modal-user-name">user name</h6>
<h6 class="modal-user" id="modal-user-email">user mail</h6>
</div>
<div class="col">
</div>
<div class="col py-5">
<h6 class="modal-user" id="">
<i class="fa-brands fa-facebook"></i>
<i class="fa-brands fa-github"></i>
<i class="fa-brands fa-linkedin"></i></h6>
</div>
</div>
</div>
<div class="container mb-2">
<button class="btn btn-primary mb-2" id="commentsBtn" type="button" data-bs-toggle="collapse"
data-bs-target="#comments-wrapper" aria-expanded="false" aria-controls="collapseExample">
Comments
</button>
<div class="collapse" id="comments-wrapper">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

<!-- deleting modal -->
<div class="modal fade" id="deleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header p-3 mb-2 bg-primary text-white ">
<h5 class="modal-title" id="staticBackdropLabel">Post Delete</h5>
<!-- <div id="deletePostID" hidden></div> -->
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to delete this post?
</div>
<div class="modal-footer">
<button type="submit" id="submitDelete" class="btn btn-secondary" data-dismiss="modal">Yes</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
</div>
</div>
</div>
</div>

<!-- edit post -->
<div class="modal fade" id="editModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header p-3 mb-2 bg-primary text-white ">
<h5 class="modal-title" id="staticBackdropLabel">Post Edit</h5>
<div id="editPostID" hidden></div>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form class="row d-flex" id="editForm">
<label for="editTitle"> Title </label>
<input type="text" name="editTitle" id="editTitle">

<label for="editBody"> Main text </label>
<input type="text" name="editBody" id="editBody">
</form>
<div class="modal-footer">
<button type="submit" id="submitEdit" class="btn btn-secondary" data-bs-dismiss="modal">Edit</button>
</div>
</div>
</div>
</div>

</body>

</html>
79 changes: 79 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
createPost,
handleModal,
handleComments,
handleEdit,
handleSubmit,
handleDelete
} from "./src/js/utility.js";

const urlPosts = "http://localhost:3000/posts";//limit of posts
const urlUsers = "http://localhost:3000/users";
const urlComments = "http://localhost:3000/comments";

document.getElementById("blog-container").scrollIntoView();

const onLoad = () => {
allPosts.map(post => {
if (post.title)
createPost(post, allUsers);
});
}

const getPosts = async () => {
const response = await fetch(urlPosts)
const posts = await response.json()
return posts
}

const getUsers = async () => {
const response = await fetch(urlUsers)
const users = await response.json()
return users
}

const getComments = async () => {
const response = await fetch(urlComments)
const comments = await response.json()
return comments
}

const allUsers = await getUsers();
const allPosts = await getPosts();
const allComments = await getComments()

const modalTemplate = document.getElementById('staticBackdrop');
modalTemplate.addEventListener('show.bs.modal', e => {
let button = e.relatedTarget;
let postId = button.getAttribute('data-bs-postID');

handleModal(allPosts, postId, allUsers);
handleComments(postId, allComments);
})

modalTemplate.addEventListener('hidden.bs.modal', function () {
document.getElementById("comments-wrapper").setAttribute("class", "collapse");
})

const editModal = document.getElementById("editModal");
editModal.addEventListener('show.bs.modal', e => {
let button = e.relatedTarget;
let postId = button.getAttribute('data-bs-postID');

handleEdit(postId, allPosts);
})

const submitEdit = document.getElementById("submitEdit");
submitEdit.addEventListener("click", () => {
handleSubmit();
})

const deleteModal = document.getElementById("deleteModal");
deleteModal.addEventListener('show.bs.modal', e => {
let button = e.relatedTarget;
let postId = button.getAttribute('data-bs-postID');

handleDelete(postId, allPosts);
})

window.onload = onLoad();
1 change: 1 addition & 0 deletions node_modules/.bin/is-ci

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/is-ci.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/is-ci.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json-server

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/json-server.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/json-server.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/mime.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/nanoid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading