Skip to content
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

Lesson-8 #7

Open
wants to merge 19 commits into
base: lesson-8
Choose a base branch
from
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "net-ninja-pwa"
}
}
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
10 changes: 10 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
8 changes: 0 additions & 8 deletions js/ui.js

This file was deleted.

33 changes: 33 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>

<style media="screen">
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
@media (max-width: 600px) {
body, #message { margin-top: 0; background: white; box-shadow: none; }
body { border-top: 16px solid #ffa100; }
}
</style>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
62 changes: 21 additions & 41 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<script type="text/javascript" src="/js/materialize.min.js"></script>
<link rel="manifest" href="/manifest.json">
<!-- ios support -->
<link rel="apple-touch-icon" href="/icons/icon-96x96.png">
<link rel="apple-touch-icon" href="/img/icons/icon-96x96.png">
<meta name="apple-mobile-web-app-status-bar" content="#FFE1C4">
<meta name="theme-color" content="#FFE1C4">
</head>
<body class="grey lighten-4">

Expand All @@ -39,46 +40,7 @@

<!-- recipes -->
<div class="recipes container grey-text text-darken-1">
<div class="card-panel recipe white row">
<img src="/img/dish.png" alt="recipe thumb">
<div class="recipe-details">
<div class="recipe-title">Edame Noodles</div>
<div class="recipe-ingredients">Edame Beans, Noodels, Garlic oil</div>
</div>
<div class="recipe-delete">
<i class="material-icons">delete_outline</i>
</div>
</div>
<div class="card-panel recipe white row">
<img src="/img/dish.png" alt="recipe thumb">
<div class="recipe-details">
<div class="recipe-title">Edame Noodles</div>
<div class="recipe-ingredients">Edame Beans, Noodels, Garlic oil</div>
</div>
<div class="recipe-delete">
<i class="material-icons">delete_outline</i>
</div>
</div>
<div class="card-panel recipe white row">
<img src="/img/dish.png" alt="recipe thumb">
<div class="recipe-details">
<div class="recipe-title">Edame Noodles</div>
<div class="recipe-ingredients">Edame Beans, Noodels, Garlic oil</div>
</div>
<div class="recipe-delete">
<i class="material-icons">delete_outline</i>
</div>
</div>
<div class="card-panel recipe white row">
<img src="/img/dish.png" alt="recipe thumb">
<div class="recipe-details">
<div class="recipe-title">Edame Noodles</div>
<div class="recipe-ingredients">Edame Beans, Noodels, Garlic oil</div>
</div>
<div class="recipe-delete">
<i class="material-icons">delete_outline</i>
</div>
</div>

</div>

<div class="center">
Expand Down Expand Up @@ -106,6 +68,24 @@ <h6 >New Recipe</h6>
</form>
</div>


<script src="https://www.gstatic.com/firebasejs/5.11.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.11.0/firebase-firestore.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyDuDGcpHGU-Sx1Hla3wYwZvXbjeKpHqPjA",
authDomain: "net-ninja-pwa.firebaseapp.com",
databaseURL: "https://net-ninja-pwa.firebaseio.com",
projectId: "net-ninja-pwa",
storageBucket: "net-ninja-pwa.appspot.com",
messagingSenderId: "1008745109838"
};
firebase.initializeApp(config);
const db = firebase.firestore();
</script>
<script src="/js/app.js"></script>
<script src="/js/db.js"></script>
<script src="/js/ui.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if('serviceWorker' in navigator){
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('service worker registered'))
.catch(err => console.log('service worker not registered', err));
}
50 changes: 50 additions & 0 deletions public/js/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// enable offline data
db.enablePersistence()
.catch(function(err) {
if (err.code == 'failed-precondition') {
// probably multible tabs open at once
console.log('persistance failed');
} else if (err.code == 'unimplemented') {
// lack of browser support for the feature
console.log('persistance not available');
}
});

// real-time listener
db.collection('recipes').onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
if(change.type === 'added'){
renderRecipe(change.doc.data(), change.doc.id);
}
if(change.type === 'removed'){
removeRecipe(change.doc.id);
}
});
});

// add new recipe
const form = document.querySelector('form');
form.addEventListener('submit', evt => {
evt.preventDefault();

const recipe = {
name: form.title.value,
ingredients: form.ingredients.value
};

db.collection('recipes').add(recipe)
.catch(err => console.log(err));

form.title.value = '';
form.ingredients.value = '';
});

