import React, { useState } from "react"; import { 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 { Text } from "@/components/ui/Text"; import { useToast } from "@/components/ui/Toast"; import { useCreateBookmarkList } from "@karakeep/shared-react/hooks/lists"; type ListType = "manual" | "smart"; const NewListPage = () => { const dismiss = () => { router.back(); }; const { toast } = useToast(); const [text, setText] = useState(""); const [listType, setListType] = useState("manual"); const [query, setQuery] = useState(""); const { mutate, isPending } = useCreateBookmarkList({ onSuccess: () => { dismiss(); }, onError: (error) => { // Extract error message from the error object let errorMessage = "Something went wrong"; if (error.data?.zodError) { errorMessage = Object.values(error.data.zodError.fieldErrors) .flat() .join("\n"); } else if (error.message) { errorMessage = error.message; } toast({ message: errorMessage, variant: "destructive", }); }, }); const onSubmit = () => { // Validate smart list has a query if (listType === "smart" && !query.trim()) { toast({ message: "Smart lists must have a search query", variant: "destructive", }); return; } mutate({ name: text, icon: "🚀", type: listType, query: listType === "smart" ? query : undefined, }); }; return ( {/* List Type Selector */} List Type {/* List Name */} 🚀 {/* Smart List Query Input */} {listType === "smart" && ( Search Query Smart lists automatically show bookmarks matching your search query )} ); }; export default NewListPage;