From 458a8c849da82adf045a40919a4a9e3aa06e1c06 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Thu, 25 Jul 2024 18:52:28 +0530 Subject: initialized vite+react project --- src/App.css | 52 +++++++++++++++++++---------------- src/App.js | 28 ------------------- src/App.jsx | 35 ++++++++++++++++++++++++ src/App.test.js | 8 ------ src/assets/react.svg | 1 + src/components/Admin.js | 37 ------------------------- src/components/Login.js | 58 --------------------------------------- src/components/Upload.js | 54 ------------------------------------ src/firebase.js | 16 ----------- src/index.css | 71 ++++++++++++++++++++++++++++++++++++++++++------ src/index.js | 17 ------------ src/logo.svg | 1 - src/main.jsx | 10 +++++++ src/reportWebVitals.js | 13 --------- src/setupTests.js | 5 ---- 15 files changed, 137 insertions(+), 269 deletions(-) delete mode 100644 src/App.js create mode 100644 src/App.jsx delete mode 100644 src/App.test.js create mode 100644 src/assets/react.svg delete mode 100644 src/components/Admin.js delete mode 100644 src/components/Login.js delete mode 100644 src/components/Upload.js delete mode 100644 src/firebase.js delete mode 100644 src/index.js delete mode 100644 src/logo.svg create mode 100644 src/main.jsx 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 index 74b5e05..b9d355d 100644 --- a/src/App.css +++ b/src/App.css @@ -1,34 +1,24 @@ -.App { +#root { + max-width: 1280px; + margin: 0 auto; + padding: 2rem; text-align: center; } -.App-logo { - height: 40vmin; - pointer-events: none; +.logo { + height: 6em; + padding: 1.5em; + will-change: filter; + transition: filter 300ms; } - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +.logo:hover { + filter: drop-shadow(0 0 2em #646cffaa); } - -.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; +.logo.react:hover { + filter: drop-shadow(0 0 2em #61dafbaa); } -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { +@keyframes logo-spin { from { transform: rotate(0deg); } @@ -36,3 +26,17 @@ transform: rotate(360deg); } } + +@media (prefers-reduced-motion: no-preference) { + a:nth-of-type(2) .logo { + animation: logo-spin infinite 20s linear; + } +} + +.card { + padding: 2em; +} + +.read-the-docs { + color: #888; +} diff --git a/src/App.js b/src/App.js deleted file mode 100644 index 7f23517..0000000 --- a/src/App.js +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react'; -import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-dom'; -import './App.css'; -import Login from './components/Login'; -import Admin from './components/Admin'; - -function App() { - const isAuthenticated = () => { - return !!localStorage.getItem('jwtToken'); - }; - - return ( - -
- - } /> - : } - /> - } /> - -
-
- ); -} - -export default App; diff --git a/src/App.jsx b/src/App.jsx new file mode 100644 index 0000000..b8b8473 --- /dev/null +++ b/src/App.jsx @@ -0,0 +1,35 @@ +import { useState } from 'react' +import reactLogo from './assets/react.svg' +import viteLogo from '/vite.svg' +import './App.css' + +function App() { + const [count, setCount] = useState(0) + + return ( + <> +
+ + Vite logo + + + React logo + +
+

Vite + React

+
+ +

+ Edit src/App.jsx and save to test HMR +

+
+

+ Click on the Vite and React logos to learn more +

+ + ) +} + +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/assets/react.svg b/src/assets/react.svg new file mode 100644 index 0000000..6c87de9 --- /dev/null +++ b/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/Admin.js b/src/components/Admin.js deleted file mode 100644 index 15696e0..0000000 --- a/src/components/Admin.js +++ /dev/null @@ -1,37 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import axios from 'axios'; -import Upload from './Upload'; - -function Admin() { - const [message, setMessage] = useState(''); - - useEffect(() => { - const fetchData = async () => { - const token = localStorage.getItem('jwtToken'); - if (token) { - try { - const response = await axios.get('http://localhost:5000/admin', { - headers: { Authorization: `Bearer ${token}` }, - }); - setMessage(response.data.message); - } catch (error) { - console.error('Error fetching admin data', error); - } - } else { - setMessage('You are not authorized to view this page.'); - } - }; - - fetchData(); - }, []); - - return ( -
-

Admin Panel

-

{message}

- -
- ); -} - -export default Admin; diff --git a/src/components/Login.js b/src/components/Login.js deleted file mode 100644 index 717a3ae..0000000 --- a/src/components/Login.js +++ /dev/null @@ -1,58 +0,0 @@ -import React, { useState } from 'react'; -import axios from 'axios'; -import { useNavigate } from 'react-router-dom'; - -function Login() { - const [username, setUsername] = useState(''); - const [password, setPassword] = useState(''); - const [error, setError] = useState(''); - const navigate = useNavigate(); // Initialize useNavigate hook - - const handleSubmit = async (event) => { - event.preventDefault(); - try { - console.log('Attempting login with:', { username, password }); - const response = await axios.post('http://localhost:5000/login', { - username, - password, - }); - const { token } = response.data; - console.log('Login successful, token:', token); - localStorage.setItem('jwtToken', token); - navigate('/admin'); // Redirect to the admin page - } catch (error) { - setError('Invalid credentials'); - console.error('Error logging in', error); - } - }; - - return ( -
-

Login

- {error &&

{error}

} -
-
- - setUsername(e.target.value)} - required - /> -
-
- - setPassword(e.target.value)} - required - /> -
- -
-
- ); -} - -export default Login; diff --git a/src/components/Upload.js b/src/components/Upload.js deleted file mode 100644 index 6308fda..0000000 --- a/src/components/Upload.js +++ /dev/null @@ -1,54 +0,0 @@ -import React, { useState } from 'react'; -import { ref, uploadBytesResumable, getDownloadURL } from 'firebase/storage'; -import { storage } from '../firebase'; - -function Upload() { - const [file, setFile] = useState(null); - const [progress, setProgress] = useState(0); - const [url, setUrl] = useState(''); - - const handleFileChange = (e) => { - if (e.target.files[0]) { - setFile(e.target.files[0]); - } - }; - - const handleUpload = () => { - if (!file) { - alert('Please choose a file first!'); - return; - } - - const storageRef = ref(storage, `uploads/${file.name}`); - const uploadTask = uploadBytesResumable(storageRef, file); - - uploadTask.on( - 'state_changed', - (snapshot) => { - const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; - setProgress(progress); - }, - (error) => { - console.error('Upload failed', error); - }, - () => { - getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { - setUrl(downloadURL); - alert('File uploaded successfully!'); - }); - } - ); - }; - - return ( -
-

Upload Content

- - -

Upload Progress: {progress}%

- {url &&

File URL: {url}

} -
- ); -} - -export default Upload; diff --git a/src/firebase.js b/src/firebase.js deleted file mode 100644 index 5ec00da..0000000 --- a/src/firebase.js +++ /dev/null @@ -1,16 +0,0 @@ -import { initializeApp } from 'firebase/app'; -import { getStorage } from 'firebase/storage'; - -const firebaseConfig = { - apiKey: process.env.REACT_APP_FIREBASE_API_KEY, - authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN, - projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID, - storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET, - messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID, - appId: process.env.REACT_APP_FIREBASE_APP_ID, -}; - -const app = initializeApp(firebaseConfig); -const storage = getStorage(app); - -export { storage }; diff --git a/src/index.css b/src/index.css index ec2585e..6119ad9 100644 --- a/src/index.css +++ b/src/index.css @@ -1,13 +1,68 @@ -body { - margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } } diff --git a/src/index.js b/src/index.js deleted file mode 100644 index d563c0f..0000000 --- a/src/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import ReactDOM from 'react-dom/client'; -import './index.css'; -import App from './App'; -import reportWebVitals from './reportWebVitals'; - -const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - -); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); 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/main.jsx b/src/main.jsx new file mode 100644 index 0000000..54b39dd --- /dev/null +++ b/src/main.jsx @@ -0,0 +1,10 @@ +import React from 'react' +import ReactDOM from 'react-dom/client' +import App from './App.jsx' +import './index.css' + +ReactDOM.createRoot(document.getElementById('root')).render( + + + , +) 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