From 04572a8e5081b1e4871e273cde9dbaaa44c52fe0 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Wed, 13 Mar 2024 21:43:44 +0000
Subject: structure: Create apps dir and copy tooling dir from t3-turbo repo

---
 apps/mobile/app/dashboard/add-link.tsx | 57 ++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 apps/mobile/app/dashboard/add-link.tsx

(limited to 'apps/mobile/app/dashboard/add-link.tsx')

diff --git a/apps/mobile/app/dashboard/add-link.tsx b/apps/mobile/app/dashboard/add-link.tsx
new file mode 100644
index 00000000..69a9c7a2
--- /dev/null
+++ b/apps/mobile/app/dashboard/add-link.tsx
@@ -0,0 +1,57 @@
+import { useRouter } from "expo-router";
+import { useState } from "react";
+import { View, Text } from "react-native";
+
+import { Button } from "@/components/ui/Button";
+import { Input } from "@/components/ui/Input";
+import { api } from "@/lib/trpc";
+
+export default function AddNote() {
+  const [text, setText] = useState("");
+  const [error, setError] = useState<string | undefined>();
+  const router = useRouter();
+  const invalidateAllBookmarks =
+    api.useUtils().bookmarks.getBookmarks.invalidate;
+
+  const { mutate } = api.bookmarks.createBookmark.useMutation({
+    onSuccess: () => {
+      invalidateAllBookmarks();
+      if (router.canGoBack()) {
+        router.replace("../");
+      } else {
+        router.replace("dashboard");
+      }
+    },
+    onError: (e) => {
+      let message;
+      if (e.data?.code === "BAD_REQUEST") {
+        const error = JSON.parse(e.message)[0];
+        message = error.message;
+      } else {
+        message = `Something went wrong: ${e.message}`;
+      }
+      setError(message);
+    },
+  });
+
+  return (
+    <View className="flex gap-2 p-4">
+      {error && (
+        <Text className="w-full text-center text-red-500">{error}</Text>
+      )}
+      <Input
+        className="bg-white"
+        value={text}
+        onChangeText={setText}
+        placeholder="Link"
+        autoCapitalize="none"
+        inputMode="url"
+        autoFocus
+      />
+      <Button
+        onPress={() => mutate({ type: "link", url: text })}
+        label="Add Link"
+      />
+    </View>
+  );
+}
-- 
cgit v1.2.3-70-g09d2

