Skip to content

Commit

Permalink
feat(mobile): Allow editing titles and a cleaner info page
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Nov 23, 2024
1 parent 5522e20 commit fbb2644
Showing 1 changed file with 73 additions and 14 deletions.
87 changes: 73 additions & 14 deletions apps/mobile/app/dashboard/bookmarks/[slug]/info.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
import React from "react";
import { Text, View } from "react-native";
import { Stack, useLocalSearchParams } from "expo-router";
import {
Keyboard,
Pressable,
Text,
TouchableWithoutFeedback,
View,
} from "react-native";
import { ScrollView } from "react-native-gesture-handler";
import { router, Stack, useLocalSearchParams } from "expo-router";
import TagPill from "@/components/bookmarks/TagPill";
import FullPageError from "@/components/FullPageError";
import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
import { Input } from "@/components/ui/Input";
import { Skeleton } from "@/components/ui/Skeleton";
import { api } from "@/lib/trpc";
import { ChevronRight } from "lucide-react-native";

import { useUpdateBookmark } from "@hoarder/shared-react/hooks/bookmarks";
import { isBookmarkStillTagging } from "@hoarder/shared-react/utils/bookmarkUtils";
import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks";

function TagList({ bookmark }: { bookmark: ZBookmark }) {
return (
<View className="flex flex-row items-center gap-4">
<Text className="text-foreground">Tags</Text>
<View className="flex gap-4">
<Text className="text-lg text-foreground">Tags</Text>
{isBookmarkStillTagging(bookmark) ? (
<>
<Skeleton className="h-4 w-full" />
<Skeleton className="h-4 w-full" />
</>
) : bookmark.tags.length > 0 ? (
<View className="flex flex-row flex-wrap gap-2">
<View className="flex flex-row flex-wrap gap-2 rounded-lg bg-background p-4">
{bookmark.tags.map((t) => (
<TagPill key={t.id} tag={t} />
))}
Expand All @@ -35,14 +43,61 @@ function TagList({ bookmark }: { bookmark: ZBookmark }) {
);
}

function ManageLists({ bookmark }: { bookmark: ZBookmark }) {
return (
<View className="flex gap-4">
<Text className="text-lg text-foreground">Lists</Text>
<Pressable
onPress={() =>
router.push(`/dashboard/bookmarks/${bookmark.id}/manage_lists`)
}
className="flex w-full flex-row justify-between gap-3 rounded-lg bg-white px-4 py-2 dark:bg-accent"
>
<Text className="text-lg text-accent-foreground">Manage Lists</Text>
<ChevronRight color="rgb(0, 122, 255)" />
</Pressable>
</View>
);
}

function TitleEditor({
bookmarkId,
title,
}: {
bookmarkId: string;
title: string;
}) {
const { mutate, isPending } = useUpdateBookmark();
return (
<View className="flex gap-4">
<Text className="text-lg text-foreground">Title</Text>

<Input
editable={!isPending}
multiline={true}
numberOfLines={3}
loading={isPending}
placeholder="Title"
textAlignVertical="top"
onEndEditing={(ev) =>
mutate({
bookmarkId,
title: ev.nativeEvent.text ? ev.nativeEvent.text : null,
})
}
defaultValue={title ?? ""}
/>
</View>
);
}

function NotesEditor({ bookmark }: { bookmark: ZBookmark }) {
const { mutate, isPending } = useUpdateBookmark();
return (
<View className="flex flex-row items-center gap-4">
<Text className="text-foreground">Notes</Text>
<View className="flex gap-4">
<Text className="text-lg text-foreground">Notes</Text>

<Input
className="flex-1"
editable={!isPending}
multiline={true}
numberOfLines={3}
Expand Down Expand Up @@ -102,12 +157,16 @@ const ViewBookmarkPage = () => {
headerTitle: title ?? "Untitled",
}}
/>
<View className="w-full p-4">
<View className="gap-4 px-4">
<TagList bookmark={bookmark} />
<NotesEditor bookmark={bookmark} />
</View>
</View>
<ScrollView className="h-screen w-full p-4">
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View className="gap-4 px-2">
<TitleEditor bookmarkId={bookmark.id} title={title ?? ""} />
<TagList bookmark={bookmark} />
<ManageLists bookmark={bookmark} />
<NotesEditor bookmark={bookmark} />
</View>
</TouchableWithoutFeedback>
</ScrollView>
</CustomSafeAreaView>
);
};
Expand Down

0 comments on commit fbb2644

Please sign in to comment.