From 1f853be5b9c07519cceeea9b7a5cbeee06756401 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 25 Jul 2024 11:07:20 +0530 Subject: new project --- src/App.css | 38 ------------------- src/App.js | 18 --------- src/App.test.js | 8 ---- src/components/Dashboard.js | 83 ------------------------------------------ src/components/Login.js | 33 ----------------- src/components/PrivateRoute.js | 17 --------- src/firebase/firebaseConfig.js | 17 --------- src/index.css | 13 ------- src/index.js | 5 --- src/logo.svg | 1 - src/reportWebVitals.js | 13 ------- src/setupTests.js | 5 --- 12 files changed, 251 deletions(-) delete mode 100644 src/App.css delete mode 100644 src/App.js delete mode 100644 src/App.test.js delete mode 100644 src/components/Dashboard.js delete mode 100644 src/components/Login.js delete mode 100644 src/components/PrivateRoute.js delete mode 100644 src/firebase/firebaseConfig.js delete mode 100644 src/index.css delete mode 100644 src/index.js delete mode 100644 src/logo.svg delete mode 100644 src/reportWebVitals.js delete mode 100644 src/setupTests.js (limited to 'src') diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 74b5e05..0000000 --- a/src/App.css +++ /dev/null @@ -1,38 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/src/App.js b/src/App.js deleted file mode 100644 index 437278a..0000000 --- a/src/App.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react'; -import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; -import Login from './components/Login'; -import Dashboard from './components/Dashboard'; -import PrivateRoute from './components/PrivateRoute'; - -const App = () => { - return ( - - - - - - - ); -}; - -export default App; diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 1f03afe..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/src/components/Dashboard.js b/src/components/Dashboard.js deleted file mode 100644 index cb14e26..0000000 --- a/src/components/Dashboard.js +++ /dev/null @@ -1,83 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { useHistory } from 'react-router-dom'; -import { auth, firestore } from '../firebase/firebaseConfig'; -import { getStorage, ref, uploadBytes, deleteObject } from "firebase/storage"; -import { collection, getDocs, addDoc, deleteDoc, doc } from "firebase/firestore"; -import { Bar } from 'react-chartjs-2'; - -const Dashboard = () => { - const history = useHistory(); - const [ads, setAds] = useState([]); - const [views, setViews] = useState([]); - const storage = getStorage(); - const adsCollectionRef = collection(firestore, "ads"); - - useEffect(() => { - const fetchAds = async () => { - const adsSnapshot = await getDocs(adsCollectionRef); - setAds(adsSnapshot.docs.map(doc => ({ ...doc.data(), id: doc.id }))); - }; - - const fetchViews = async () => { - // Assume we have a 'views' collection to track ad views - const viewsSnapshot = await getDocs(collection(firestore, "views")); - setViews(viewsSnapshot.docs.map(doc => doc.data())); - }; - - fetchAds(); - fetchViews(); - }, []); - - const handleLogout = () => { - auth.signOut(); - localStorage.removeItem('token'); - history.push('/login'); - }; - - const handleUpload = async (event) => { - const file = event.target.files[0]; - const storageRef = ref(storage, `ads/${file.name}`); - await uploadBytes(storageRef, file); - await addDoc(adsCollectionRef, { name: file.name, url: `ads/${file.name}` }); - setAds([...ads, { name: file.name, url: `ads/${file.name}` }]); - }; - - const handleDelete = async (id, url) => { - const storageRef = ref(storage, url); - await deleteObject(storageRef); - await deleteDoc(doc(firestore, "ads", id)); - setAds(ads.filter(ad => ad.id !== id)); - }; - - const viewData = { - labels: ads.map(ad => ad.name), - datasets: [ - { - label: 'Ad Views', - data: views.map(view => view.count), - backgroundColor: 'rgba(75, 192, 192, 0.6)', - }, - ], - }; - - return ( -
-

Dashboard

- - -
- {ads.map(ad => ( -
-

{ad.name}

- -
- ))} -
-
- -
-
- ); -}; - -export default Dashboard; diff --git a/src/components/Login.js b/src/components/Login.js deleted file mode 100644 index 64539c6..0000000 --- a/src/components/Login.js +++ /dev/null @@ -1,33 +0,0 @@ -import React, { useState } from 'react'; -import axios from 'axios'; -import { useHistory } from 'react-router-dom'; - -const Login = () => { - const [email, setEmail] = useState(''); - const [password, setPassword] = useState(''); - const history = useHistory(); - - const handleSubmit = async (e) => { - e.preventDefault(); - try { - const response = await axios.post('/api/auth/login', { email, password }); - localStorage.setItem('token', response.data.token); - history.push('/dashboard'); - } catch (error) { - console.error('Error logging in:', error); - } - }; - - return ( -
-

Login

-
- setEmail(e.target.value)} required /> - setPassword(e.target.value)} required /> - -
-
- ); -}; - -export default Login; diff --git a/src/components/PrivateRoute.js b/src/components/PrivateRoute.js deleted file mode 100644 index 1296935..0000000 --- a/src/components/PrivateRoute.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import { Route, Redirect } from 'react-router-dom'; - -const PrivateRoute = ({ component: Component, ...rest }) => { - const isAuthenticated = !!localStorage.getItem('token'); - - return ( - - isAuthenticated ? : - } - /> - ); -}; - -export default PrivateRoute; diff --git a/src/firebase/firebaseConfig.js b/src/firebase/firebaseConfig.js deleted file mode 100644 index 87546fd..0000000 --- a/src/firebase/firebaseConfig.js +++ /dev/null @@ -1,17 +0,0 @@ -import firebase from 'firebase/app'; -import 'firebase/auth'; -import 'firebase/firestore'; - -const firebaseConfig = { - apiKey: "YOUR_API_KEY", - authDomain: "YOUR_AUTH_DOMAIN", - projectId: "YOUR_PROJECT_ID", - storageBucket: "YOUR_STORAGE_BUCKET", - messagingSenderId: "YOUR_MESSAGING_SENDER_ID", - appId: "YOUR_APP_ID" -}; - -firebase.initializeApp(firebaseConfig); - -export const auth = firebase.auth(); -export const firestore = firebase.firestore(); diff --git a/src/index.css b/src/index.css deleted file mode 100644 index ec2585e..0000000 --- a/src/index.css +++ /dev/null @@ -1,13 +0,0 @@ -body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; -} diff --git a/src/index.js b/src/index.js deleted file mode 100644 index b597a44..0000000 --- a/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import App from './App'; - -ReactDOM.render(, document.getElementById('root')); diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 9dfc1c0..0000000 --- a/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/reportWebVitals.js b/src/reportWebVitals.js deleted file mode 100644 index 5253d3a..0000000 --- a/src/reportWebVitals.js +++ /dev/null @@ -1,13 +0,0 @@ -const reportWebVitals = onPerfEntry => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 8f2609b..0000000 --- a/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom'; -- cgit v1.2.3-59-g8ed1b