22
loading...
This website collects cookies to deliver better user experience
// App.js
import React from "react";
const firebaseConfig = {
apiKey: "--------------------",
authDomain: "--------------------",
databaseURL: "--------------------",
projectId: "--------------------",
storageBucket: "--------------------",
messagingSenderId: "--------------------",
appId: "--------------------",
measurementId: "--------------------",
};
const App = () => {
return <div>Hello there</div>;
};
export default App;
{
"name":"react-firebase-notebook",
"version":"0.1.0",
"private":true,
"dependencies":{
"@testing-library/jest-dom":"^5.11.4",
"@testing-library/react":"^11.1.0",
"@testing-library/user-event":"^12.1.10",
"firebase":"^9.2.0",
"react":"^17.0.2",
"react-dom":"^17.0.2",
"react-scripts":"4.0.3",
"web-vitals":"^1.0.1"
},
"scripts":{
"start":"react-scripts start",
"build":"react-scripts build",
"test":"react-scripts test",
"eject":"react-scripts eject"
},
"eslintConfig":{
"extends":[
"react-app",
"react-app/jest"
]
},
"browserslist":{
"production":[
">0.2%",
"not dead",
"not op_mini all"
],
"development":[
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
import firebase from "firebase/app"
//App.js
import React from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/database";
const firebaseConfig = {
apiKey: "--------------------",
authDomain: "--------------------",
databaseURL: "--------------------",
projectId: "--------------------",
storageBucket: "--------------------",
messagingSenderId: "--------------------",
appId: "--------------------",
measurementId: "--------------------",
};
firebase.initializeApp(firebaseConfig);
const App = () => {
return <div>Hello there</div>;
};
export default App;
// components/Navbar/index.js
import Navbar from "./Navbar.js"
export default Navbar;
// components/Navbar/Navbar.js
import React from "react";
import "./Navbar.css";
const Navbar = () => {
return (
<>
<header className="navbar">
<h2 className="heading">📓 React firebase Notebook </h2>
</header>
</>
);
};
export default Navbar;
/*components/Navbar/Navbar.css */
.navbar {
display: flex;
justify-content: center;
align-items: center;
width: 99vw;
height: 70px;
background: rgba( 255, 255, 255, 0.15 );
box-shadow: 0 8px 32px 0 rgba( 31, 38, 135, 0.37 );
backdrop-filter: blur( 7.5px );
-webkit-backdrop-filter: blur( 7.5px );
border-radius: 20px;
border: 1px solid rgba( 255, 255, 255, 0.18 );
}
.navbar .heading {
color: #fd5252;
font-size: 20px;
font-weight: 700;
font-family: 'Poppins', sans-serif;
}
// App.js
import React from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/database";
import Navbar from "./components/Navbar";
const firebaseConfig = {
apiKey: "--------------------",
authDomain: "--------------------",
databaseURL: "--------------------",
projectId: "--------------------",
storageBucket: "--------------------",
messagingSenderId: "--------------------",
appId: "--------------------",
measurementId: "--------------------",
};
firebase.initializeApp(firebaseConfig);
const App = () => {
return (
<div>
<Navbar />
</div>
);
};
export default App;
// components/NoteAdd/index.js
import NoteAdd from "./NoteAdd";
export default NoteAdd
// components/NoteAdd/NoteAdd.js
import React from "react";
import "./NoteAdd.css";
const NoteAdd = () => {
return (
<>
<div className="noteadd">
<h1>Add a New Note</h1>
<div className="form-group">
<input
type="text"
className="noteadd-header"
name="noteadd-header"
placeholder="Note Title"
/>
</div>
<div className="form-group">
<textarea
name="noteadd-description"
className="noteadd-description"
placeholder="Note Description"
></textarea>
</div>
<div className="noteadd-button">
<button>Add a Note</button>
</div>
</div>
</>
);
};
export default NoteAdd;
/* components/NoteAdd/NoteAdd.css */
.noteadd {
display: block;
width: 100%;
max-width: 500px;
margin: 10px auto;
}
.noteadd h1 {
display: flex;
background: rgba(255, 255, 255, 0.15);
justify-content: center;
align-items: center;
color: #8661d1;
font-family: "poppins";
margin-bottom: 10px;
}
input {
border-style: none;
background: transparent;
outline: none;
}
textarea {
border-style: none;
background: transparent;
outline: none;
}
.noteadd-header {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
width: 100%;
max-width: 400px;
height: 10px;
margin: 0 auto;
border-radius: 5px;
padding: 1rem;
background: white;
}
.noteadd-header input {
flex-grow: 1;
color: white;
font-size: 1.8rem;
line-height: 2.4rem;
vertical-align: middle;
}
.noteadd-description {
position: relative;
display: flex;
flex-direction: row;
width: 100%;
max-width: 400px;
height: 40px;
margin: 0 auto;
border-radius: 5px;
padding: 1rem;
background: white;
}
.noteadd-header textarea {
flex-grow: 1;
color: white;
font-size: 1.8rem;
line-height: 2.4rem;
vertical-align: middle;
}
.noteadd .form-group {
display: flex;
flex-direction: column;
margin-bottom: 15px;
justify-content: center;
}
.noteadd-button {
display: flex;
justify-content: center;
align-items: center;
}
button {
padding: 10px 15px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #8661d1;
border: none;
border-radius: 15px;
box-shadow: 0 5px rgb(109, 57, 129);
}
button:hover {
background-color: #906ed3;
}
button:active {
background-color: #fd5252e5;
box-shadow: 0 5px rgb(212, 93, 93);
transform: translateY(4px);
}
// App.js
import React from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/database";
import Navbar from "./components/Navbar";
import NoteAdd from "./components/NoteAdd";
import "./App.css";
const firebaseConfig = {
apiKey: "--------------------",
authDomain: "--------------------",
databaseURL: "--------------------",
projectId: "--------------------",
storageBucket: "--------------------",
messagingSenderId: "--------------------",
appId: "--------------------",
measurementId: "--------------------",
};
firebase.initializeApp(firebaseConfig);
const App = () => {
return (
<div className="app">
<Navbar />
<div className="note-section">
<NoteAdd />
</div>
</div>
);
};
export default App;
const [state, setState] = useState(initialState);
// components/NoteAdd/NoteAdd.js
import React, { useState } from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/database";
import "./NoteAdd.css";
const NoteAdd = () => {
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const handleTitleChange = (event) => {
setTitle(event.target.value);
};
const handleDescriptionChange = (event) => {
setDescription(event.target.value);
};
const addNote = () => {
if (title !== "" && description !== "") {
firebase.database().ref("notebook").push({
title: title,
description: description,
});
}
};
return (
<>
<div className="noteadd">
<h1>Add a New Note</h1>
<div className="form-group">
<input
type="text"
className="noteadd-header"
name="noteadd-header"
placeholder="Note Title"
value={title}
onChange={(val) => handleTitleChange(val)}
/>
</div>
<div className="form-group">
<textarea
name="noteadd-description"
className="noteadd-description"
placeholder="Note Description"
value={description}
onChange={(val) => handleDescriptionChange(val)}
></textarea>
</div>
<div className="noteadd-button">
<button onClick={() => addNote()}>Add a Note</button>
</div>
</div>
</>
);
};
export default NoteAdd;
// components/Notebook/index.js
import Notebook from "./Notebook";
export default Notebook;
// components/Notebook/NoteAdd.js
import React from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/database";
import "./Notebook.css";
const Notebook = (props) => {
const deleteNotebook = (id) => {
firebase.database().ref("notebook").child(id).remove();
};
return (
<>
<section className="notebook-container">
<div className="notebook">
{props.notebook.map((note, index) => (
<React.Fragment key={index}>
<div className="notebookInfo" key={note.id}>
<div className="notebookInfo-title">
<h3>{note.title}</h3>
<div
className="remove"
onClick={() => deleteNotebook(note.id)}
>
🗑️
</div>
</div>
<div className="notebookInfo-description">
<p>{note.description}</p>
</div>
</div>
</React.Fragment>
))}
</div>
</section>
</>
);
};
export default Notebook;
.notebook {
display: grid;
grid-template-columns: 1fr;
grid-gap: 20px;
padding: 20px;
}
.notebook .notebookInfo {
background: rgba(209, 97, 175, 0.25);
box-shadow: 0 8px 32px 0 rgba(135, 31, 100, 0.37);
backdrop-filter: blur(2.5px);
border-radius: 20px;
border: 1px solid rgba(255, 255, 255, 0.18);
display: flex;
flex-direction: column;
justify-content: center;
padding: 2rem;
min-height: 1rem;
width: 20rem !important;
margin: 0rem auto;
}
.notebook .notebookInfo .notebookInfo-title {
background: rgba(212, 134, 98, 0.25);
box-shadow: 0 8px 32px 0 rgba(135, 31, 130, 0.37);
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.18);
backdrop-filter: blur(2.5px);
display: flex;
justify-content: space-between;
align-items: center;
}
.notebookInfo-title h3 {
padding-left: 1rem;
}
.notebookInfo-title .remove {
padding-right: 1rem;
}
.notebook .notebookInfo .notebookInfo-title {
color: #f3f3f3;
margin: 0;
padding: 0;
font-family: "Poppins";
}
.notebook .notebookInfo .notebookInfo-title .remove {
color: #ff0000;
font-size: 24px;
font-weight: 700;
}
.notebook .notebookInfo .notebookInfo-description {
padding: 10px;
}
.remove {
cursor: pointer;
}
@media screen and (min-width: 768px) {
.notebook {
grid-template-columns: repeat(3, 1fr);
}
}
const updateNotes = () => {
firebase
.database()
.ref("notebook")
.on("child_added", (snapshot) => {
let note = {
id: snapshot.key,
title: snapshot.val().title,
description: snapshot.val().description,
};
let notebook = noteBookData;
notebook.push(note);
setNoteBookData([...noteBookData]);
});
firebase
.database()
.ref("notebook")
.on("child_removed", (snapshot) => {
let notebook = noteBookData;
notebook = noteBookData.filter((note) => note.id !== snapshot.key);
setNoteBookData(notebook);
});
};
useEffect(() => {
updateNotes();
}, []);
// components/Notebook/Notebook.js
import React, { useState, useEffect } from "react";
import firebase from "firebase/compat/app";
import "firebase/compat/database";
import Navbar from "./components/Navbar";
import NoteAdd from "./components/NoteAdd";
import Notebook from "./components/Notebook";
import "./App.css";
const firebaseConfig = {
apiKey: "--------------------",
authDomain: "--------------------",
databaseURL: "--------------------",
projectId: "--------------------",
storageBucket: "--------------------",
messagingSenderId: "--------------------",
appId: "--------------------",
measurementId: "--------------------"
};
firebase.initializeApp(firebaseConfig);
const App = () => {
const [noteBookData, setNoteBookData] = useState([]);
const updateNotes = () => {
firebase
.database()
.ref("notebook")
.on("child_added", (snapshot) => {
let note = {
id: snapshot.key,
title: snapshot.val().title,
description: snapshot.val().description,
};
let notebook = noteBookData;
notebook.push(note);
setNoteBookData([...noteBookData]);
});
firebase
.database()
.ref("notebook")
.on("child_removed", (snapshot) => {
let notebook = noteBookData;
notebook = noteBookData.filter((note) => note.id !== snapshot.key);
setNoteBookData(notebook);
});
};
useEffect(() => {
updateNotes();
}, []);
return (
<div className="app">
<Navbar />
<div className="note-section">
<NoteAdd />
<Notebook notebook={noteBookData} />
</div>
</div>
);
};
export default App;
* {
margin: 0;
padding: 0;
}
.app {
background-image: linear-gradient( to right, rgb(242, 112, 156), rgb(255, 148, 114) );
min-height: 100vh;
width: 100vw;
align-items: center;
}
.note-section {
padding: 15px;
}