Skip to content

App #558

@sayemsarkar420

Description

@sayemsarkar420
import React, {useEffect, useState} from 'react';

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions