-
Notifications
You must be signed in to change notification settings - Fork 70
Team 1 blog-API #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gaerste
wants to merge
39
commits into
assembler-institute:main
Choose a base branch
from
Gaerste:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Team 1 blog-API #46
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f403382
ad package json and .gitignore
Gaerste 8046cc3
feature(structure html and the dialog)
Gaerste 6ad69e8
feature(add the folder structure)
Gaerste 97a014e
feature(added fetchPosts() and displayPosts() in main)
blakejohns5 d967c02
Add links for bootstrap and temporary title
blakejohns5 4747ac2
feature(add links botstrap)
Gaerste b0deda8
feature(add links botstrap)
Gaerste 3f1331c
Initial commit add style with bootstrap to main
blakejohns5 0e5467b
feature(add the modal whit bootstrap and header fixed)
Gaerste 50f41b4
Changes to main style, possible conflicts with feature-style-modal on…
blakejohns5 a5e16f9
Changes from feature-style-modal adopted during merge from feature-st…
blakejohns5 1d280d3
Changes from feature-style-modal adopted during merge from feature-st…
blakejohns5 9d1f869
Add to main: flex, wrap, spacing, color changes
blakejohns5 73e51dd
Feature: Add modal to html, email and username
blakejohns5 fa645a3
feature: add showTitleBody & showUserEmail in the modal
Gaerste 3591a7b
feature: add fonts style
Gaerste 9676e6d
feature: style main title
Gaerste 23c51a9
Add possible .svgs. Add color scheme to main, background transparency…
blakejohns5 7cd1cc4
Change size header, remove redundant classes
blakejohns5 1c14b1b
Add new font to header, remove nav menu
blakejohns5 d36431f
feature:add font title
Gaerste 500f89f
feature: add folder fonts
Gaerste a41a093
Add comments functionality and removeComments()
blakejohns5 ab26220
Fix style on brand initials and icon, left side header
blakejohns5 28c06a5
Change assets directory, change header, remove logo
blakejohns5 997434e
feature:add background-image
Gaerste 08c33cb
Add basic console.log function for searchBar, adapt getPostData for a…
blakejohns5 7ddea1b
Add search functionality and separate to search.js
blakejohns5 56a7658
Add comments to search.js and to changed functions on main page
blakejohns5 1fc3cc3
feature:post grid fixed
Gaerste 4d6efa0
testing
Gaerste aefd6ed
feature: add transition in the src-btn
Gaerste aa88a78
feature: refactor and add comments
Gaerste 7bfd182
Refactor
Gaerste f1e56dc
Add README.md file and related imgs to assets
blakejohns5 e66f6b3
Merge branch 'main' of https://github.com/Gaerste/blog-with-api
blakejohns5 7f26687
fix header img link in readme
blakejohns5 62a1df4
Correction to readme
blakejohns5 810972b
Set offset for main page post section
blakejohns5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules | ||
| package-lock.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,60 +1,42 @@ | ||
| `#html` `#css` `#js` `#dom` `#JSON` `#HTTP` `#API` `#Bootstrap` `#master-in-software-development` | ||
| # News Blog with API | ||
| Our blog adopts a design inspired by well-known newspapers and news websites, such as The Guardian, The Washington Post, The New York Times. Our goal for the design focused on simplicity and functionality for the user. | ||
|
|
||
| # Blog with API <!-- omit in toc --> | ||
| It was important for us to be able to access different endpoints for the {JSON}Placeholder API. Although we did not incorporate POST and DELETE functions for the blog posts, the code is scalable and this implementation is planned for future versions. | ||
|
|
||
| <p> | ||
| <img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" /> | ||
| </p> | ||
|  | ||
|
|
||
| > In this pill you will put into practice the knowledge learned about making HTTP requests to create a blog consuming the information from a third-party API. You will also learn how to use Bootstrap Framework for the layout. | ||
|
|
||
| ## Index <!-- omit in toc --> | ||
| ## Planning | ||
|
|
||
| - [Requirements](#requirements) | ||
| - [Repository](#repository) | ||
| - [Technologies used](#technologies-used) | ||
| - [Project delivery](#project-delivery) | ||
| - [Resources](#resources) | ||
| We began the project by outlining the project, using tools like Trello for workflow, as well as Figma and Miró for basic design plans. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - You must use semantic HTML5 elements for all the contents of the application | ||
| - You must use JSON server library to create your own local repository | ||
| - You must use fecth to do the requests | ||
| - You have to use Bootstrap Framework for the Layout and the styles | ||
|
|
||
|
|
||
| ## Repository | ||
| Day 1 of the project was dedicated toward planning the functionality and design of the app. | ||
|
|
||
| First of all you must fork this project into your GitHub account. | ||
| Day 2 began by setting up a local JSON server for testing, then moving on to basic HTML structure and Javascript functionality. | ||
|
|
||
| To create a fork on GitHub is as easy as clicking the “fork” button on the repository page. | ||
| On Day 3, we focused on accessing the JSON data and displaying successfully on the main page, testing several methods, finally settling on *fetch*, using a mix of standard and async functions. | ||
|
|
||
| <img src="https://docs.github.com/assets/images/help/repository/fork_button.jpg" alt="Fork on GitHub" width='450'> | ||
| On Day 4, the design and visual aspect was improved by further integrating Bootstrap 5 classes into the HTML and Javascript. Then time was spent refactoring main functions. | ||
|
|
||
| ## Technologies used | ||
|
|
||
| \* HTML | ||
|  | ||
|
|
||
| \* CSS | ||
|  | ||
|
|
||
| \* JS | ||
|  | ||
|
|
||
| \* Bootstrap | ||
|
|
||
| \* HTTP Requests | ||
|
|
||
| \* JSON | ||
|
|
||
| \* API | ||
| ## Requirements | ||
|
|
||
| ## Project delivery | ||
| -Use {JSON}Placeholder API with endpoints for users, comments, and posts. | ||
| -Use fetch method for HTTP requests. | ||
| -Use Bootstrap to add style to the website. | ||
|
|
||
| To deliver this project you must follow the steps indicated in the document: | ||
| ## Attribution | ||
|
|
||
| - [Submitting a solution](https://www.notion.so/Submitting-a-solution-524dab1a71dd4b96903f26385e24cdb6) | ||
| Illustration on main page from Undraw (https://undraw.co/illustrations) | ||
| Icon on header by Icons8 (https://icons8.com) | ||
|
|
||
| ## Resources | ||
| ## The Team | ||
|
|
||
| - [JSON server](https://github.com/typicode/json-server) | ||
| - [Official Bootstrap](https://getbootstrap.com/) | ||
| Alejandro Gaerste Steger (https://github.com/Gaerste/) | ||
| Blake Johnson (https://github.com/blakejohns5) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <!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.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | ||
| <link rel="stylesheet" href="./src/css/style.css"> | ||
| <script src="./src/js/main.js" type="module"></script> | ||
| <title>The Dispatch</title> | ||
| </head> | ||
| <body> | ||
| <!-- main --> | ||
| <nav id="blogHeader" class="blog__header navbar sticky-top container-fluid p-5 d-flex align-items-center justify-content-center"> | ||
| <div class="blog__logo d-flex"> | ||
| <a href="index.html" class="blog__header--title navbar-brand text-dark"><h1 class="blog__header--title">The Post Dispatch<img src="./assets/icons8-bugle-50.png" class="navbar__logo-img" alt="bugle icon"></h1></a> | ||
| </div> | ||
| <div class="header__form"> | ||
| <form class="form-inline d-flex gap-3"> | ||
| <input id="headerSearch" class="src__header form-control " type="search" placeholder="Search" aria-label="Search"> | ||
| <button id="headerSearchBtn" class="btn btn-outline-success my-2 my-sm-0" type="button">Search</button> | ||
| </form> | ||
| </div> | ||
| </nav> | ||
| <!-- main content --> | ||
| <main id="mainContent" class="main__content d-flex align-items-center pt-5"> | ||
| <article id="postDisplay" class="d-flex container pt-5 flex-md-wrap justify-content-center overflow-auto gap-3 offset-lg-4"> | ||
| <!-- post content --> | ||
| </article> | ||
| <!-- modal --> | ||
| <dialog id="modal" class="modal__dialog modal fade"> | ||
| <!-- modal content --> | ||
| <article id="modalContent" class="modal-dialog modal-dialog-centered"> | ||
| <div class="modal-content"> | ||
| <header id="modalHeader" class="modal-header"> | ||
| <!-- title of the modal --> | ||
| <h3 id="modalTitle" class="modal-title">Title</h3> | ||
| <!-- btn to close the modal --> | ||
| <button class="btn-close" data-bs-dismiss="modal" type="button"></button> | ||
| </header> | ||
| <section id="modalBody" class="modal-body"> | ||
| <h5>Username</h5> | ||
| <p id="modalUsername" class="modal__username">username</p> | ||
| <h5>Email</h5> | ||
| <p id="modalEmail" class="modal__email">email</p> | ||
| <p id="modalText"> | ||
| </p> | ||
| </section> | ||
| <section id="modalComments" class="modal-footer"> | ||
| <button type="button" id="btnComments" class="btn btn-secondary" data-bs-dismiss="modal"> | ||
| Close | ||
| </button> | ||
| <button | ||
| type="button" | ||
| id="commentsContentBtn" | ||
| class="btn btn-primary" | ||
| > | ||
| Loads Comments | ||
| </button> | ||
| </section> | ||
| <section id="commentsContentBody" class="comments__content container-fluid overflow-auto"> | ||
| </section> | ||
| </div> | ||
| </article> | ||
| </dialog> | ||
| </main> | ||
| <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> | ||
|
|
||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "blog-with-api", | ||
| "version": "1.0.0", | ||
| "description": "`#html` `#css` `#js` `#dom` `#JSON` `#HTTP` `#API` `#Bootstrap` `#master-in-software-development`", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "server": "json-server --watch ./src/data/db.json" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/Gaerste/blog-with-api.git" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "bugs": { | ||
| "url": "https://github.com/Gaerste/blog-with-api/issues" | ||
| }, | ||
| "homepage": "https://github.com/Gaerste/blog-with-api#readme", | ||
| "dependencies": { | ||
| "json-server": "^0.17.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| @import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,300;0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;0,6..72,800;1,6..72,300;1,6..72,400;1,6..72,500;1,6..72,600;1,6..72,700;1,6..72,800&display=swap'); | ||
| /* fonts */ | ||
| @font-face { | ||
| font-family: "old london"; | ||
| src: url("/src/fonts/old_london/OldLondon.ttf"); | ||
| } | ||
| /* header src */ | ||
| .src__header{ | ||
| transition: all 0.85s cubic-bezier(0.68, -0.55, 0.265, 1.55); | ||
| content: ''; | ||
| width: 50%; | ||
| height: 100%; | ||
| background: black; | ||
| height: 4vh; | ||
| } | ||
| /* btn src */ | ||
| .btn{ | ||
| transition: all 0.85s cubic-bezier(0.68, -0.55, 0.265, 1.55); | ||
| content: ''; | ||
| width: 50%; | ||
| height: 100%; | ||
| background: black; | ||
| height: 4vh; | ||
| width: 6vw; | ||
| text-align: center; | ||
| } | ||
| /* main title */ | ||
| .blog__header--title{ | ||
| text-decoration: none; | ||
| margin: 0 2rem; | ||
| font-family: 'old london'; | ||
| font-size: 3.5rem; | ||
| } | ||
| /* main background-image */ | ||
| .main__content{ | ||
| background-image: url("/assets/undraw_news_re_6uub_tall_fit.svg"); | ||
| background-attachment: fixed; | ||
| background-repeat: no-repeat; | ||
| background-size: 53vh; | ||
| background-position: left; | ||
| overflow: hidden; | ||
| background-color: var(--bg-custom); | ||
| } | ||
| .blog__header{ | ||
| background-color: var(--bg-header-custom); | ||
| } | ||
| /* color of the website */ | ||
| :root { | ||
| --bg-custom: #f2ddc3; | ||
| --bg-header-custom: #ebba7e; | ||
| } | ||
|
|
||
| /* nav logo */ | ||
| .navbar__logo-img { | ||
| transform: rotate(-45deg); | ||
| margin: 0 2rem; | ||
| } | ||
|
|
||
| /* post style */ | ||
| .post__container { | ||
| border-bottom: solid .5rem var(--bg-header-custom); | ||
| border-radius: 1rem 1rem 0 0; | ||
| font-family: 'Newsreader', serif; | ||
| } | ||
| /* modal font */ | ||
| .modal { | ||
| font-family: 'Newsreader', serif; | ||
| } | ||
| /* color modal */ | ||
| .modal__dialog { | ||
| background-color: hsla(0, 0%, 100%, .25); | ||
| } | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { getComments } from "./main.js"; | ||
|
|
||
| //modal display in the main content | ||
| function openPost() { | ||
| const modalOpen = new bootstrap.Modal(document.getElementById("modal")); | ||
| const commentsBtn = document.getElementById("commentsContentBtn"); | ||
| modalOpen.show(); | ||
| removeComments(); | ||
| commentsBtn.addEventListener("click", loadComments); | ||
| } | ||
|
|
||
| //show the content of body and title | ||
| function showTitleBody(event) { | ||
| const postId = event.target.getAttribute("data-post-id"); | ||
| const modalTitle = document.getElementById("modalTitle"); | ||
| const modalBody = document.getElementById("modalText"); | ||
| const postData = fetch("https://jsonplaceholder.typicode.com/posts/"); | ||
| try { | ||
| postData | ||
| .then((response) => { | ||
| return response.json(); | ||
| }) | ||
| .then((data) => { | ||
| let obj = data.find((item) => item.id == postId); // whe could make typeof!! | ||
| modalTitle.textContent = obj.title; | ||
| modalBody.textContent = obj.body; | ||
| }); | ||
| } catch (error) { | ||
| alert("Error Data"); | ||
| } | ||
| setCommentsId(postId); | ||
| } | ||
|
|
||
| // Show the email and user in post modal | ||
| function showUserEmail(event) { | ||
| const userId = event.target.getAttribute("data-user-id"); | ||
| const modalUser = document.getElementById("modalUsername"); | ||
| const modalEmail = document.getElementById("modalEmail"); | ||
| const userData = fetch("https://jsonplaceholder.typicode.com/users"); | ||
| try { | ||
| userData | ||
| .then((response) => { | ||
| return response.json(); | ||
| }) | ||
| .then((data) => { | ||
| let obj = data.find((item) => item.id == userId); // whe could make typeof!! | ||
| modalUser.textContent = obj.username; | ||
| modalEmail.textContent = obj.email; | ||
| }); | ||
| } catch (error) { | ||
| alert("Error Data"); | ||
| } | ||
| } | ||
| // Gives comments section a data attribute, to match with the id from the comments json data. | ||
| function setCommentsId(postId) { | ||
| const commentsContent = document.getElementById("commentsContentBody"); | ||
| commentsContent.setAttribute("data-post-id", `${postId}`); | ||
| } | ||
|
|
||
| // Removes comments before displaying more comments | ||
| function removeComments() { | ||
| const commentsBody = document.getElementById("commentsContentBody"); | ||
| while (commentsBody.firstElementChild) { | ||
| commentsBody.removeChild(commentsBody.lastElementChild); | ||
| } | ||
| } | ||
|
|
||
| // Loads comments into the bottom of the modal, adds comments formatting | ||
| async function loadComments() { | ||
| const commentsContent = document.getElementById("commentsContentBody"); | ||
| const commentsTitle = document.createElement("h4"); | ||
| commentsTitle.textContent = "Comments:"; | ||
| commentsTitle.classList.add("fw-bold"); | ||
|
|
||
| const modalPostId = parseInt(commentsContent.getAttribute("data-post-id")); // read the attribute for which comments | ||
| const commentsData = await getComments(); | ||
| const commentsSet = commentsData.filter((comment) => { | ||
| return comment.postId == modalPostId; | ||
| }); | ||
| commentsContent.append(commentsTitle); | ||
| commentsSet.map((comment) => { | ||
| const commentName = document.createElement("h5"); | ||
| const email = document.createElement("p"); | ||
| const body = document.createElement("p"); | ||
| commentName.textContent = comment.name; | ||
|
|
||
| email.textContent = comment.email; | ||
| body.textContent = comment.body; | ||
| body.classList.add("border-bottom", "pb-3"); | ||
|
|
||
| commentsContent.append(commentName, email, body); | ||
| }); | ||
| } | ||
|
|
||
| //EXPORT | ||
| export { openPost, showTitleBody, showUserEmail }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect Css, congrats!