-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
import { initializeApp } from "firebase/app";
import { getFirestore, collection, query, where, onSnapshot, doc, updateDoc } from "firebase/firestore";
const firebaseConfig = {
// paste your firebase config here
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
function App() {
const [posts, setPosts] = useState([]);
useEffect(() => {
const q = query(collection(db, "posts"), where("status", "==", "pending"));
const unsub = onSnapshot(q, snap => {
const arr = snap.docs.map(d => ({id:d.id, ...d.data()}));
setPosts(arr);
});
return () => unsub();
}, []);
async function approve(id) {
const d = doc(db, "posts", id);
await updateDoc(d, {status: "approved"});
}
async function reject(id) {
const d = doc(db, "posts", id);
await updateDoc(d, {status: "rejected"});
}
return (
SECRET BD Admin - Pending Posts
{posts.map(p => (
<div key={p.id} style={{border:"1px solid #ccc", padding:10, margin:10}}>
{p.title}
{p.description}
<button onClick={() => approve(p.id)}>Approve
<button onClick={() => reject(p.id)}>Reject
))}
);
}
export default App;