⚡️⚡️⚡️ 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): preserved formats basic viewing functionality
daniel31x13c6713f67f4c5
diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsxindex 8cc52137..708794a3 100644--- a/apps/mobile/app/_layout.tsx+++ b/apps/mobile/app/_layout.tsx@@ -15,7 +15,6 @@ export default function RootLayout() {<StackscreenOptions={{headerShown: false,- gestureEnabled: false,}}>{/* <Stack.Screen name="(tabs)" /> */}@@ -24,7 +23,6 @@ export default function RootLayout() {options={{headerBackTitle: "Back",headerShown: true,- gestureEnabled: true,headerTitle: "",}}/>diff --git a/apps/mobile/app/links/[id].tsx b/apps/mobile/app/links/[id].tsxindex b9fb3aad..44641c9a 100644--- a/apps/mobile/app/links/[id].tsx+++ b/apps/mobile/app/links/[id].tsx@@ -9,7 +9,7 @@ import { generateLinkHref } from "@linkwarden/lib/generateLinkHref";export default function HomeScreen() {const { auth } = useAuthStore();- const { id } = useLocalSearchParams();+ const { id, format } = useLocalSearchParams();const getLink = useGetLink(false, auth);const { data: user } = useUser(auth);const [url, setUrl] = useState<string>();@@ -19,8 +19,12 @@ export default function HomeScreen() {async function fetchLinkData() {const link = await getLink.mutateAsync({ id: Number(id) });- if (link) {+ if (link && !format) {setUrl(generateLinkHref(link, user[0], auth.instance, true));+ } else if (link && format) {+ setUrl(+ auth.instance + "/api/v1/archives/" + link.id + "?format=" + format+ );}}diff --git a/apps/mobile/components/LinkListing.tsx b/apps/mobile/components/LinkListing.tsxindex cea950eb..05396f92 100644--- a/apps/mobile/components/LinkListing.tsx+++ b/apps/mobile/components/LinkListing.tsx@@ -10,9 +10,13 @@ import { decode } from "html-entities";import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";import { IconSymbol } from "@/components/ui/IconSymbol";import { ArchivedFormat } from "@linkwarden/types";-import { formatAvailable } from "@linkwarden/lib/formatStats";+import {+ atLeastOneFormatAvailable,+ formatAvailable,+} from "@linkwarden/lib/formatStats";import useAuthStore from "@/store/auth";import { useRouter } from "expo-router";+import * as ContextMenu from "zeego/context-menu";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -33,147 +37,256 @@ const LinkListing = ({ link }: Props) => {}return (- <Pressable- onPress={() => router.push(`/links/${link.id}`)}- android_ripple={{ color: "#ddd", borderless: false }}- style={({ pressed }) => ({- backgroundColor: pressed- ? Platform.OS === "android"- ? "#fff"- : "#eee"- : "#fff",- })}+ <ContextMenu.Root+ onOpenChange={(open) => {+ /* if needed, track open/close */+ }}>- <View- style={{- padding: 20,- flexDirection: "row",- justifyContent: "space-between",- }}- >+ <ContextMenu.Trigger asChild><Viewstyle={{- width: "70%",- flexDirection: "column",+ padding: 20,+ flexDirection: "row",justifyContent: "space-between",+ backgroundColor: "#fff",}}>- <Text- style={{- fontWeight: "500",- fontSize: 18,- }}- numberOfLines={2}+ <Pressable+ onPress={() => router.push(`/links/${link.id}`)}+ android_ripple={{ color: "#ddd", borderless: false }}+ style={({ pressed }) => ({+ backgroundColor: pressed+ ? Platform.OS === "android"+ ? "#fff"+ : "#eee"+ : "#fff",+ })}>- {decode(link.name || link.description || link.url)}- </Text>-- {shortendURL && (- <Text+ <Viewstyle={{- marginTop: 5,- fontWeight: "300",- fontSize: 14,+ padding: 20,+ flexDirection: "row",+ justifyContent: "space-between",}}- numberOfLines={1}>- {shortendURL}- </Text>- )}-- <View- style={{- flexDirection: "row",- alignItems: "center",- gap: 5,- marginTop: 5,- // padding: 5,- paddingRight: 5,- alignSelf: "flex-start",- borderRadius: 5,- // backgroundColor: link.collection.color- // ? `${link.collection.color}33`- // : "#00000033",- }}- >- <IconSymbol- name="folder.fill"- size={16}- color={link.collection.color || ""}- />- <Text style={{ fontWeight: "300", fontSize: 12 }} numberOfLines={1}>- {link.collection.name}- </Text>- </View>- </View>-- <View- style={{- flexDirection: "column",- alignItems: "flex-end",- }}- >- <View- style={{- borderRadius: 7,- position: "relative",- overflow: "hidden",- }}- >- {formatAvailable(link, "preview") ? (- <Image- source={{- uri:- auth.instance +- `/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}&preview=true&updatedAt=${link.updatedAt}`,- headers: {- Authorization: `Bearer ${auth.session}`,- },- }}+ <Viewstyle={{- borderRadius: 5,- height: 60,- width: 90,- resizeMode: "cover",- transform: [{ scale: 1.05 }],+ width: "70%",+ flexDirection: "column",+ justifyContent: "space-between",}}- />- ) : (+ >+ <Text+ style={{+ fontWeight: "500",+ fontSize: 18,+ }}+ numberOfLines={2}+ >+ {decode(link.name || link.description || link.url)}+ </Text>++ {shortendURL && (+ <Text+ style={{+ marginTop: 5,+ fontWeight: "300",+ fontSize: 14,+ }}+ numberOfLines={1}+ >+ {shortendURL}+ </Text>+ )}++ <View+ style={{+ flexDirection: "row",+ alignItems: "center",+ gap: 5,+ marginTop: 5,+ // padding: 5,+ paddingRight: 5,+ alignSelf: "flex-start",+ borderRadius: 5,+ // backgroundColor: link.collection.color+ // ? `${link.collection.color}33`+ // : "#00000033",+ }}+ >+ <IconSymbol+ name="folder.fill"+ size={16}+ color={link.collection.color || ""}+ />+ <Text+ style={{ fontWeight: "300", fontSize: 12 }}+ numberOfLines={1}+ >+ {link.collection.name}+ </Text>+ </View>+ </View>+<Viewstyle={{- height: 60,- width: 90,+ flexDirection: "column",+ alignItems: "flex-end",}}- />- )}- </View>- <View- style={{- flexDirection: "row",- alignItems: "center",- gap: 5,- marginTop: 20,- alignSelf: "flex-start",- }}- >- <IconSymbol name="calendar" size={16} color={"gray"} />- <Text- style={{- fontWeight: "300",- fontSize: 12,- }}- numberOfLines={1}- >- {new Date(link.createdAt as string).toLocaleString("en-US", {- year: "numeric",- month: "short",- day: "numeric",- })}- </Text>- </View>+ >+ <View+ style={{+ borderRadius: 7,+ position: "relative",+ overflow: "hidden",+ }}+ >+ {formatAvailable(link, "preview") ? (+ <Image+ source={{+ uri:+ auth.instance ++ `/api/v1/archives/${link.id}?format=${ArchivedFormat.jpeg}&preview=true&updatedAt=${link.updatedAt}`,+ headers: {+ Authorization: `Bearer ${auth.session}`,+ },+ }}+ style={{+ borderRadius: 5,+ height: 60,+ width: 90,+ resizeMode: "cover",+ transform: [{ scale: 1.05 }],+ }}+ />+ ) : (+ <View+ style={{+ height: 60,+ width: 90,+ }}+ />+ )}+ </View>+ <View+ style={{+ flexDirection: "row",+ alignItems: "center",+ gap: 5,+ marginTop: 20,+ alignSelf: "flex-start",+ }}+ >+ <IconSymbol name="calendar" size={16} color={"gray"} />+ <Text+ style={{+ fontWeight: "300",+ fontSize: 12,+ }}+ numberOfLines={1}+ >+ {new Date(link.createdAt as string).toLocaleString(+ "en-US",+ {+ year: "numeric",+ month: "short",+ day: "numeric",+ }+ )}+ </Text>+ </View>+ </View>+ </View>+ </Pressable></View>- </View>- </Pressable>+ </ContextMenu.Trigger>++ <ContextMenu.Content avoidCollisions>+ <ContextMenu.Item+ key="open-link"+ onSelect={() => router.push(`/links/${link.id}`)}+ >+ <ContextMenu.ItemTitle>Open Link</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ {link.url && atLeastOneFormatAvailable(link) && (+ <ContextMenu.Sub>+ <ContextMenu.SubTrigger key="preserved-formats">+ <ContextMenu.ItemTitle>Preserved Formats</ContextMenu.ItemTitle>+ </ContextMenu.SubTrigger>+ <ContextMenu.SubContent>+ {formatAvailable(link, "monolith") && (+ <ContextMenu.Item+ key="preserved-formats-webpage"+ onSelect={() =>+ router.push(+ `/links/${link.id}?format=${ArchivedFormat.monolith}`+ )+ }+ >+ <ContextMenu.ItemTitle>Webpage</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ )}+ {formatAvailable(link, "image") && (+ <ContextMenu.Item+ key="preserved-formats-screenshot"+ onSelect={() =>+ router.push(+ `/links/${link.id}?format=${+ link.image?.endsWith(".png")+ ? ArchivedFormat.png+ : ArchivedFormat.jpeg+ }`+ )+ }+ >+ <ContextMenu.ItemTitle>Screenshot</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ )}+ {formatAvailable(link, "pdf") && (+ <ContextMenu.Item+ key="preserved-formats-pdf"+ onSelect={() =>+ router.push(+ `/links/${link.id}?format=${ArchivedFormat.pdf}`+ )+ }+ >+ <ContextMenu.ItemTitle>PDF</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ )}+ {formatAvailable(link, "readable") && (+ <ContextMenu.Item+ key="preserved-formats-readable"+ onSelect={() =>+ router.push(+ `/links/${link.id}?format=${ArchivedFormat.readability}`+ )+ }+ >+ <ContextMenu.ItemTitle>Readable</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ )}+ </ContextMenu.SubContent>+ </ContextMenu.Sub>+ )}+ <ContextMenu.Item+ key="copy-url"+ onSelect={() => {+ /* e.g. copy URL */+ }}+ >+ <ContextMenu.ItemTitle>Copy URL</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ <ContextMenu.Item+ key="delete-link"+ onSelect={() => {+ /* e.g. delete */+ }}+ >+ <ContextMenu.ItemTitle>Delete</ContextMenu.ItemTitle>+ </ContextMenu.Item>+ </ContextMenu.Content>+ </ContextMenu.Root>);};diff --git a/apps/mobile/store/auth.ts b/apps/mobile/store/auth.tsindex 4143b27e..fa03b7c5 100644--- a/apps/mobile/store/auth.ts+++ b/apps/mobile/store/auth.ts@@ -70,7 +70,7 @@ const useAuthStore = create<AuthStore>((set) => ({},});- router.push("/dashboard");+ router.replace("/dashboard");} else {set({auth: {@@ -92,7 +92,7 @@ const useAuthStore = create<AuthStore>((set) => ({},});- router.push("/login");+ router.replace("/login");},}));