From 5522e20104da6afe2e4667cf45dbbbbc0e838865 Mon Sep 17 00:00:00 2001
From: Mohamed Bassem <me@mbassem.com>
Date: Sat, 23 Nov 2024 20:59:34 +0000
Subject: ui(mobile): Replace bottom sheet with native screens (#690)

* Remove bottom sheet from bookmark info page

* Remove bottom sheet from manage lists page

* Remove bottom sheet from new list page

* Remove bottom sheet from new bookmark page

* Drop bottom-sheets

* Improve the look of the modals

* Make the search page fade from bottom
---
 apps/mobile/app/dashboard/bookmarks/new.tsx | 76 +++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 apps/mobile/app/dashboard/bookmarks/new.tsx

(limited to 'apps/mobile/app/dashboard/bookmarks/new.tsx')

diff --git a/apps/mobile/app/dashboard/bookmarks/new.tsx b/apps/mobile/app/dashboard/bookmarks/new.tsx
new file mode 100644
index 00000000..06a16a40
--- /dev/null
+++ b/apps/mobile/app/dashboard/bookmarks/new.tsx
@@ -0,0 +1,76 @@
+import React, { useState } from "react";
+import { Text, View } from "react-native";
+import { router } from "expo-router";
+import { Button } from "@/components/ui/Button";
+import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView";
+import { Input } from "@/components/ui/Input";
+import { useToast } from "@/components/ui/Toast";
+
+import { useCreateBookmark } from "@hoarder/shared-react/hooks/bookmarks";
+import { BookmarkTypes } from "@hoarder/shared/types/bookmarks";
+
+const NoteEditorPage = () => {
+  const dismiss = () => {
+    router.back();
+  };
+
+  const [text, setText] = useState("");
+  const [error, setError] = useState<string | undefined>();
+  const { toast } = useToast();
+
+  const { mutate: createBookmark } = useCreateBookmark({
+    onSuccess: (resp) => {
+      if (resp.alreadyExists) {
+        toast({
+          message: "Bookmark already exists",
+        });
+      }
+      setText("");
+      dismiss();
+    },
+    onError: (e) => {
+      let message;
+      if (e.data?.zodError) {
+        const zodError = e.data.zodError;
+        message = JSON.stringify(zodError);
+      } else {
+        message = `Something went wrong: ${e.message}`;
+      }
+      setError(message);
+    },
+  });
+
+  const onSubmit = () => {
+    const data = text.trim();
+    try {
+      const url = new URL(data);
+      if (url.protocol != "http:" && url.protocol != "https:") {
+        throw new Error(`Unsupported URL protocol: ${url.protocol}`);
+      }
+      createBookmark({ type: BookmarkTypes.LINK, url: data });
+    } catch (e: unknown) {
+      createBookmark({ type: BookmarkTypes.TEXT, text: data });
+    }
+  };
+
+  return (
+    <CustomSafeAreaView>
+      <View className="gap-2 px-4">
+        {error && (
+          <Text className="w-full text-center text-red-500">{error}</Text>
+        )}
+        <Input
+          onChangeText={setText}
+          multiline
+          placeholder="What's on your mind?"
+          autoFocus
+          autoCapitalize={"none"}
+          textAlignVertical="top"
+        />
+        <Button onPress={onSubmit} label="Save" />
+      </View>
+    </CustomSafeAreaView>
+  );
+};
+
+export default NoteEditorPage;
-- 
cgit v1.2.3-70-g09d2

