diff options
| author | MohamedBassem <me@mbassem.com> | 2024-07-28 20:03:15 -0700 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-07-28 20:56:27 -0700 |
| commit | 93afb75619a02aa741b464634911b994620092be (patch) | |
| tree | 414eb0b184027c67b01112caa56c039f2d82aebf /apps/mobile/app | |
| parent | 92c92c161b3195bdfb571284e783f39f369a25a5 (diff) | |
| download | karakeep-93afb75619a02aa741b464634911b994620092be.tar.zst | |
feat(mobile): Add ability to manage lists
Diffstat (limited to 'apps/mobile/app')
| -rw-r--r-- | apps/mobile/app/_layout.tsx | 50 | ||||
| -rw-r--r-- | apps/mobile/app/sharing.tsx | 40 |
2 files changed, 60 insertions, 30 deletions
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx index a5aafb8c..f56aa810 100644 --- a/apps/mobile/app/_layout.tsx +++ b/apps/mobile/app/_layout.tsx @@ -3,6 +3,7 @@ import "expo-dev-client"; import { useEffect } from "react"; import { View } from "react-native"; +import { GestureHandlerRootView } from "react-native-gesture-handler"; import { useRouter } from "expo-router"; import { Stack } from "expo-router/stack"; import { ShareIntentProvider, useShareIntent } from "expo-share-intent"; @@ -10,6 +11,7 @@ import { StatusBar } from "expo-status-bar"; import { StyledStack } from "@/components/navigation/stack"; import { Providers } from "@/lib/providers"; import { cn } from "@/lib/utils"; +import { BottomSheetModalProvider } from "@gorhom/bottom-sheet"; import { useColorScheme } from "nativewind"; export default function RootLayout() { @@ -28,28 +30,32 @@ export default function RootLayout() { return ( <ShareIntentProvider> <Providers> - <View - className={cn( - "w-full flex-1 bg-gray-100 text-foreground dark:bg-background", - colorScheme == "dark" ? "dark" : "light", - )} - > - <StyledStack - contentClassName="bg-gray-100 dark:bg-background" - screenOptions={{ - headerShown: false, - }} - > - <Stack.Screen name="index" /> - <Stack.Screen - name="sharing" - options={{ - presentation: "modal", - }} - /> - </StyledStack> - <StatusBar style="auto" /> - </View> + <GestureHandlerRootView style={{ flex: 1 }}> + <BottomSheetModalProvider> + <View + className={cn( + "w-full flex-1 bg-gray-100 text-foreground dark:bg-background", + colorScheme == "dark" ? "dark" : "light", + )} + > + <StyledStack + contentClassName="bg-gray-100 dark:bg-background" + screenOptions={{ + headerShown: false, + }} + > + <Stack.Screen name="index" /> + <Stack.Screen + name="sharing" + options={{ + presentation: "modal", + }} + /> + </StyledStack> + <StatusBar style="auto" /> + </View> + </BottomSheetModalProvider> + </GestureHandlerRootView> </Providers> </ShareIntentProvider> ); diff --git a/apps/mobile/app/sharing.tsx b/apps/mobile/app/sharing.tsx index d1d39e5b..ee7bd609 100644 --- a/apps/mobile/app/sharing.tsx +++ b/apps/mobile/app/sharing.tsx @@ -1,10 +1,13 @@ -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { ActivityIndicator, Text, View } from "react-native"; import { useRouter } from "expo-router"; import { useShareIntentContext } from "expo-share-intent"; +import ListPickerModal from "@/components/bookmarks/ListPickerModal"; +import { Button } from "@/components/ui/Button"; import useAppSettings from "@/lib/settings"; import { api } from "@/lib/trpc"; import { useUploadAsset } from "@/lib/upload"; +import { BottomSheetModal } from "@gorhom/bottom-sheet"; import { z } from "zod"; import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks"; @@ -80,18 +83,39 @@ export default function Sharing() { const router = useRouter(); const [mode, setMode] = useState<Mode>({ type: "idle" }); + let autoCloseTimeoutId: NodeJS.Timeout | null = null; + const addToListSheetRef = useRef<BottomSheetModal>(null); + let comp; switch (mode.type) { case "idle": { comp = <SaveBookmark setMode={setMode} />; break; } + case "alreadyExists": case "success": { - comp = <Text className="text-4xl text-foreground">Hoarded!</Text>; - break; - } - case "alreadyExists": { - comp = <Text className="text-4xl text-foreground">Already Hoarded!</Text>; + comp = ( + <View className="items-center gap-4"> + <ListPickerModal + ref={addToListSheetRef} + snapPoints={["90%"]} + bookmarkId={mode.bookmarkId} + onDismiss={() => router.replace("dashboard")} + /> + <Text className="text-4xl text-foreground"> + {mode.type === "alreadyExists" ? "Already Hoarded!" : "Hoarded!"} + </Text> + <Button + label="Add to List" + onPress={() => { + addToListSheetRef.current?.present(); + if (autoCloseTimeoutId) { + clearTimeout(autoCloseTimeoutId); + } + }} + /> + </View> + ); break; } case "error": { @@ -106,11 +130,11 @@ export default function Sharing() { return; } - const timeoutId = setTimeout(() => { + autoCloseTimeoutId = setTimeout(() => { router.replace("dashboard"); }, 2000); - return () => clearTimeout(timeoutId); + return () => clearTimeout(autoCloseTimeoutId!); }, [mode.type]); return ( |
