-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(mobile): Add ability to create basic lists from the app
- Loading branch information
1 parent
410b0e7
commit 1405540
Showing
3 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useState } from "react"; | ||
import { Text, View } from "react-native"; | ||
import { | ||
BottomSheetBackdrop, | ||
BottomSheetModal, | ||
BottomSheetModalProps, | ||
BottomSheetView, | ||
useBottomSheetModal, | ||
} from "@gorhom/bottom-sheet"; | ||
|
||
import { useCreateBookmarkList } from "@hoarder/shared-react/hooks/lists"; | ||
|
||
import { Button } from "../ui/Button"; | ||
import { Input } from "../ui/Input"; | ||
import PageTitle from "../ui/PageTitle"; | ||
import { useToast } from "../ui/Toast"; | ||
|
||
const NewListModal = React.forwardRef< | ||
BottomSheetModal, | ||
Omit<BottomSheetModalProps, "children" | "backdropComponent" | "onDismiss"> | ||
>(({ ...props }, ref) => { | ||
const { dismiss } = useBottomSheetModal(); | ||
const { toast } = useToast(); | ||
const [text, setText] = useState(""); | ||
|
||
const { mutate, isPending } = useCreateBookmarkList({ | ||
onSuccess: () => { | ||
dismiss(); | ||
}, | ||
onError: () => { | ||
toast({ | ||
message: "Something went wrong", | ||
variant: "destructive", | ||
}); | ||
}, | ||
}); | ||
|
||
const onSubmit = () => { | ||
mutate({ | ||
name: text, | ||
icon: "🚀", | ||
}); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<BottomSheetModal | ||
ref={ref} | ||
onDismiss={() => setText("")} | ||
backdropComponent={(props) => ( | ||
<BottomSheetBackdrop | ||
appearsOnIndex={0} | ||
disappearsOnIndex={-1} | ||
{...props} | ||
/> | ||
)} | ||
{...props} | ||
> | ||
<PageTitle title="New List" /> | ||
<BottomSheetView className="gap-2 px-4"> | ||
<BottomSheetView className="flex flex-row items-center gap-1"> | ||
<Text className="shrink p-2">🚀</Text> | ||
<Input | ||
className="flex-1" | ||
onChangeText={setText} | ||
placeholder="List Name" | ||
autoFocus | ||
autoCapitalize={"none"} | ||
/> | ||
</BottomSheetView> | ||
<Button disabled={isPending} onPress={onSubmit} label="Save" /> | ||
</BottomSheetView> | ||
</BottomSheetModal> | ||
</View> | ||
); | ||
}); | ||
|
||
NewListModal.displayName = "NewListModal"; | ||
|
||
export default NewListModal; |