// App.jsx // Sahra Social - React + Firebase starter (single-file App) // Replace firebaseConfig and ADMIN_EMAIL before running. // Tailwind assumed to be configured. import React, { useEffect, useState } from 'react' import ReactDOM from 'react-dom/client' import firebase from 'firebase/compat/app' import 'firebase/compat/auth' import 'firebase/compat/firestore' import 'firebase/compat/storage' import './styles.css' // make sure Tailwind utilities are available // -------------------- CONFIG -------------------- const firebaseConfig = { apiKey: 'YOUR_API_KEY', authDomain: 'YOUR_PROJECT.firebaseapp.com', projectId: 'YOUR_PROJECT', storageBucket: 'YOUR_PROJECT.appspot.com', messagingSenderId: 'YOUR_SENDER_ID', appId: 'YOUR_APP_ID' } const ADMIN_EMAIL = 'YOU@EXAMPLE.COM' // set your admin email here // ------------------------------------------------ if (!firebase.apps.length) firebase.initializeApp(firebaseConfig) const auth = firebase.auth() const db = firebase.firestore() const storage = firebase.storage() // Simple button wrapper function Button({ children, className = '', ...props }) { return ( ) } // -------------------- PostEditor (Admin) -------------------- function PostEditor({ onDone }) { const [title, setTitle] = useState('') const [content, setContent] = useState('') const [file, setFile] = useState(null) const [tag, setTag] = useState('weekly') const [publishing, setPublishing] = useState(false) async function publish() { if (!title.trim() || !content.trim()) return alert('Add title and content') setPublishing(true) try { const postRef = db.collection('posts').doc() await postRef.set({ title: title.trim(), content: content.trim(), tag, likes: 0, views: 0, timestamp: firebase.firestore.FieldValue.serverTimestamp(), owner: true }) if (file) { const uploadRef = storage.ref(`posts/${postRef.id}/${file.name}`) await uploadRef.put(file) const url = await uploadRef.getDownloadURL() await postRef.update({ imageUrl: url }) } setTitle('') setContent('') setFile(null) setTag('weekly') onDone && onDone() } catch (err) { console.error(err) alert('Publish failed: ' + (err.message || err)) } finally { setPublishing(false) } } return (

Create Post

setTitle(e.target.value)} placeholder="Title" className="w-full p-2 border rounded mb-2" />