aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/Admin.js37
-rw-r--r--src/components/Login.js58
-rw-r--r--src/components/Upload.js54
3 files changed, 0 insertions, 149 deletions
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 (
- <div className="Admin">
- <h2>Admin Panel</h2>
- <p>{message}</p>
- <Upload />
- </div>
- );
-}
-
-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 (
- <div className="Login">
- <h2>Login</h2>
- {error && <p style={{ color: 'red' }}>{error}</p>}
- <form onSubmit={handleSubmit}>
- <div>
- <label>Username:</label>
- <input
- type="text"
- value={username}
- onChange={(e) => setUsername(e.target.value)}
- required
- />
- </div>
- <div>
- <label>Password:</label>
- <input
- type="password"
- value={password}
- onChange={(e) => setPassword(e.target.value)}
- required
- />
- </div>
- <button type="submit">Login</button>
- </form>
- </div>
- );
-}
-
-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 (
- <div className="Upload">
- <h2>Upload Content</h2>
- <input type="file" onChange={handleFileChange} />
- <button onClick={handleUpload}>Upload</button>
- <p>Upload Progress: {progress}%</p>
- {url && <p>File URL: <a href={url} target="_blank" rel="noopener noreferrer">{url}</a></p>}
- </div>
- );
-}
-
-export default Upload;