generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
8,241 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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,25 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jest": true | ||
}, | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"extends": ["airbnb-base"], | ||
"rules": { | ||
"no-shadow": "off", | ||
"no-param-reassign": "off", | ||
"eol-last": "off", | ||
"import/extensions": [ 1, { | ||
"js": "always", "json": "always" | ||
}] | ||
}, | ||
"ignorePatterns": [ | ||
"dist/", | ||
"build/" | ||
] | ||
} |
This file contains 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,62 @@ | ||
name: Linters | ||
|
||
on: pull_request | ||
|
||
env: | ||
FORCE_COLOR: 1 | ||
|
||
jobs: | ||
lighthouse: | ||
name: Lighthouse | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "12.x" | ||
- name: Setup Lighthouse | ||
run: npm install -g @lhci/cli@0.7.x | ||
- name: Lighthouse Report | ||
run: lhci autorun --upload.target=temporary-public-storage --collect.staticDistDir=. | ||
webhint: | ||
name: Webhint | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "12.x" | ||
- name: Setup Webhint | ||
run: | | ||
npm install --save-dev hint@6.x | ||
[ -f .hintrc ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/html-css-js/.hintrc | ||
- name: Webhint Report | ||
run: npx hint . | ||
stylelint: | ||
name: Stylelint | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "12.x" | ||
- name: Setup Stylelint | ||
run: | | ||
npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x | ||
[ -f .stylelintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/html-css-js/.stylelintrc.json | ||
- name: Stylelint Report | ||
run: npx stylelint "**/*.{css,scss}" | ||
eslint: | ||
name: ESLint | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "12.x" | ||
- name: Setup ESLint | ||
run: | | ||
npm install --save-dev eslint@7.x eslint-config-airbnb-base@14.x eslint-plugin-import@2.x babel-eslint@10.x | ||
[ -f .eslintrc.json ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/html-css-js/.eslintrc.json | ||
- name: ESLint Report | ||
run: npx eslint . |
This file contains 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 @@ | ||
node_modules/ |
This file contains 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,18 @@ | ||
{ | ||
"connector": { | ||
"name": "local", | ||
"options": { | ||
"pattern": ["**", "!.git/**", "!node_modules/**"] | ||
} | ||
}, | ||
"extends": ["development"], | ||
"formatters": ["stylish"], | ||
"hints": [ | ||
"button-type", | ||
"disown-opener", | ||
"html-checker", | ||
"meta-charset-utf-8", | ||
"meta-viewport", | ||
"no-inline-styles:error" | ||
] | ||
} |
This file contains 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,10 @@ | ||
{ | ||
"extends": ["stylelint-config-standard"], | ||
"plugins": ["stylelint-scss", "stylelint-csstree-validator"], | ||
"rules": { | ||
"at-rule-no-unknown": null, | ||
"scss/at-rule-no-unknown": true, | ||
"csstree/validator": true | ||
}, | ||
"ignoreFiles": ["build/**", "dist/**", "**/reset*.css", "**/bootstrap*.css"] | ||
} |
This file contains 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,53 +1,76 @@ | ||
const container = document.getElementById('booksList'); | ||
const title = document.getElementById('title'); | ||
const author = document.getElementById('author'); | ||
|
||
let books = []; | ||
|
||
function data() { | ||
books.forEach((book) => { | ||
container.innerHTML += ` | ||
<p>${book.author}</p> | ||
<p>${book.title}</p> | ||
<input type="button" value="Remove" id="${book.id}" onClick="removeItem('${book.id}')"/> | ||
<hr> | ||
`; | ||
}); | ||
const titleInput = document.querySelector('#book_title'); | ||
const authorInput = document.querySelector('#book_author'); | ||
const addBookBtn = document.querySelector('#add_book'); | ||
const addForm = document.querySelector('.addBookForm'); | ||
const bookList = document.querySelector('.list_present'); | ||
|
||
let booksData = []; | ||
|
||
function addBook() { | ||
const titleValue = titleInput.value; | ||
const authorValue = authorInput.value; | ||
|
||
if (titleValue !== '' && authorValue !== '') { | ||
if (booksData.length === 0) { | ||
bookList.innerHTML = ''; | ||
} | ||
|
||
const bookId = Math.random().toString(36).slice(2); | ||
booksData.unshift({ | ||
id: bookId, | ||
title: titleValue, | ||
author: authorValue, | ||
}); | ||
|
||
localStorage.setItem('bookData', JSON.stringify(booksData)); | ||
addForm.reset(); | ||
|
||
bookList.innerHTML = `<li> | ||
<h3> ${titleValue} </h3> | ||
<p>by - ${authorValue} </p> | ||
<input type="button" value="Remove" id="${bookId}" class="removeBook" onClick="removeBook('${bookId}')"/> | ||
</li>${bookList.innerHTML}`; | ||
} | ||
} | ||
|
||
function addItem() { | ||
const bookId = Math.random().toString(36).slice(2); | ||
books = JSON.parse(localStorage.getItem('books')); | ||
const inputForm = { | ||
Id: bookId, | ||
title: title.value, | ||
author: author.value, | ||
}; | ||
books.push(inputForm); | ||
localStorage.setItem('books', JSON.stringify(books)); | ||
data(); | ||
addBookBtn.addEventListener('click', addBook); | ||
|
||
function buildBookLists(book) { | ||
const bookData = `<li> | ||
<h3> ${book.title} </h3> | ||
<p>by - ${book.author} </p> | ||
<input type="button" value="Remove" id="${book.id}" onClick="removeBook('${book.id}')"/> | ||
</li>`; | ||
return bookData; | ||
} | ||
|
||
const formData = document.querySelectorAll('input'); | ||
for (let form of formData) { | ||
form.addEventListener('change', () => { | ||
addItem(); | ||
}); | ||
function readBookData() { | ||
let booksBuild = ''; | ||
if (booksData.length > 0) { | ||
booksData.forEach((books) => { | ||
booksBuild += buildBookLists(books); | ||
}); | ||
} else { | ||
booksBuild = '<li><h3>No books available yet!</h3></li>'; | ||
} | ||
|
||
bookList.innerHTML = booksBuild; | ||
} | ||
|
||
function removeItem(bookId) { | ||
books = JSON.parse(localStorage.getItem('books')); | ||
books = books.filter((e) => e.id !== bookId); | ||
console.log(books); | ||
localStorage.setItem('books', JSON.stringify(books)); | ||
// eslint-disable-next-line no-unused-vars | ||
function removeBook(bookId) { | ||
booksData = booksData.filter((books) => books.id !== bookId); | ||
localStorage.setItem('bookData', JSON.stringify(booksData)); | ||
readBookData(); | ||
} | ||
// Fetch data from localstorage | ||
|
||
const getFormData = JSON.parse(localStorage.getItem('books')); | ||
function getFormDataStorage() { | ||
if (getFormData !== null) { | ||
books = getFormData; | ||
data(); | ||
const localStorageData = JSON.parse(localStorage.getItem('bookData')); | ||
function getLocalStorageData() { | ||
if (localStorageData !== null) { | ||
booksData = localStorageData; | ||
readBookData(); | ||
} | ||
} | ||
|
||
window.onresize = getFormDataStorage(); | ||
window.onresize = getLocalStorageData(); |
This file contains 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
Oops, something went wrong.