⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
feat(mobile): improved dashboard
daniel31x13e0abe1df39a5
diff --git a/apps/mobile/app/(tabs)/(dashboard)/_layout.tsx b/apps/mobile/app/(tabs)/(dashboard)/_layout.tsxdeleted file mode 100644index 6f91c5cb..00000000--- a/apps/mobile/app/(tabs)/(dashboard)/_layout.tsx+++ /dev/null@@ -1,51 +0,0 @@-import { IconSymbol } from "@/components/ui/IconSymbol";-import { Stack } from "expo-router";-import { TouchableOpacity } from "react-native";-import { SheetManager } from "react-native-actions-sheet";-import * as DropdownMenu from "zeego/dropdown-menu";--export default function RootLayout() {- return (- <Stack- screenOptions={{- headerTitle: "Dashboard",- headerLargeTitle: true,- headerTransparent: true,- headerBlurEffect: "systemUltraThinMaterial",- headerLargeStyle: {- backgroundColor: "#f2f2f2",- },- headerRight: () => (- <DropdownMenu.Root>- <DropdownMenu.Trigger>- <TouchableOpacity>- <IconSymbol size={20} name="plus" color={"#3478f6"} />- </TouchableOpacity>- </DropdownMenu.Trigger>-- <DropdownMenu.Content>- <DropdownMenu.Item- key="new-link"- onSelect={() => SheetManager.show("add-link-sheet")}- >- <DropdownMenu.ItemTitle>New Link</DropdownMenu.ItemTitle>- </DropdownMenu.Item>- <DropdownMenu.Item- key="new-collection"- onSelect={() => alert("Item 2 selected")}- >- <DropdownMenu.ItemTitle>New Collection</DropdownMenu.ItemTitle>- </DropdownMenu.Item>- {/* <DropdownMenu.Item- key="upload-file"- onSelect={() => alert("Item 3 selected")}- >- <DropdownMenu.ItemTitle>Upload File</DropdownMenu.ItemTitle>- </DropdownMenu.Item> */}- </DropdownMenu.Content>- </DropdownMenu.Root>- ),- }}- />- );-}diff --git a/apps/mobile/app/(tabs)/_layout.tsx b/apps/mobile/app/(tabs)/_layout.tsxindex 6651824a..347be0ca 100644--- a/apps/mobile/app/(tabs)/_layout.tsx+++ b/apps/mobile/app/(tabs)/_layout.tsx@@ -1,4 +1,4 @@-import { Tabs, useRouter } from "expo-router";+import { Tabs } from "expo-router";import React from "react";import { Platform, TouchableOpacity, useColorScheme } from "react-native";import HapticTab from "@/components/HapticTab";@@ -8,7 +8,6 @@ import TabBarBackground from "@/components/ui/TabBarBackground";export default function TabLayout() {const colorScheme = useColorScheme();- const router = useRouter();return (<Tabs@@ -26,7 +25,7 @@ export default function TabLayout() {}}><Tabs.Screen- name="(dashboard)"+ name="dashboard"options={{title: "Dashboard",headerShown: false,@@ -39,13 +38,7 @@ export default function TabLayout() {name="links"options={{title: "Links",- headerSearchBarOptions: {- placeholder: "Search",- autoCapitalize: "none",- onChangeText: (e) => {- router.setParams({ search: e.nativeEvent.text });- },- },+ headerShown: false,tabBarIcon: ({ color }) => (<IconSymbol size={28} name="link" color={color} />),diff --git a/apps/mobile/app/(tabs)/dashboard/[section].tsx b/apps/mobile/app/(tabs)/dashboard/[section].tsxnew file mode 100644index 00000000..73d35584--- /dev/null+++ b/apps/mobile/app/(tabs)/dashboard/[section].tsx@@ -0,0 +1,81 @@+import { useLinks } from "@linkwarden/router/links";+import { View, StyleSheet, FlatList, Platform } from "react-native";+import useAuthStore from "@/store/auth";+import LinkListing from "@/components/LinkListing";+import { useLocalSearchParams, useNavigation } from "expo-router";+import React, { useEffect, useState } from "react";+import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";+import { useCollections } from "@linkwarden/router/collections";++const RenderItem = React.memo(+ ({ item }: { item: LinkIncludingShortenedCollectionAndTags }) => {+ return <LinkListing link={item} />;+ }+);++export default function LinksScreen() {+ const { auth } = useAuthStore();+ const { search, section, collectionId } = useLocalSearchParams<{+ search?: string;+ section?: "pinned-links" | "recent-links" | "collection";+ collectionId?: string;+ }>();++ const navigation = useNavigation();+ const collections = useCollections(auth);++ useEffect(() => {+ navigation.setOptions({+ headerTitle:+ section === "pinned-links"+ ? "Pinned Links"+ : section === "recent-links"+ ? "Recent Links"+ : section === "collection"+ ? collections.data?.find((c) => c.id?.toString() === collectionId)+ ?.name || "Collection"+ : "Links",+ });+ }, [section, navigation]);++ const { links, data } = useLinks(+ {+ sort: 0,+ searchQueryString: decodeURIComponent(search ?? ""),+ collectionId: Number(collectionId),+ pinnedOnly: section === "pinned-links",+ },+ auth+ );++ return (+ <View style={styles.container} className="h-full">+ <FlatList+ contentInsetAdjustmentBehavior="automatic"+ ListHeaderComponent={() => <></>}+ data={links || []}+ onRefresh={() => data.refetch()}+ refreshing={data.isRefetching}+ initialNumToRender={4}+ keyExtractor={(item) => item.id?.toString() || ""}+ renderItem={({ item }) => (+ <RenderItem item={item} key={item.id?.toString()} />+ )}+ onEndReached={() => data.fetchNextPage()}+ onEndReachedThreshold={0.5}+ ItemSeparatorComponent={() => (+ <View className="bg-[#eee] h-[1px] w-[100px]" />+ )}+ />+ </View>+ );+}++const styles = StyleSheet.create({+ container: Platform.select({+ ios: {+ paddingBottom: 83,+ },+ default: {},+ }),+});diff --git a/apps/mobile/app/(tabs)/dashboard/_layout.tsx b/apps/mobile/app/(tabs)/dashboard/_layout.tsxnew file mode 100644index 00000000..61b29f33--- /dev/null+++ b/apps/mobile/app/(tabs)/dashboard/_layout.tsx@@ -0,0 +1,80 @@+import { IconSymbol } from "@/components/ui/IconSymbol";+import { Stack, useRouter } from "expo-router";+import { TouchableOpacity } from "react-native";+import { SheetManager } from "react-native-actions-sheet";+import * as DropdownMenu from "zeego/dropdown-menu";++export default function RootLayout() {+ const router = useRouter();++ return (+ <Stack+ screenOptions={{+ headerLargeTitle: true,+ headerTransparent: true,+ headerBlurEffect: "systemUltraThinMaterial",+ }}+ >+ <Stack.Screen+ name="index"+ options={{+ headerTitle: "Dashboard",+ headerLargeStyle: {+ backgroundColor: "#f2f2f2",+ },+ headerRight: () => (+ <DropdownMenu.Root>+ <DropdownMenu.Trigger>+ <TouchableOpacity>+ <IconSymbol size={20} name="plus" color={"#3478f6"} />+ </TouchableOpacity>+ </DropdownMenu.Trigger>++ <DropdownMenu.Content>+ <DropdownMenu.Item+ key="new-link"+ onSelect={() => SheetManager.show("add-link-sheet")}+ >+ <DropdownMenu.ItemTitle>New Link</DropdownMenu.ItemTitle>+ </DropdownMenu.Item>+ <DropdownMenu.Item+ key="new-collection"+ onSelect={() => alert("Item 2 selected")}+ >+ <DropdownMenu.ItemTitle>+ New Collection+ </DropdownMenu.ItemTitle>+ </DropdownMenu.Item>+ {/* <DropdownMenu.Item+ key="upload-file"+ onSelect={() => alert("Item 3 selected")}+ >+ <DropdownMenu.ItemTitle>Upload File</DropdownMenu.ItemTitle>+ </DropdownMenu.Item> */}+ </DropdownMenu.Content>+ </DropdownMenu.Root>+ ),+ }}+ />+ <Stack.Screen+ name="[section]"+ options={{+ headerTitle: "Links",+ headerBackTitle: "Back",+ headerLargeStyle: {+ backgroundColor: "white",+ },+ headerSearchBarOptions: {+ placeholder: "Search",+ autoCapitalize: "none",+ onChangeText: (e) => {+ router.setParams({+ search: encodeURIComponent(e.nativeEvent.text),+ });+ },+ },+ }}+ />+ </Stack>+ );+}diff --git a/apps/mobile/app/(tabs)/(dashboard)/index.tsx b/apps/mobile/app/(tabs)/dashboard/index.tsxsimilarity index 95%rename from apps/mobile/app/(tabs)/(dashboard)/index.tsxrename to apps/mobile/app/(tabs)/dashboard/index.tsxindex 79fa9211..cd049587 100644--- a/apps/mobile/app/(tabs)/(dashboard)/index.tsx+++ b/apps/mobile/app/(tabs)/dashboard/index.tsx@@ -21,6 +21,7 @@ import clsx from "clsx";import DashboardItem from "@/components/DashboardItem";import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";import LinkListing from "@/components/LinkListing";+import { useRouter } from "expo-router";export default function DashboardScreen() {const { auth } = useAuthStore();@@ -130,6 +131,8 @@ const Section: React.FC<SectionProps> = ({dashboardData,collectionLinks = [],}) => {+ const router = useRouter();+switch (sectionData.type) {case DashboardSectionType.STATS:return (@@ -139,11 +142,13 @@ const Section: React.FC<SectionProps> = ({name={numberOfLinks === 1 ? "Link" : "Links"}value={numberOfLinks}icon="link.circle.fill"+ color="#9c00cc"/><DashboardItemname={collectionsLength === 1 ? "Collection" : "Collections"}value={collectionsLength}icon="folder.circle.fill"+ color="#0096cc"/></View><View className="flex-row gap-4">@@ -151,11 +156,13 @@ const Section: React.FC<SectionProps> = ({name={tagsLength === 1 ? "Tag" : "Tags"}value={tagsLength}icon="tag.circle.fill"+ color="#00cc99"/><DashboardItemname={"Pinned Links"}value={numberOfPinnedLinks}icon="pin.circle.fill"+ color="#cc6d00"/></View></View>@@ -173,7 +180,7 @@ const Section: React.FC<SectionProps> = ({</View><TouchableOpacityclassName="flex-row items-center text-sm gap-1"- // onPress={() => navigation.navigate('Links')}+ onPress={() => router.navigate("/(tabs)/dashboard/recent-links")}><Text className="text-[#3478f6]">View All</Text><IconSymbol size={15} name="chevron.right" color={"#3478f6"} />@@ -229,7 +236,7 @@ const Section: React.FC<SectionProps> = ({</View><TouchableOpacityclassName="flex-row items-center text-sm gap-1"- // onPress={() => navigation.navigate("PinnedLinks")}+ onPress={() => router.navigate("/(tabs)/dashboard/pinned-links")}><Text className="text-[#3478f6]">View All</Text><IconSymbol size={15} name="chevron.right" color={"#3478f6"} />@@ -283,9 +290,11 @@ const Section: React.FC<SectionProps> = ({</View><TouchableOpacityclassName="flex-row items-center text-sm gap-1 whitespace-nowrap"- // onPress={() =>- // navigation.navigate("Collection", { id: collection.id })- // }+ onPress={() =>+ router.navigate(+ `/(tabs)/dashboard/collection?collectionId=${collection.id}`+ )+ }><Text className="text-[#3478f6]">View All</Text><IconSymbol size={15} name="chevron.right" color={"#3478f6"} />diff --git a/apps/mobile/app/(tabs)/links/_layout.tsx b/apps/mobile/app/(tabs)/links/_layout.tsxnew file mode 100644index 00000000..efae05f5--- /dev/null+++ b/apps/mobile/app/(tabs)/links/_layout.tsx@@ -0,0 +1,28 @@+import { Stack, useRouter } from "expo-router";++export default function RootLayout() {+ const router = useRouter();++ return (+ <Stack+ screenOptions={{+ headerTitle: "Links",+ headerLargeTitle: true,+ headerTransparent: true,+ headerBlurEffect: "systemUltraThinMaterial",+ headerSearchBarOptions: {+ placeholder: "Search",+ autoCapitalize: "none",+ onChangeText: (e) => {+ router.setParams({+ search: encodeURIComponent(e.nativeEvent.text),+ });+ },+ },+ headerLargeStyle: {+ backgroundColor: "white",+ },+ }}+ />+ );+}diff --git a/apps/mobile/app/(tabs)/links.tsx b/apps/mobile/app/(tabs)/links/index.tsxsimilarity index 84%rename from apps/mobile/app/(tabs)/links.tsxrename to apps/mobile/app/(tabs)/links/index.tsxindex 67db8cf0..fe4bcd9a 100644--- a/apps/mobile/app/(tabs)/links.tsx+++ b/apps/mobile/app/(tabs)/links/index.tsx@@ -5,6 +5,7 @@ import LinkListing from "@/components/LinkListing";import { useLocalSearchParams } from "expo-router";import React from "react";import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";+import { useHeaderHeight } from "@react-navigation/elements";const RenderItem = React.memo(({ item }: { item: LinkIncludingShortenedCollectionAndTags }) => {@@ -15,18 +16,20 @@ const RenderItem = React.memo(export default function LinksScreen() {const { auth } = useAuthStore();const { search } = useLocalSearchParams<{ search?: string }>();+ const headerHeight = useHeaderHeight();const { links, data } = useLinks({sort: 0,- searchQueryString: search ?? search,+ searchQueryString: decodeURIComponent(search ?? ""),},auth);return (- <View style={styles.container}>+ <View style={styles.container} className="h-full"><FlatList+ contentInsetAdjustmentBehavior="automatic"ListHeaderComponent={() => <></>}data={links || []}onRefresh={() => data.refetch()}diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsxindex 6cf1324a..9fdebdf3 100644--- a/apps/mobile/app/index.tsx+++ b/apps/mobile/app/index.tsx@@ -10,7 +10,7 @@ export default function HomeScreen() {}, []);if (auth.session) {- return <Redirect href="/(tabs)/(dashboard)" />;+ return <Redirect href="/(tabs)/dashboard" />;} else {return <Redirect href="/login" />;}diff --git a/apps/mobile/components/DashboardItem.tsx b/apps/mobile/components/DashboardItem.tsxindex d81101d1..00297048 100644--- a/apps/mobile/components/DashboardItem.tsx+++ b/apps/mobile/components/DashboardItem.tsx@@ -6,16 +6,18 @@ export default function DashboardItem({name,value,icon,+ color,}: {name: string;value: number;icon: SFSymbols6_0;+ color: string;}) {return (<View className="flex-1 flex-col gap-2 rounded-xl bg-white p-3"><View className="flex-row justify-between"><View className="flex-col gap-2 items-start">- <IconSymbol name={icon} size={40} color={"#4169e1"} />+ <IconSymbol name={icon} size={40} color={color} /></View><TextclassName="text-4xl text-primary mt-0.5 text-right max-w-[75%]"diff --git a/apps/mobile/components/LinkListing.tsx b/apps/mobile/components/LinkListing.tsxindex 21ef6b1c..9c5aa1ed 100644--- a/apps/mobile/components/LinkListing.tsx+++ b/apps/mobile/components/LinkListing.tsx@@ -10,10 +10,11 @@ import {import useAuthStore from "@/store/auth";import { useRouter } from "expo-router";import * as ContextMenu from "zeego/context-menu";-import { useDeleteLink } from "@linkwarden/router/links";+import { useDeleteLink, useUpdateLink } from "@linkwarden/router/links";import { SheetManager } from "react-native-actions-sheet";import * as Clipboard from "expo-clipboard";import { cn } from "@linkwarden/lib/utils";+import { useUser } from "@linkwarden/router/user";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -23,6 +24,8 @@ type Props = {const LinkListing = ({ link, dashboard }: Props) => {const { auth } = useAuthStore();const router = useRouter();+ const updateLink = useUpdateLink(auth);+ const { data: user } = useUser(auth);const deleteLink = useDeleteLink(auth);@@ -37,11 +40,7 @@ const LinkListing = ({ link, dashboard }: Props) => {}return (- <ContextMenu.Root- onOpenChange={() => {- /* track open/close if needed */- }}- >+ <ContextMenu.Root><ContextMenu.Trigger asChild><PressableclassName={cn(@@ -133,6 +132,25 @@ const LinkListing = ({ link, dashboard }: Props) => {</ContextMenu.Item>)}+ <ContextMenu.Item+ key="pin-link"+ onSelect={async () => {+ const isAlreadyPinned =+ link?.pinnedBy && link.pinnedBy[0] ? true : false;++ await updateLink.mutateAsync({+ ...link,+ pinnedBy: (isAlreadyPinned+ ? [{ id: undefined }]+ : [{ id: user?.id }]) as any,+ });+ }}+ >+ <ContextMenu.ItemTitle>+ {link.pinnedBy && link.pinnedBy[0] ? "Unpin Link" : "Pin Link"}+ </ContextMenu.ItemTitle>+ </ContextMenu.Item>+<ContextMenu.Itemkey="edit-link"onSelect={() => {diff --git a/apps/mobile/store/auth.ts b/apps/mobile/store/auth.tsindex ddc22390..51a13563 100644--- a/apps/mobile/store/auth.ts+++ b/apps/mobile/store/auth.ts@@ -68,7 +68,7 @@ const useAuthStore = create<AuthStore>((set) => ({},});- router.replace("/(tabs)/(dashboard)");+ router.replace("/(tabs)/dashboard");} else {set({auth: {