From f84956636d7209dc4564f964ed5097eb34d396b5 Mon Sep 17 00:00:00 2001 From: aekmekci72 Date: Thu, 8 Aug 2024 16:01:13 -0400 Subject: [PATCH] cleaning up --- app.py | 32 +------------------------------- src/Board.css | 6 +++--- src/Login.js | 11 +++++------ src/Navbar.css | 10 +++++----- src/Resources.css | 18 +++++++++--------- src/Updates.css | 26 +++++++++++++------------- src/Updates.js | 2 +- 7 files changed, 37 insertions(+), 68 deletions(-) diff --git a/app.py b/app.py index b4ae62d..2508bd8 100644 --- a/app.py +++ b/app.py @@ -8,11 +8,9 @@ load_dotenv() -# Initialize Flask app app = Flask(__name__) CORS(app, resources={r"/*": {"origins": "*"}}) -# Initialize Firebase cred = credentials.Certificate({ "type": "service_account", "project_id": os.environ.get("FIREBASE_PROJECT_ID"), @@ -28,7 +26,6 @@ firebase_admin.initialize_app(cred, { 'storageBucket': os.environ.get("FIREBASE_STORAGE_BUCKET") }) -# Get Firestore client db = firestore.client() bucket = storage.bucket() @@ -40,11 +37,9 @@ @app.route('/data') def get_data(): try: - # Fetch data from Firestore - collection_ref = db.collection('data') # Replace 'data' with your collection name + collection_ref = db.collection('data') docs = collection_ref.stream() - # Prepare the response data = {} for doc in docs: data[doc.id] = doc.to_dict() @@ -56,16 +51,13 @@ def get_data(): @app.route('/updates') def get_updates(): try: - # Fetch updates from Firestore updates_ref = db.collection('updates') docs = updates_ref.order_by('timestamp', direction=firestore.Query.DESCENDING).stream() - # Prepare the response updates = [] for doc in docs: update = doc.to_dict() update['id'] = doc.id - # Convert Firestore Timestamp to ISO format string update['timestamp'] = update['timestamp'].isoformat() if update.get('timestamp') else None updates.append(update) @@ -80,7 +72,6 @@ def get_events(): resources_ref = db.collection('resources').order_by('timestamp', direction=firestore.Query.DESCENDING).stream() resources_ref = resources_ref.stream() - # Prepare the response resources = [] for doc in resources_ref: resource = doc.to_dict() @@ -116,14 +107,11 @@ def uploaded_file(filename): @app.route('/addupdate', methods=['POST']) def add_update(): try: - # Get the JSON data from the request data = request.get_json() - # Validate the incoming data if not data or 'author' not in data or 'content' not in data: return jsonify({"error": "Invalid data"}), 400 - # Create a new document in the 'updates' collection update_ref = db.collection('updates').add({ 'author': data['author'], 'content': data['content'], @@ -131,11 +119,9 @@ def add_update(): 'images': data.get('images', []) }) - # Retrieve the newly created document new_update = update_ref[1].get().to_dict() new_update['id'] = update_ref[1].id - # Convert Firestore Timestamp to ISO format string new_update['timestamp'] = new_update['timestamp'].isoformat() if new_update.get('timestamp') else None return jsonify(new_update), 201 @@ -144,21 +130,17 @@ def add_update(): @app.route('/delete_update', methods=['DELETE']) def delete_update(): try: - # Get the update_id from the request body data = request.get_json() update_id = data.get('update_id') if not update_id: return jsonify({"error": "Update ID is required"}), 400 - # Reference the document in the 'updates' collection update_ref = db.collection('updates').document(update_id) - # Check if the document exists if not update_ref.get().exists: return jsonify({"error": "Update not found"}), 404 - # Delete the document update_ref.delete() return jsonify({"success": True}), 200 except Exception as e: @@ -166,21 +148,17 @@ def delete_update(): @app.route('/delete_resource', methods=['DELETE']) def delete_resource(): try: - # Get the resource_id from the request body data = request.get_json() resource_id = data.get('resource_id') if not resource_id: return jsonify({"error": "Resource ID is required"}), 400 - # Reference the document in the 'resources' collection resource_ref = db.collection('resources').document(resource_id) - # Check if the document exists if not resource_ref.get().exists: return jsonify({"error": "Resource not found"}), 404 - # Delete the document resource_ref.delete() return jsonify({"success": True}), 200 except Exception as e: @@ -189,22 +167,18 @@ def delete_resource(): @app.route('/get_role', methods=['POST']) def get_role(): try: - # Get the email from the request body data = request.get_json() email = data.get('email') if not email: return jsonify({"error": "Email is required"}), 400 - # Reference the document in the 'users' collection using the email as the document ID user_ref = db.collection('users').document(email) user_doc = user_ref.get() - # Check if the document exists if not user_doc.exists: return jsonify({"error": "User not found"}), 404 - # Get the role from the document user_data = user_doc.to_dict() role = user_data.get('role') @@ -219,21 +193,17 @@ def get_role(): @app.route('/addresource', methods=['POST']) def add_resource(): try: - # Get the JSON data from the request data = request.get_json() - # Validate the incoming data if not data or 'message' not in data or 'link' not in data: return jsonify({"error": "Invalid data"}), 400 - # Create a new document in the 'resources' collection resource_ref = db.collection('resources').add({ 'message': data['message'], 'link': data['link'], 'timestamp': firestore.SERVER_TIMESTAMP }) - # Retrieve the newly created document new_resource = resource_ref[1].get().to_dict() new_resource['id'] = resource_ref[1].id diff --git a/src/Board.css b/src/Board.css index 5d37e21..917b2e9 100644 --- a/src/Board.css +++ b/src/Board.css @@ -51,7 +51,7 @@ .character-card-inner { position: relative; width: 100%; - height: 300px; /* Adjust height as needed */ + height: 300px; transition: transform 0.6s; transform-style: preserve-3d; } @@ -80,8 +80,8 @@ } .character-card-front img { - width: 100px; /* Adjust size as needed */ - height: 100px; /* Adjust size as needed */ + width: 100px; + height: 100px; border-radius: 50%; margin-bottom: 1rem; } diff --git a/src/Login.js b/src/Login.js index 468c8f3..d24f222 100644 --- a/src/Login.js +++ b/src/Login.js @@ -1,22 +1,21 @@ import React, { useState } from 'react'; -import { auth } from './firebase'; // Import the auth object from your firebase.js +import { auth } from './firebase'; import { signInWithEmailAndPassword } from 'firebase/auth'; -import { useNavigate } from 'react-router-dom'; // Import useNavigate from react-router-dom -import './Login.css'; // Import the CSS file +import { useNavigate } from 'react-router-dom'; +import './Login.css'; const LoginPage = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); - const navigate = useNavigate(); // Initialize the useNavigate hook + const navigate = useNavigate(); const handleLogin = (e) => { e.preventDefault(); signInWithEmailAndPassword(auth, email, password) .then((userCredential) => { - // Signed in console.log('User signed in:', userCredential.user); - navigate('/'); // Navigate to the homepage + navigate('/'); }) .catch((error) => { setError(error.message); diff --git a/src/Navbar.css b/src/Navbar.css index 8f0e878..66063f9 100644 --- a/src/Navbar.css +++ b/src/Navbar.css @@ -6,7 +6,7 @@ background-color: rgba(255, 255, 255, 0.9); padding: 1rem 2rem; display: flex; - justify-content: center; /* Centers the navbar content */ + justify-content: center; align-items: center; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); z-index: 1000; @@ -16,7 +16,7 @@ display: flex; justify-content: space-between; align-items: center; - width: 100%; /* Ensures the content takes the full width */ + width: 100%; } .logo { @@ -54,15 +54,15 @@ background: none; border: none; cursor: pointer; - margin-left: auto; /* Pushes the button to the right */ + margin-left: auto; } .dropdown-menu { display: none; flex-direction: column; position: absolute; - top: 60px; /* Adjust based on your navbar height */ - right: 2rem; /* Aligns to the right of the screen */ + top: 60px; + right: 2rem; background-color: rgba(255, 255, 255, 0.9); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); z-index: 999; diff --git a/src/Resources.css b/src/Resources.css index aee9cf5..e0f9141 100644 --- a/src/Resources.css +++ b/src/Resources.css @@ -2,11 +2,11 @@ max-width: 800px; margin: 0 auto; padding: 2rem 1rem; - margin-top: 5rem; /* Start updates lower to avoid navbar overlap */ + margin-top: 5rem; } .updates-box { - background-color: rgba(255, 255, 255, 0.9); /* Semi-transparent white */ + background-color: rgba(255, 255, 255, 0.9); border-radius: 10px; padding: 2rem; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); @@ -21,7 +21,7 @@ } .update-image { - max-width: 100px; /* Tiny preview size */ + max-width: 100px; max-height: 100px; cursor: pointer; transition: transform 0.2s ease-in-out; @@ -49,10 +49,10 @@ } .expanded-image { - max-width: 50vw; /* Maximum width is 50% of viewport width */ - max-height: 50vh; /* Maximum height is 50% of viewport height */ - width: auto; /* Maintain aspect ratio */ - height: auto; /* Maintain aspect ratio */ + max-width: 50vw; + max-height: 50vh; + width: auto; + height: auto; transition: transform 0.3s ease-in-out; } .expanded-image-overlay:after { @@ -165,10 +165,10 @@ } } -/* Add this to your existing CSS */ + .resource-link { - color: #4169E1; /* A nice blue color */ + color: #4169E1; text-decoration: none; font-size: 0.9rem; transition: color 0.3s ease; diff --git a/src/Updates.css b/src/Updates.css index 35e0279..4be1ce8 100644 --- a/src/Updates.css +++ b/src/Updates.css @@ -2,20 +2,20 @@ max-width: 800px; margin: 0 auto; padding: 2rem 1rem; - margin-top: 5rem; /* Start updates lower to avoid navbar overlap */ + margin-top: 5rem; } .updates-box { - background-color: rgba(255, 255, 255, 0.9); /* Semi-transparent white */ + background-color: rgba(255, 255, 255, 0.9); border-radius: 10px; padding: 2rem; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); animation: bounceIn 0.6s ease forwards; } .image-previews { - display: flex; /* Align images in a row */ - flex-wrap: wrap; /* Allow wrapping to the next line if there are too many images */ - gap: 10px; /* Add some space between the images */ + display: flex; + flex-wrap: wrap; + gap: 10px; } .add-update { @@ -34,7 +34,7 @@ } .image-preview-container { position: relative; - display: inline-block; /* Use inline-block to keep the images side by side */ + display: inline-block; margin: 5px; } .image-preview { @@ -59,10 +59,10 @@ opacity: 0.8; } .update-image { - width: 100px; /* Ensure consistency with update images */ + width: 100px; height: auto; margin: 5px; - cursor: pointer; /* Allow pointer cursor for expandable images */ + cursor: pointer; } .add-update button { @@ -97,7 +97,7 @@ } .update-image { - max-width: 100px; /* Tiny preview size */ + max-width: 100px; max-height: 100px; cursor: pointer; transition: transform 0.2s ease-in-out; @@ -125,10 +125,10 @@ } .expanded-image { - max-width: 50vw; /* Maximum width is 50% of viewport width */ - max-height: 50vh; /* Maximum height is 50% of viewport height */ - width: auto; /* Maintain aspect ratio */ - height: auto; /* Maintain aspect ratio */ + max-width: 50vw; + max-height: 50vh; + width: auto; + height: auto; transition: transform 0.3s ease-in-out; } .expanded-image-overlay:after { diff --git a/src/Updates.js b/src/Updates.js index 674ef98..7921499 100644 --- a/src/Updates.js +++ b/src/Updates.js @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import Navbar from './Navbar'; -import './Updates.css'; // Make sure to import the CSS file +import './Updates.css'; const Updates = () => { const [updates, setUpdates] = useState([]);