aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/app/dashboard/bookmarks/new.tsx
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-11-23 20:59:34 +0000
committerGitHub <noreply@github.com>2024-11-23 20:59:34 +0000
commit5522e20104da6afe2e4667cf45dbbbbc0e838865 (patch)
tree72f416fa83c97a8533eea431e25bd63bda1e7d81 /apps/mobile/app/dashboard/bookmarks/new.tsx
parent4bb74872fd518008afea16a136292037baf5b024 (diff)
downloadkarakeep-5522e20104da6afe2e4667cf45dbbbbc0e838865.tar.zst
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
Diffstat (limited to 'apps/mobile/app/dashboard/bookmarks/new.tsx')
-rw-r--r--apps/mobile/app/dashboard/bookmarks/new.tsx76
1 files changed, 76 insertions, 0 deletions
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;