From 6e6d2c3cbc860d0024e9631b01eeef55b47933a5 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Mon, 12 Feb 2024 20:50:12 +0000
Subject: WIP: Implement saving page functionality in browser extension

---
 packages/browser-extension/src/SavePage.tsx | 40 +++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 packages/browser-extension/src/SavePage.tsx

(limited to 'packages/browser-extension/src/SavePage.tsx')

diff --git a/packages/browser-extension/src/SavePage.tsx b/packages/browser-extension/src/SavePage.tsx
new file mode 100644
index 00000000..c66cc0ad
--- /dev/null
+++ b/packages/browser-extension/src/SavePage.tsx
@@ -0,0 +1,40 @@
+import { useEffect, useState } from "react";
+import { Settings } from "./settings";
+
+export default function SavePage({ settings }: { settings: Settings }) {
+  const [loading, setLoading] = useState(true);
+  const [error, setError] = useState<string | undefined>(undefined);
+
+  async function runFetch() {
+    const resp = await fetch(
+      `${settings.address}/api/trpc/bookmarks.bookmarkLink`,
+      {
+        method: "POST",
+      },
+    );
+
+    if (!resp.ok) {
+      setError("Something went wrong: " + (await resp.json()));
+    }
+    setLoading(false);
+  }
+
+  useEffect(() => {
+    runFetch();
+  }, []);
+
+  if (loading) {
+    return <div>Loading ...</div>;
+  }
+
+  if (error) {
+    return <div className="text-red-500">{error} ...</div>;
+  }
+
+  return (
+    <div>
+      SAVED!
+      <button onClick={runFetch}> Reload </button>
+    </div>
+  );
+}
-- 
cgit v1.2.3-70-g09d2

