Skip to content

Commit

Permalink
firebase deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
jgudo committed Sep 4, 2019
1 parent e7f7555 commit c66a9a8
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 133 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "salinaka-ecommerce"
}
}
63 changes: 63 additions & 0 deletions database.rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"rules": {
".read": false,
".write": "auth !== null",
"users": {
"$user_id": {
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid",
"fullname": {
".validate": "newData.isString()"
},
"email": {
".validate": "newData.isString()"
},
"address": {
".validate": "newData.isString()"
},
"mobile": {
".validate": "newData.isNumber()"
},
"avatar": {
".validate": "newData.isString()"
},
"banner": {
".validate": "newData.isString()"
},
"dateJoined": {
".validate": "newData.isString()"
}
}
},
"products": {
".read": true,
".write": false,
"$product_id": {
"name": {
".validate": "newData.isString()"
},
"description": {
".validate": "newData.isString()"
},
"price": {
".validate": "newData.isNumber()"
},
"brand": {
".validate": "newData.isString()"
},
"image": {
".validate": "newData.isString()"
},
"maxQuantity": {
".validate": "newData.isNumber()"
},
"quantity": {
".validate": "newData.isNumber()"
},
"dateAdded": {
".validate": "newData.isNumber()"
}
}
}
}
}
22 changes: 22 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
65 changes: 65 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to Firebase Hosting</title>

<!-- update the version number as needed -->
<script defer src="/__/firebase/6.5.0/firebase-app.js"></script>
<!-- include only the Firebase features as you need -->
<script defer src="/__/firebase/6.5.0/firebase-auth.js"></script>
<script defer src="/__/firebase/6.5.0/firebase-database.js"></script>
<script defer src="/__/firebase/6.5.0/firebase-messaging.js"></script>
<script defer src="/__/firebase/6.5.0/firebase-storage.js"></script>
<!-- initialize the SDK after all desired features are loaded -->
<script defer src="/__/firebase/init.js"></script>

<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; border-radius: 3px; }
#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>Welcome</h2>
<h1>Firebase Hosting Setup Complete</h1>
<p>You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!</p>
<a target="_blank" href="https://firebase.google.com/docs/hosting/">Open Hosting Documentation</a>
</div>
<p id="load">Firebase SDK Loading&hellip;</p>

<script>
document.addEventListener('DOMContentLoaded', function() {
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
// // The Firebase SDK is initialized and available here!
//
// firebase.auth().onAuthStateChanged(user => { });
// firebase.database().ref('/path/to/ref').on('value', snapshot => { });
// firebase.messaging().requestPermission().then(() => { });
// firebase.storage().ref('/path/to/ref').getDownloadURL().then(() => { });
//
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

try {
let app = firebase.app();
let features = ['auth', 'database', 'messaging', 'storage'].filter(feature => typeof app[feature] === 'function');
document.getElementById('load').innerHTML = `Firebase SDK loaded with ${features.join(', ')}`;
} catch (e) {
console.error(e);
document.getElementById('load').innerHTML = 'Error loading the Firebase SDK, check the console.';
}
});
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions src/client/actions/appActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LOADING } from '../constants/constants';

export const isLoading = (bool = true) => ({
type: LOADING,
payload: bool
});
6 changes: 5 additions & 1 deletion src/client/components/product/ProductList.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useEffect } from 'react';
import { removeProduct, getProducts } from '../../actions/productActions';
import { addToBasket, removeFromBasket } from '../../actions/basketActions';
import { isLoading as dispatchIsLoading } from '../../actions/appActions';
import { displayActionMessage } from '../../helpers/utils';


const ProductList = ({
products,
isLoading,
Expand All @@ -17,6 +17,10 @@ const ProductList = ({

useEffect(() => {
products.length === 0 && onGetProducts();

return () => {
isLoading && dispatch(dispatchIsLoading(false));
};
}, []);

useEffect(() => {
Expand Down
12 changes: 6 additions & 6 deletions src/client/components/ui/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const Footer = ({ path }) => {
<h4>SALINAKA &nbsp;<span>{new Date().getFullYear()}</span></h4>
</div>
<div className="footer-col-2">
<span>Created by <strong><a href="https://github.com/jgudo">Julius Guevarra</a></strong></span>
<strong><span>Created by <a href="https://github.com/jgudo">Julius Guevarra</a></span></strong>
</div>
<div className="footer-col-3">
<span>
Fork this project &nbsp;
<strong>
<strong>
<span>
Fork this project &nbsp;
<a href="https://github.com/jgudo/ecommerce-react">here</a>
</strong>
</span>
</span>
</strong>
</div>
</footer>
);
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/ui/Modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Modal = (props) => {
position: 'fixed',
paddingTop: '50px',
paddingBottom: '50px',
transition: 'all .5s ease',
zIndex: 9999,
marginRight: '-50%',
transform: 'translate(-50%, -50%)'
Expand All @@ -24,6 +25,7 @@ const Modal = (props) => {
isOpen={props.isOpen}
onAfterOpen={props.afterOpenModal}
onRequestClose={props.closeModal}
shouldCloseOnOverlayClick={true}
style={customStyles}
contentLabel="Product Modal"
>
Expand Down
19 changes: 9 additions & 10 deletions src/client/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@ export const displayActionMessage = (msg, status = 'info') => {
span.textContent = msg;
div.appendChild(span);

try {
if (document.querySelector('.toast')) {
document.body.removeChild(document.querySelector('.toast'));
document.body.appendChild(div);
} else {
document.body.appendChild(div);
}
} catch (e) {
console.log(e);

if (document.querySelector('.toast')) {
document.body.removeChild(document.querySelector('.toast'));
document.body.appendChild(div);
} else {
document.body.appendChild(div);
}

setTimeout(() => {
document.body.removeChild(div);
try {
document.body.removeChild(div);
} catch (e) {}
}, 3000);
};
Loading

0 comments on commit c66a9a8

Please sign in to comment.