Skip to content

Commit

Permalink
Merge pull request #42 from rampantvoid/rampantvoid
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
akanksha2305 authored Jul 15, 2024
2 parents 9a5fdc4 + d5a5e6c commit 74e6280
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
69 changes: 69 additions & 0 deletions src/extenssion/bookmarkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import {
updateBookmark,
deleteBookmark,
} from "../service/bookmarkService.js";
import {
collection,
addDoc,
getDoc,
getDocs,
updateDoc,
deleteDoc,
doc,
query,
where,
} from "https://www.gstatic.com/firebasejs/9.22.1/firebase-firestore.js";
import { db } from "../firebaseConfig.js";

const COLLECTION_NAME = "bookmarks";

class BookmarkManager {
constructor(userId) {
Expand Down Expand Up @@ -63,6 +77,61 @@ class BookmarkManager {
throw error;
}
}

async getAllTags() {
try {
const q = query(
collection(db, COLLECTION_NAME),
where("userId", "==", this.userId)
);
const querySnapshot = await getDocs(q);

// Use a Set to store unique tags
const tagSet = new Set();

querySnapshot.forEach((doc) => {
const bookmark = doc.data();
if (bookmark.keywords && Array.isArray(bookmark.keywords)) {
bookmark.keywords.forEach((tag) => tagSet.add(tag));
}
});

// Convert Set to Array and sort alphabetically
const allTags = Array.from(tagSet).sort((a, b) => a.localeCompare(b));

return allTags;
} catch (error) {
console.error("Error fetching all tags:", error);
throw error;
}
}

async getTagCount() {
try {
const allTags = await this.getAllTags();
const tagCount = {};

const q = query(
collection(db, COLLECTION_NAME),
where("userId", "==", this.userId)
);
const querySnapshot = await getDocs(q);

querySnapshot.forEach((doc) => {
const bookmark = doc.data();
if (bookmark.keywords && Array.isArray(bookmark.keywords)) {
bookmark.keywords.forEach((tag) => {
tagCount[tag] = (tagCount[tag] || 0) + 1;
});
}
});

return allTags.map((tag) => ({ tag, count: tagCount[tag] || 0 }));
} catch (error) {
console.error("Error getting tag count:", error);
throw error;
}
}
}

export default BookmarkManager;
2 changes: 2 additions & 0 deletions src/extenssion/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ let bookmarkManager;

async function fetchLatestBookmarks() {
try {
const tags = await bookmarkManager.getTagCount();
console.log(tags);
const allBookmarks = await bookmarkManager.getAllBookmarks();
const sortedBookmarks = allBookmarks.sort(
(a, b) => b.timestamp - a.timestamp
Expand Down
2 changes: 1 addition & 1 deletion src/tag-classification/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GoogleGenerativeAI } from "https://esm.run/@google/generative-ai";

const genAI = new GoogleGenerativeAI("AIzaSyAGGFFsi64yOm93TypJeZrweUo23gCKw2M");
const genAI = new GoogleGenerativeAI("");

async function generateTags(url, title, summary, notes) {
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
Expand Down
2 changes: 1 addition & 1 deletion src/text-summarization-model/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GoogleGenerativeAI } from "https://esm.run/@google/generative-ai";

const genAI = new GoogleGenerativeAI("AIzaSyAGGFFsi64yOm93TypJeZrweUo23gCKw2M");
const genAI = new GoogleGenerativeAI("");

const parseCustomJson = async (text) => {
try {
Expand Down

0 comments on commit 74e6280

Please sign in to comment.