├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── firebase-config.js ├── index.js ├── pages │ ├── CreatePost.js │ ├── Home.js │ └── Login.js └── reportWebVitals.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blog-tutorial-fs", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "firebase": "^9.6.0", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-router-dom": "^6.0.2", 13 | "react-scripts": "4.0.3", 14 | "web-vitals": "^1.0.1" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/machadop1407/react-firebase-blog-website/ddd2abfb588ac85a40fb03b2d027023a65188a24/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/machadop1407/react-firebase-blog-website/ddd2abfb588ac85a40fb03b2d027023a65188a24/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/machadop1407/react-firebase-blog-website/ddd2abfb588ac85a40fb03b2d027023a65188a24/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | body { 5 | padding: 0%; 6 | margin: 0%; 7 | font-family: Arial, Helvetica, sans-serif; 8 | } 9 | 10 | nav { 11 | margin: 0; 12 | width: 100%; 13 | height: 80px; 14 | background-color: black; 15 | display: flex; 16 | justify-content: center; 17 | align-items: center; 18 | color: white; 19 | text-decoration: none; 20 | } 21 | 22 | a { 23 | color: white; 24 | text-decoration: none; 25 | margin: 10px; 26 | font-size: 25px; 27 | } 28 | 29 | .createPostPage { 30 | width: 100%; 31 | height: calc(100vh - 80px); 32 | display: grid; 33 | place-items: center; 34 | } 35 | 36 | .cpContainer { 37 | width: 500px; 38 | height: auto; 39 | padding: 20px; 40 | background-color: black; 41 | border-radius: 12px; 42 | color: white; 43 | display: flex; 44 | flex-direction: column; 45 | } 46 | 47 | .cpContainer h1 { 48 | text-align: center; 49 | } 50 | 51 | .cpContainer label { 52 | font-size: 25px; 53 | } 54 | .cpContainer .inputGp { 55 | margin-top: 30px; 56 | display: flex; 57 | flex-direction: column; 58 | } 59 | 60 | .inputGp input, 61 | .inputGp textarea { 62 | font-size: 18px; 63 | border: none; 64 | border-radius: 2px; 65 | padding: 5px; 66 | } 67 | 68 | .inputGp input { 69 | height: 40px; 70 | } 71 | .inputGp textarea { 72 | height: 150px; 73 | } 74 | 75 | .cpContainer button { 76 | margin-top: 20px; 77 | height: 40px; 78 | border: none; 79 | border-radius: 5px; 80 | cursor: pointer; 81 | font-size: 18px; 82 | } 83 | input, 84 | textarea { 85 | margin-top: 5px; 86 | } 87 | 88 | .loginPage { 89 | width: 100vw; 90 | height: calc(100vh - 80px); 91 | display: flex; 92 | flex-direction: column; 93 | justify-content: center; 94 | align-items: center; 95 | } 96 | 97 | .loginPage p { 98 | font-size: 30px; 99 | } 100 | 101 | /* GOOGLE BUTTOn */ 102 | .login-with-google-btn { 103 | cursor: pointer; 104 | transition: background-color 0.3s, box-shadow 0.3s; 105 | padding: 5px 16px 12px 42px; 106 | border: none; 107 | border-radius: 3px; 108 | box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.25); 109 | color: #757575; 110 | font-size: 25px; 111 | font-weight: 500; 112 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, 113 | Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; 114 | background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNMTcuNiA5LjJsLS4xLTEuOEg5djMuNGg0LjhDMTMuNiAxMiAxMyAxMyAxMiAxMy42djIuMmgzYTguOCA4LjggMCAwIDAgMi42LTYuNnoiIGZpbGw9IiM0Mjg1RjQiIGZpbGwtcnVsZT0ibm9uemVybyIvPjxwYXRoIGQ9Ik05IDE4YzIuNCAwIDQuNS0uOCA2LTIuMmwtMy0yLjJhNS40IDUuNCAwIDAgMS04LTIuOUgxVjEzYTkgOSAwIDAgMCA4IDV6IiBmaWxsPSIjMzRBODUzIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48cGF0aCBkPSJNNCAxMC43YTUuNCA1LjQgMCAwIDEgMC0zLjRWNUgxYTkgOSAwIDAgMCAwIDhsMy0yLjN6IiBmaWxsPSIjRkJCQzA1IiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48cGF0aCBkPSJNOSAzLjZjMS4zIDAgMi41LjQgMy40IDEuM0wxNSAyLjNBOSA5IDAgMCAwIDEgNWwzIDIuNGE1LjQgNS40IDAgMCAxIDUtMy43eiIgZmlsbD0iI0VBNDMzNSIgZmlsbC1ydWxlPSJub256ZXJvIi8+PHBhdGggZD0iTTAgMGgxOHYxOEgweiIvPjwvZz48L3N2Zz4=); 115 | background-color: white; 116 | background-repeat: no-repeat; 117 | background-position: 12px 11px; 118 | } 119 | .login-with-google-btn:hover { 120 | box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.25); 121 | } 122 | .login-with-google-btn:active { 123 | background-color: #eeeeee; 124 | } 125 | .login-with-google-btn:focus { 126 | outline: none; 127 | box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.25), 128 | 0 0 0 3px #c8dafc; 129 | } 130 | .login-with-google-btn:disabled { 131 | filter: grayscale(100%); 132 | background-color: #ebebeb; 133 | box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.25); 134 | cursor: not-allowed; 135 | } 136 | 137 | .homePage { 138 | width: 100%; 139 | min-height: calc(100vh - 80px); 140 | height: auto; 141 | display: flex; 142 | flex-direction: column; 143 | align-items: center; 144 | padding-top: 20px; 145 | } 146 | 147 | .homePage .post { 148 | width: 600px; 149 | height: auto; 150 | max-height: 600px; 151 | background-color: rgb(250, 250, 250); 152 | box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px; 153 | margin: 20px; 154 | padding: 20px; 155 | border-radius: 15px; 156 | } 157 | 158 | .post .postHeader { 159 | display: flex; 160 | justify-content: center; 161 | width: 100%; 162 | } 163 | 164 | .postHeader .title { 165 | flex: 50%; 166 | } 167 | .postHeader .deletePost { 168 | flex: 50%; 169 | display: flex; 170 | flex-direction: column; 171 | align-items: flex-end; 172 | } 173 | 174 | .deletePost button { 175 | border: none; 176 | 177 | background: none; 178 | font-size: 30px; 179 | cursor: pointer; 180 | } 181 | 182 | .post .postTextContainer { 183 | word-wrap: break-word; 184 | height: auto; 185 | max-height: 400px; 186 | width: 100%; 187 | overflow: hidden; 188 | overflow-y: auto; 189 | } 190 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom"; 3 | import Home from "./pages/Home"; 4 | import CreatePost from "./pages/CreatePost"; 5 | import Login from "./pages/Login"; 6 | import { useState } from "react"; 7 | import { signOut } from "firebase/auth"; 8 | import { auth } from "./firebase-config"; 9 | 10 | function App() { 11 | const [isAuth, setIsAuth] = useState(localStorage.getItem("isAuth")); 12 | 13 | const signUserOut = () => { 14 | signOut(auth).then(() => { 15 | localStorage.clear(); 16 | setIsAuth(false); 17 | window.location.pathname = "/login"; 18 | }); 19 | }; 20 | 21 | return ( 22 | 23 | 35 | 36 | } /> 37 | } /> 38 | } /> 39 | 40 | 41 | ); 42 | } 43 | 44 | export default App; 45 | -------------------------------------------------------------------------------- /src/firebase-config.js: -------------------------------------------------------------------------------- 1 | import { initializeApp } from "firebase/app"; 2 | import { getFirestore } from "firebase/firestore"; 3 | import { getAuth, GoogleAuthProvider } from "firebase/auth"; 4 | // TODO: Add SDKs for Firebase products that you want to use 5 | // https://firebase.google.com/docs/web/setup#available-libraries 6 | 7 | // Your web app's Firebase configuration 8 | const firebaseConfig = { 9 | apiKey: "AIzaSyDc7PJ9309GQRO0v2-mCUhBIWpOAnNyec8", 10 | authDomain: "blogproject-92aa7.firebaseapp.com", 11 | projectId: "blogproject-92aa7", 12 | storageBucket: "blogproject-92aa7.appspot.com", 13 | messagingSenderId: "135318509256", 14 | appId: "1:135318509256:web:034fab8084a0ad39e3b7fd", 15 | }; 16 | 17 | // Initialize Firebase 18 | const app = initializeApp(firebaseConfig); 19 | 20 | export const db = getFirestore(app); 21 | export const auth = getAuth(app); 22 | export const provider = new GoogleAuthProvider(); 23 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./App"; 4 | import reportWebVitals from "./reportWebVitals"; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById("root") 11 | ); 12 | 13 | // If you want to start measuring performance in your app, pass a function 14 | // to log results (for example: reportWebVitals(console.log)) 15 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 16 | reportWebVitals(); 17 | -------------------------------------------------------------------------------- /src/pages/CreatePost.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { addDoc, collection } from "firebase/firestore"; 3 | import { db, auth } from "../firebase-config"; 4 | import { useNavigate } from "react-router-dom"; 5 | 6 | function CreatePost({ isAuth }) { 7 | const [title, setTitle] = useState(""); 8 | const [postText, setPostText] = useState(""); 9 | 10 | const postsCollectionRef = collection(db, "posts"); 11 | let navigate = useNavigate(); 12 | 13 | const createPost = async () => { 14 | await addDoc(postsCollectionRef, { 15 | title, 16 | postText, 17 | author: { name: auth.currentUser.displayName, id: auth.currentUser.uid }, 18 | }); 19 | navigate("/"); 20 | }; 21 | 22 | useEffect(() => { 23 | if (!isAuth) { 24 | navigate("/login"); 25 | } 26 | }, []); 27 | 28 | return ( 29 |
30 |
31 |

Create A Post

32 |
33 | 34 | { 37 | setTitle(event.target.value); 38 | }} 39 | /> 40 |
41 |
42 | 43 |