// remove a recipe
const recipeContainer = document.querySelector('.recipes');
recipeContainer.addEventListener('click', evt => {
if(evt.target.tagName === 'I'){
const id = evt.target.getAttribute('data-id');
//console.log(id);
db.collection('recipes').doc(id).delete();
}
})
File renamed without changes.
35 changes: 35 additions & 0 deletions public/js/ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const recipes = document.querySelector('.recipes');

document.addEventListener('DOMContentLoaded', function() {
// nav menu
const menus = document.querySelectorAll('.side-menu');
M.Sidenav.init(menus, {edge: 'right'});
// add recipe form
const forms = document.querySelectorAll('.side-form');
M.Sidenav.init(forms, {edge: 'left'});
});

// render recipe data
const renderRecipe = (data, id) => {

const html = `
<div class="card-panel recipe white row" data-id="${id}">
<img src="/img/dish.png" alt="recipe thumb">
<div class="recipe-details">
<div class="recipe-title">${data.name}</div>
<div class="recipe-ingredients">${data.ingredients}</div>
</div>
<div class="recipe-delete">
<i class="material-icons" data-id="${id}">delete_outline</i>
</div>
</div>
`;
recipes.innerHTML += html;

};

// remove recipe
const removeRecipe = (id) => {
const recipe = document.querySelector(`.recipe[data-id=${id}]`);
recipe.remove();
};
File renamed without changes.
4 changes: 3 additions & 1 deletion pages/about.html → public/pages/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<link type="text/css" href="/css/styles.css" rel="stylesheet">
<script type="text/javascript" src="/js/materialize.min.js"></script>
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" href="/icons/icon-96x96.png">
<link rel="apple-touch-icon" href="/img/icons/icon-96x96.png">
<meta name="apple-mobile-web-app-status-bar" content="#FFE1C4">
<meta name="theme-color" content="#FFE1C4">
</head>
<body class="grey lighten-4">

Expand Down Expand Up @@ -43,6 +44,7 @@ <h5 class="center">About Food Ninja</h5>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam voluptatibus omnis, ea doloremque exercitationem id necessitatibus. Voluptatem officiis cupiditate commodi totam, hic laborum est ducimus amet iure, non dignissimos illo.</p>
</div>

<script src="/js/app.js"></script>
<script src="/js/ui.js"></script>
</body>
</html>
4 changes: 3 additions & 1 deletion pages/contact.html → public/pages/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<link type="text/css" href="/css/styles.css" rel="stylesheet">
<script type="text/javascript" src="/js/materialize.min.js"></script>
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" href="/icons/icon-96x96.png">
<link rel="apple-touch-icon" href="/img/icons/icon-96x96.png">
<meta name="apple-mobile-web-app-status-bar" content="#FFE1C4">
<meta name="theme-color" content="#FFE1C4">
</head>
<body class="grey lighten-4">

Expand Down Expand Up @@ -48,6 +49,7 @@ <h6>Find us at:</h6>
</ul>
</div>

<script src="/js/app.js"></script>
<script src="/js/ui.js"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions public/pages/fallback.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Food Ninja</title>
<!-- materialize icons, css & js -->
<link type="text/css" href="/css/materialize.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" href="/css/styles.css" rel="stylesheet">
<script type="text/javascript" src="/js/materialize.min.js"></script>
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" href="/img/icons/icon-96x96.png">
<meta name="apple-mobile-web-app-status-bar" content="#FFE1C4">
<meta name="theme-color" content="#FFE1C4">
</head>
<body class="grey lighten-4">

<!-- top nav -->
<nav class="z-depth-0">
<div class="nav-wrapper container">
<a href="/">Food<span>Ninja</span></a>
<span class="right grey-text text-darken-1">
<i class="material-icons sidenav-trigger" data-target="side-menu">menu</i>
</span>
</div>
</nav>

<!-- side nav -->
<ul id="side-menu" class="sidenav side-menu">
<li><a class="subheader">FOODNINJA</a></li>
<li><a href="/" class="waves-effect">Home</a></li>
<li><a href="/pages/about.html" class="waves-effect">About</a></li>
<li><div class="divider"></div></li>
<li><a href="/pages/contact.html" class="waves-effect">
<i class="material-icons">mail_outline</i>Contact</a>
</li>
</ul>

<!-- content -->
<div class="container grey-text center">
<h5>OOPS!</h5>
<p>Currently you can't view this page without a connection.</p>
<a href="/" class="btn-small orange z-depth-0">Go to the Homepage</a>
</div>

<script src="/js/app.js"></script>
<script src="/js/ui.js"></script>
</body>
</html>
Loading