aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/components
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-08-26 17:07:10 +0300
committerMohamedBassem <me@mbassem.com>2024-08-26 17:07:10 +0300
commit49dc06e1a3e47892dc93b6c3c9dcc3c7d892430e (patch)
tree3d9c3e38e8885bd5e84b83741e10d10abac24374 /apps/mobile/components
parentb094b2cecb0da1bcdf4c63dd081638d87793c53c (diff)
downloadkarakeep-49dc06e1a3e47892dc93b6c3c9dcc3c7d892430e.tar.zst
ui(mobile): Merge the editors for notes and links
Diffstat (limited to '')
-rw-r--r--apps/mobile/components/bookmarks/NewBookmarkModal.tsx38
1 files changed, 27 insertions, 11 deletions
diff --git a/apps/mobile/components/bookmarks/NewBookmarkModal.tsx b/apps/mobile/components/bookmarks/NewBookmarkModal.tsx
index 6915c663..218c54b8 100644
--- a/apps/mobile/components/bookmarks/NewBookmarkModal.tsx
+++ b/apps/mobile/components/bookmarks/NewBookmarkModal.tsx
@@ -14,6 +14,7 @@ import { BookmarkTypes } from "@hoarder/shared/types/bookmarks";
import { Button } from "../ui/Button";
import { Input } from "../ui/Input";
import PageTitle from "../ui/PageTitle";
+import { useToast } from "../ui/Toast";
const NoteEditorModal = React.forwardRef<
BottomSheetModal,
@@ -23,14 +24,18 @@ const NoteEditorModal = React.forwardRef<
const [text, setText] = useState("");
const [error, setError] = useState<string | undefined>();
-
- const onSuccess = () => {
- setText("");
- dismiss();
- };
+ const { toast } = useToast();
const { mutate: createBookmark } = useCreateBookmark({
- onSuccess,
+ onSuccess: (resp) => {
+ if (resp.alreadyExists) {
+ toast({
+ message: "Bookmark already exists",
+ });
+ }
+ setText("");
+ dismiss();
+ },
onError: (e) => {
let message;
if (e.data?.zodError) {
@@ -43,6 +48,19 @@ const NoteEditorModal = React.forwardRef<
},
});
+ 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 (
<View>
<BottomSheetModal
@@ -56,7 +74,7 @@ const NoteEditorModal = React.forwardRef<
)}
{...props}
>
- <PageTitle title="New Note" />
+ <PageTitle title="New Bookmark" />
<BottomSheetView className="gap-2 p-4">
{error && (
<Text className="w-full text-center text-red-500">{error}</Text>
@@ -66,12 +84,10 @@ const NoteEditorModal = React.forwardRef<
multiline
placeholder="What's on your mind?"
autoFocus
+ autoCapitalize={"none"}
textAlignVertical="top"
/>
- <Button
- onPress={() => createBookmark({ type: BookmarkTypes.TEXT, text })}
- label="Add Note"
- />
+ <Button onPress={onSubmit} label="Save" />
</BottomSheetView>
</BottomSheetModal>
</View>