Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

add LinkListing component

daniel31x132e131403d467
diff --git a/apps/mobile/app/(tabs)/links.tsx b/apps/mobile/app/(tabs)/links.tsx
index a267e5af..2f7fac1b 100644
--- a/apps/mobile/app/(tabs)/links.tsx
+++ b/apps/mobile/app/(tabs)/links.tsx
@@ -1,7 +1,14 @@
import { useLinks } from "@linkwarden/router/links";
-import { View, Text, StyleSheet, VirtualizedList } from "react-native";
+import {
+ View,
+ StyleSheet,
+ VirtualizedList,
+ Text,
+ ActivityIndicator,
+} from "react-native";
import { Platform } from "react-native";
import useAuthStore from "@/store/auth";
+import LinkListing from "@/components/LinkListing";
export default function HomeScreen() {
const { auth } = useAuthStore();
@@ -17,31 +24,31 @@ export default function HomeScreen() {
const getItemCount = (data: any) => data.length;
return (
- <VirtualizedList
- data={links || []}
- initialNumToRender={4}
- keyExtractor={(item) => item.id.toString()}
- renderItem={({ item }) => (
- <View
- style={{
- padding: 20,
- }}
- >
- <Text
+ <View>
+ <VirtualizedList
+ data={links || []}
+ initialNumToRender={4}
+ keyExtractor={(item) => item.id.toString()}
+ renderItem={({ item }) => (
+ <LinkListing link={item} key={item.id.toString()} />
+ )}
+ getItem={getItem}
+ getItemCount={getItemCount}
+ onEndReached={() => data.fetchNextPage()}
+ onEndReachedThreshold={0.5}
+ ItemSeparatorComponent={() => (
+ <View
style={{
- fontWeight: "bold",
- fontSize: 18,
+ height: 1,
+ backgroundColor: "#CED0CE",
+ marginHorizontal: 20,
}}
- >
- {item.name || item.description || item.url}
- </Text>
- <Text>{item.url}</Text>
- </View>
- )}
- getItem={getItem}
- getItemCount={getItemCount}
- contentContainerStyle={styles.container}
- />
+ />
+ )}
+ contentContainerStyle={styles.container}
+ />
+ <ActivityIndicator size="large" color="gray" />
+ </View>
);
}
diff --git a/apps/mobile/components/LinkListing.tsx b/apps/mobile/components/LinkListing.tsx
new file mode 100644
index 00000000..a6985037
--- /dev/null
+++ b/apps/mobile/components/LinkListing.tsx
@@ -0,0 +1,160 @@
+import { View, Text, Image } from "react-native";
+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 useAuthStore from "@/store/auth";
+
+type Props = {
+ link: LinkIncludingShortenedCollectionAndTags;
+};
+
+const LinkListing = ({ link }: Props) => {
+ const { auth } = useAuthStore();
+
+ let shortendURL;
+
+ try {
+ if (link.url) {
+ shortendURL = new URL(link.url).host.toLowerCase();
+ }
+ } catch (error) {
+ console.log(error);
+ }
+
+ return (
+ <View
+ style={{
+ padding: 20,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ }}
+ >
+ <View
+ style={{
+ 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,
+ }}
+ >
+ {shortendURL}
+ </Text>
+ )}
+
+ <View
+ style={{
+ flexDirection: "row",
+ alignItems: "center",
+ gap: 5,
+ marginTop: 5,
+ padding: 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}`,
+ },
+ }}
+ 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>
+ );
+};
+
+export default LinkListing;
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index 21d45404..9563ca81 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -15,9 +15,9 @@
"preset": "jest-expo"
},
"dependencies": {
- "@linkwarden/router": "*",
- "@linkwarden/lib": "*",
"@expo/vector-icons": "^14.0.2",
+ "@linkwarden/lib": "*",
+ "@linkwarden/router": "*",
"@react-native-menu/menu": "1.2.2",
"@react-navigation/bottom-tabs": "^7.0.0",
"@react-navigation/native": "^7.0.0",
@@ -36,6 +36,7 @@
"expo-symbols": "~0.2.0",
"expo-system-ui": "~4.0.6",
"expo-web-browser": "~14.0.1",
+ "html-entities": "^2.6.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-native": "0.76.5",
diff --git a/apps/web/components/LinkDetails.tsx b/apps/web/components/LinkDetails.tsx
index 84a85e48..1ac37e3e 100644
--- a/apps/web/components/LinkDetails.tsx
+++ b/apps/web/components/LinkDetails.tsx
@@ -7,7 +7,7 @@ import Link from "next/link";
import {
atLeastOneFormatAvailable,
formatAvailable,
-} from "@/lib/shared/formatStats";
+} from "@linkwarden/lib/formatStats";
import PreservedFormatRow from "@/components/PreserverdFormatRow";
import getPublicUserData from "@/lib/client/getPublicUserData";
import { useTranslation } from "next-i18next";
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
index 91ac3233..f74e9e4e 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkCard.tsx
@@ -13,7 +13,7 @@ import Image from "next/image";
import {
atLeastOneFormatAvailable,
formatAvailable,
-} from "@/lib/shared/formatStats";
+} from "@linkwarden/lib/formatStats";
import LinkIcon from "./LinkIcon";
import useOnScreen from "@/hooks/useOnScreen";
import usePermissions from "@/hooks/usePermissions";
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkFormats.tsx b/apps/web/components/LinkViews/LinkComponents/LinkFormats.tsx
index dee8d88f..505de8a2 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkFormats.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkFormats.tsx
@@ -1,4 +1,4 @@
-import { formatAvailable } from "@/lib/shared/formatStats";
+import { formatAvailable } from "@linkwarden/lib/formatStats";
import {
ArchivedFormat,
LinkIncludingShortenedCollectionAndTags,
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
index 6aff4ff2..f66d0238 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkList.tsx
@@ -20,7 +20,7 @@ import { useLinks } from "@linkwarden/router/links";
import useLocalSettingsStore from "@/store/localSettings";
import LinkPin from "./LinkPin";
import { useRouter } from "next/router";
-import { atLeastOneFormatAvailable } from "@/lib/shared/formatStats";
+import { atLeastOneFormatAvailable } from "@linkwarden/lib/formatStats";
import LinkFormats from "./LinkFormats";
import openLink from "@/lib/client/openLink";
diff --git a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
index d7dc35f0..bf9eec93 100644
--- a/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
+++ b/apps/web/components/LinkViews/LinkComponents/LinkMasonry.tsx
@@ -13,7 +13,7 @@ import Image from "next/image";
import {
atLeastOneFormatAvailable,
formatAvailable,
-} from "@/lib/shared/formatStats";
+} from "@linkwarden/lib/formatStats";
import Link from "next/link";
import LinkIcon from "./LinkIcon";
import useOnScreen from "@/hooks/useOnScreen";
diff --git a/apps/web/components/Preservation/PreservationContent.tsx b/apps/web/components/Preservation/PreservationContent.tsx
index 849edf41..f6bec126 100644
--- a/apps/web/components/Preservation/PreservationContent.tsx
+++ b/apps/web/components/Preservation/PreservationContent.tsx
@@ -13,7 +13,7 @@ import {
import {
atLeastOneFormatAvailable,
formatAvailable,
-} from "@/lib/shared/formatStats";
+} from "@linkwarden/lib/formatStats";
type Props = {
link?: LinkIncludingShortenedCollectionAndTags;
diff --git a/apps/web/lib/client/generateLinkHref.ts b/apps/web/lib/client/generateLinkHref.ts
index 34c32848..b737d25b 100644
--- a/apps/web/lib/client/generateLinkHref.ts
+++ b/apps/web/lib/client/generateLinkHref.ts
@@ -4,7 +4,7 @@ import {
LinkIncludingShortenedCollectionAndTags,
} from "@linkwarden/types";
import { LinksRouteTo } from "@linkwarden/prisma/client";
-import { formatAvailable } from "../shared/formatStats";
+import { formatAvailable } from "@linkwarden/lib/formatStats";
export const generateLinkHref = (
link: LinkIncludingShortenedCollectionAndTags,
diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json
index f4ab65fd..a53d36e8 100644
--- a/apps/web/tsconfig.json
+++ b/apps/web/tsconfig.json
@@ -19,6 +19,11 @@
"@/*": ["./*"]
}
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ "../../packages/lib/formatStats.ts"
+ ],
"exclude": ["node_modules"]
}
diff --git a/apps/web/lib/shared/formatStats.ts b/packages/lib/formatStats.ts
similarity index 100%
rename from apps/web/lib/shared/formatStats.ts
rename to packages/lib/formatStats.ts
diff --git a/yarn.lock b/yarn.lock
index 0cf77b44..f6a677e6 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7759,6 +7759,11 @@ html-encoding-sniffer@^3.0.0:
dependencies:
whatwg-encoding "^2.0.0"
+html-entities@^2.6.0:
+ version "2.6.0"
+ resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.6.0.tgz#7c64f1ea3b36818ccae3d3fb48b6974208e984f8"
+ integrity sha512-kig+rMn/QOVRvr7c86gQ8lWXq+Hkv6CbAH1hLu+RG338StTpE8Z0b44SDVaqVu7HGKf27frdmUYEs9hTUX/cLQ==
+
html-escaper@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453"