Skip to content

Commit

Permalink
feature(mobile): Change the view bookmark page to be a modal and add …
Browse files Browse the repository at this point in the history
…tags and

notes
  • Loading branch information
MohamedBassem committed Aug 26, 2024
1 parent 8410a6d commit b094b2c
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 192 deletions.
82 changes: 0 additions & 82 deletions apps/mobile/app/dashboard/bookmarks/[slug].tsx

This file was deleted.

100 changes: 52 additions & 48 deletions apps/mobile/components/bookmarks/BookmarkCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
View,
} from "react-native";
import * as Haptics from "expo-haptics";
import { Link, router } from "expo-router";
import * as WebBrowser from "expo-web-browser";
import useAppSettings from "@/lib/settings";
import { api } from "@/lib/trpc";
Expand All @@ -35,7 +34,8 @@ import { useToast } from "../ui/Toast";
import BookmarkAssetImage from "./BookmarkAssetImage";
import BookmarkTextMarkdown from "./BookmarkTextMarkdown";
import ListPickerModal from "./ListPickerModal";
import NoteEditorModal from "./NewBookmarkModal";
import TagPill from "./TagPill";
import ViewBookmarkModal from "./ViewBookmarkModal";

function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
const { toast } = useToast();
Expand Down Expand Up @@ -75,7 +75,6 @@ function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
});

const manageListsSheetRef = useRef<BottomSheetModal>(null);
const editBookmarkModal = useRef<BottomSheetModal>(null);

return (
<View className="flex flex-row gap-4">
Expand All @@ -101,13 +100,6 @@ function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
snapPoints={["50%", "90%"]}
bookmarkId={bookmark.id}
/>
{bookmark.content.type === BookmarkTypes.TEXT && (
<NoteEditorModal
ref={editBookmarkModal}
bookmark={bookmark}
snapPoints={["90%", "60%"]}
/>
)}

<MenuView
onPressAction={({ nativeEvent }) => {
Expand All @@ -123,21 +115,9 @@ function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
});
} else if (nativeEvent.event === "manage_list") {
manageListsSheetRef?.current?.present();
} else if (nativeEvent.event === "edit") {
editBookmarkModal.current?.present();
}
}}
actions={[
{
id: "edit",
title: "Edit",
image: Platform.select({
ios: "edit",
}),
attributes: {
hidden: bookmark.content.type !== BookmarkTypes.TEXT,
},
},
{
id: "archive",
title: bookmark.archived ? "Un-archive" : "Archive",
Expand Down Expand Up @@ -187,21 +167,19 @@ function TagList({ bookmark }: { bookmark: ZBookmark }) {
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
<View className="flex flex-row gap-2">
{tags.map((t) => (
<View
key={t.id}
className="rounded-full border border-accent px-2.5 py-0.5 text-xs font-semibold"
>
<Link className="text-foreground" href={`dashboard/tags/${t.id}`}>
{t.name}
</Link>
</View>
<TagPill key={t.id} tag={t} />
))}
</View>
</ScrollView>
);
}

function LinkCard({ bookmark }: { bookmark: ZBookmark }) {
function LinkCard({
bookmark,
}: {
bookmark: ZBookmark;
onOpenBookmark: () => void;
}) {
const { settings } = useAppSettings();
if (bookmark.content.type !== BookmarkTypes.LINK) {
throw new Error("Wrong content type rendered");
Expand Down Expand Up @@ -264,26 +242,28 @@ function LinkCard({ bookmark }: { bookmark: ZBookmark }) {
);
}

function TextCard({ bookmark }: { bookmark: ZBookmark }) {
function TextCard({
bookmark,
onOpenBookmark,
}: {
bookmark: ZBookmark;
onOpenBookmark: () => void;
}) {
if (bookmark.content.type !== BookmarkTypes.TEXT) {
throw new Error("Wrong content type rendered");
}
const content = bookmark.content.text;
return (
<View className="flex max-h-96 gap-2 p-2">
<Pressable
onPress={() => router.push(`/dashboard/bookmarks/${bookmark.id}`)}
>
<Pressable onPress={onOpenBookmark}>
{bookmark.title && (
<Text className="line-clamp-2 text-xl font-bold text-foreground">
{bookmark.title}
</Text>
)}
</Pressable>
<View className="max-h-56 overflow-hidden p-2 text-foreground">
<Pressable
onPress={() => router.push(`/dashboard/bookmarks/${bookmark.id}`)}
>
<Pressable onPress={onOpenBookmark}>
<BookmarkTextMarkdown text={content} />
</Pressable>
</View>
Expand All @@ -297,26 +277,28 @@ function TextCard({ bookmark }: { bookmark: ZBookmark }) {
);
}

function AssetCard({ bookmark }: { bookmark: ZBookmark }) {
function AssetCard({
bookmark,
onOpenBookmark,
}: {
bookmark: ZBookmark;
onOpenBookmark: () => void;
}) {
if (bookmark.content.type !== BookmarkTypes.ASSET) {
throw new Error("Wrong content type rendered");
}
const title = bookmark.title ?? bookmark.content.fileName;

return (
<View className="flex gap-2">
<Pressable
onPress={() => router.push(`/dashboard/bookmarks/${bookmark.id}`)}
>
<Pressable onPress={onOpenBookmark}>
<BookmarkAssetImage
assetId={bookmark.content.assetId}
className="h-56 min-h-56 w-full object-cover"
/>
</Pressable>
<View className="flex gap-2 p-2">
<Pressable
onPress={() => router.push(`/dashboard/bookmarks/${bookmark.id}`)}
>
<Pressable onPress={onOpenBookmark}>
{title && (
<Text className="line-clamp-2 text-xl font-bold text-foreground">
{title}
Expand Down Expand Up @@ -359,21 +341,43 @@ export default function BookmarkCard({
},
);

const viewBookmarkModal = useRef<BottomSheetModal>(null);

let comp;
switch (bookmark.content.type) {
case BookmarkTypes.LINK:
comp = <LinkCard bookmark={bookmark} />;
comp = (
<LinkCard
bookmark={bookmark}
onOpenBookmark={() => viewBookmarkModal.current?.present()}
/>
);
break;
case BookmarkTypes.TEXT:
comp = <TextCard bookmark={bookmark} />;
comp = (
<TextCard
bookmark={bookmark}
onOpenBookmark={() => viewBookmarkModal.current?.present()}
/>
);
break;
case BookmarkTypes.ASSET:
comp = <AssetCard bookmark={bookmark} />;
comp = (
<AssetCard
bookmark={bookmark}
onOpenBookmark={() => viewBookmarkModal.current?.present()}
/>
);
break;
}

return (
<View className="overflow-hidden rounded-xl border-b border-accent bg-background">
<ViewBookmarkModal
bookmark={bookmark}
ref={viewBookmarkModal}
snapPoints={["95%"]}
/>
{comp}
</View>
);
Expand Down
Loading

0 comments on commit b094b2c

Please sign in to comment.