diff options
| author | Dhravya <[email protected]> | 2024-04-12 23:22:51 -0700 |
|---|---|---|
| committer | Dhravya <[email protected]> | 2024-04-12 23:22:51 -0700 |
| commit | ee9c598013deb9cf20882e6971267942d0832d7b (patch) | |
| tree | 021cf9ca808d1df024d7f63b007eb7bcecc49aac /apps/extension/src | |
| parent | mark runtime=edge for spaces (diff) | |
| download | supermemory-ee9c598013deb9cf20882e6971267942d0832d7b.tar.xz supermemory-ee9c598013deb9cf20882e6971267942d0832d7b.zip | |
bookmark tweets feature
Diffstat (limited to 'apps/extension/src')
| -rw-r--r-- | apps/extension/src/SideBar.tsx | 14 | ||||
| -rw-r--r-- | apps/extension/src/background.ts | 27 |
2 files changed, 37 insertions, 4 deletions
diff --git a/apps/extension/src/SideBar.tsx b/apps/extension/src/SideBar.tsx index 9ecb8afa..4cce9a17 100644 --- a/apps/extension/src/SideBar.tsx +++ b/apps/extension/src/SideBar.tsx @@ -65,6 +65,14 @@ function SideBar({ jwt }: { jwt: string }) { saveToUser: string; } + function sendBookmarkedTweetsToAPI(tweets: TweetData[], token: string) { + chrome.runtime.sendMessage({ + type: "sendBookmarkedTweets", + jwt: token, + tweets, + }); + } + const fetchBookmarks = () => { const tweets: TweetData[] = []; // Initialize an empty array to hold all tweet elements @@ -161,11 +169,9 @@ function SideBar({ jwt }: { jwt: string }) { observer.observe(document.body, { childList: true, subtree: true }); function downloadTweetsAsJson(tweetsArray: TweetData[]) { + setLog([...log, "Saving the tweets to our database..."]); + sendBookmarkedTweetsToAPI(tweetsArray, jwt); setIsImportingTweets(false); - const jsonData = JSON.stringify(tweetsArray); // Convert the array to JSON - - // TODO: send jsonData to the API - console.log(jsonData); } }; diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts index 44931dc4..7e12bba4 100644 --- a/apps/extension/src/background.ts +++ b/apps/extension/src/background.ts @@ -5,6 +5,15 @@ const backendUrl = ? "http://localhost:3000" : "https://supermemory.dhr.wtf"; +interface TweetData { + tweetText: string; + postUrl: string; + authorName: string; + handle: string; + time: string; + saveToUser: string; +} + // TODO: Implement getting bookmarks from Twitter API directly // let authorizationHeader: string | null = null; // let csrfToken: string | null = null; @@ -105,4 +114,22 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { // cookies: cookies // }); // } + else if (request.type === "sendBookmarkedTweets") { + const jwt = request.jwt; + const tweets = request.tweets as TweetData[]; + + (async () => { + await fetch(`${backendUrl}/api/vectorizeTweets`, { + method: "POST", + headers: { + Authorization: `Bearer ${jwt}`, + }, + body: JSON.stringify(tweets), + }).then(async (response) => { + return response.json(); + }); + })(); + + return true; + } }); |