aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/components/bookmarks/NewBookmarkModal.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/components/bookmarks/NewBookmarkModal.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/components/bookmarks/NewBookmarkModal.tsx')
-rw-r--r--apps/mobile/components/bookmarks/NewBookmarkModal.tsx98
1 files changed, 0 insertions, 98 deletions
diff --git a/apps/mobile/components/bookmarks/NewBookmarkModal.tsx b/apps/mobile/components/bookmarks/NewBookmarkModal.tsx
deleted file mode 100644
index 218c54b8..00000000
--- a/apps/mobile/components/bookmarks/NewBookmarkModal.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import React, { useState } from "react";
-import { Text, View } from "react-native";
-import {
- BottomSheetBackdrop,
- BottomSheetModal,
- BottomSheetModalProps,
- BottomSheetView,
- useBottomSheetModal,
-} from "@gorhom/bottom-sheet";
-
-import { useCreateBookmark } from "@hoarder/shared-react/hooks/bookmarks";
-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,
- Omit<BottomSheetModalProps, "children" | "backdropComponent" | "onDismiss">
->(({ ...props }, ref) => {
- const { dismiss } = useBottomSheetModal();
-
- 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 (
- <View>
- <BottomSheetModal
- ref={ref}
- backdropComponent={(props) => (
- <BottomSheetBackdrop
- appearsOnIndex={0}
- disappearsOnIndex={-1}
- {...props}
- />
- )}
- {...props}
- >
- <PageTitle title="New Bookmark" />
- <BottomSheetView className="gap-2 p-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" />
- </BottomSheetView>
- </BottomSheetModal>
- </View>
- );
-});
-NoteEditorModal.displayName = "NewBookmarkModal";
-
-export default NoteEditorModal;