Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
aekmekci72 committed Aug 8, 2024
1 parent 197fbcf commit f849566
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 68 deletions.
32 changes: 1 addition & 31 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -116,26 +107,21 @@ 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'],
'timestamp': firestore.SERVER_TIMESTAMP,
'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
Expand All @@ -144,43 +130,35 @@ 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:
return jsonify({"error": str(e)}), 500
@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:
Expand All @@ -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')

Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/Board.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 5 additions & 6 deletions src/Login.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/Resources.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions src/Updates.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Updates.js
Original file line number Diff line number Diff line change
@@ -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([]);
Expand Down

0 comments on commit f849566

Please sign in to comment.