You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.9 KiB

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore, collection, doc, writeBatch, setDoc } from "firebase/firestore";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyB3Yfrh18w5VNSb36LFHJHvegTSv_W1VOU",
authDomain: "uc-23070-grayscale.firebaseapp.com",
projectId: "uc-23070-grayscale",
storageBucket: "uc-23070-grayscale.firebasestorage.app",
messagingSenderId: "866564340708",
appId: "1:866564340708:web:31eea78e6c56eeab6825f1",
measurementId: "G-NNY50B5T9F"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
export function addKeywords(keywords) {
console.log('Adding keywords to Firestore:', keywords);
const sortedKeywords = [...keywords].sort((a, b) => a.id - b.id);
const db = getFirestore(app);
const batch = writeBatch(db);
sortedKeywords.forEach((keyword) => {
const keywordRef = doc(db, "keywords", keyword.id.toString());
const keywordDoc = {
...keyword,
updatedTime: new Date(),
};
batch.set(keywordRef, keywordDoc);
});
batch.commit()
.then(() => {
console.log("Keywords added successfully!");
})
.catch((error) => {
console.error("Error adding keywords: ", error);
});
}
export function lookatKeyword(keyword) {
console.log('Looking at keyword in Firestore:', keyword);
const db = getFirestore(app);
const keywordRef = doc(collection(db, "lookat"), 'latest');
// Update the keyword document with the focused state
setDoc(keywordRef, {
id: keyword.id,
title: keyword.title,
updatedTime: new Date(),
});
}