-
Notifications
You must be signed in to change notification settings - Fork 0
/
addfirebase.jsx
44 lines (35 loc) · 1.54 KB
/
addfirebase.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, { useEffect } from 'react';
import { collection, addDoc } from 'firebase/firestore';
import { projects } from './src/constants';
import { db } from './firebase';
const UploadProjects = () => {
useEffect(() => {
const uploadProjects = async () => {
try {
const projectsCollection = collection(db, 'Blogs'); // create or reference the collection 'projects'
// Iterate over each project and add to Firebase
for (const project of projects) {
const projectData = {
date: project.date,
description: project.description,
image: project.image || '',
index: projects.indexOf(project),
name: project.name,
source_code_link: project.source_code_link,
tags: project.tags.map((tag) => ({
[tag.name]: tag.color,
})),
};
// Add project to Firestore
await addDoc(projectsCollection, projectData);
console.log(`Project '${project.name}' uploaded successfully!`);
}
} catch (error) {
console.error('Error uploading projects: ', error);
}
};
uploadProjects(); // Call the function when the component mounts
}, []);
return <div>Uploading Projects to Firebase...</div>;
};
export default UploadProjects;