⚡️⚡️⚡️ 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): add link functionality + delete link functionality
daniel31x138555d26d99c0
diff --git a/apps/mobile/app/(tabs)/dashboard.tsx b/apps/mobile/app/(tabs)/dashboard.tsxindex e7da1522..f7f1057b 100644--- a/apps/mobile/app/(tabs)/dashboard.tsx+++ b/apps/mobile/app/(tabs)/dashboard.tsx@@ -1,13 +1,20 @@-import { Text, StyleSheet, TouchableOpacity } from "react-native";+import { Text, TouchableOpacity, View } from "react-native";import { IconSymbol } from "@/components/ui/IconSymbol";import * as DropdownMenu from "zeego/dropdown-menu";import { SafeAreaView } from "react-native-safe-area-context";-import { useState } from "react";+import { useRef, useState } from "react";// import AddLink from "@/components/Modals/AddLink";-import ModalBase from "@/components/ModalBase";+import ActionSheet, { ActionSheetRef } from "react-native-actions-sheet";+import Input from "@/components/ui/Input";+import { Button } from "@/components/ui/Button";+import { useAddLink } from "@linkwarden/router/links";+import useAuthStore from "@/store/auth";export default function DashboardScreen() {- const [modalOpen, setModalOpen] = useState(false);+ const actionSheetRef = useRef<ActionSheetRef>(null);+ const { auth } = useAuthStore();+ const addLink = useAddLink(auth);+ const [link, setLink] = useState("");return (<SafeAreaView className="flex-1 justify-center items-center">@@ -19,7 +26,10 @@ export default function DashboardScreen() {</DropdownMenu.Trigger><DropdownMenu.Content>- <DropdownMenu.Item key="new-link" onSelect={() => setModalOpen(true)}>+ <DropdownMenu.Item+ key="new-link"+ onSelect={() => actionSheetRef.current?.show()}+ ><DropdownMenu.ItemTitle>New Link</DropdownMenu.ItemTitle></DropdownMenu.Item><DropdownMenu.Item@@ -40,14 +50,48 @@ export default function DashboardScreen() {{/* <TouchableOpacity><IconSymbol size={20} name="plus" color={""} /></TouchableOpacity> */}- <ModalBase- isVisible={modalOpen}- onClose={() => {- setModalOpen(false);- }}- >- <Text>Hi</Text>- </ModalBase>+ <ActionSheet ref={actionSheetRef} gestureEnabled>+ <View className="px-8 py-5">+ <Input+ placeholder="e.g. https://example.com"+ className="mb-4"+ value={link}+ onChangeText={setLink}+ />++ <Button+ onPress={() =>+ addLink.mutate(+ { url: link },+ {+ onSuccess: () => {+ actionSheetRef.current?.hide();+ setLink("");+ },+ onError: (error) => {+ console.error("Error adding link:", error);+ },+ }+ )+ }+ variant="accent"+ className="mb-2"+ >+ Save to Linkwarden+ </Button>++ <Button+ onPress={() => {+ actionSheetRef.current?.hide();+ setLink("");+ }}+ variant="outline"+ className="mb-2"+ >+ Cancel+ </Button>+ </View>+ </ActionSheet>{/* <AddLink isVisible={modalOpen} onClose={() => setModalOpen(false)} /> */}</SafeAreaView>);diff --git a/apps/mobile/app/(tabs)/links.tsx b/apps/mobile/app/(tabs)/links.tsxindex 9df6f1ca..67db8cf0 100644--- a/apps/mobile/app/(tabs)/links.tsx+++ b/apps/mobile/app/(tabs)/links.tsx@@ -39,12 +39,7 @@ export default function LinksScreen() {onEndReached={() => data.fetchNextPage()}onEndReachedThreshold={0.5}ItemSeparatorComponent={() => (- <View- style={{- height: 1,- backgroundColor: "#eee",- }}- />+ <View className="bg-[#eee] h-[1px] w-[100px]" />)}/></View>diff --git a/apps/mobile/app/index.tsx b/apps/mobile/app/index.tsxindex 7613f885..156b36ef 100644--- a/apps/mobile/app/index.tsx+++ b/apps/mobile/app/index.tsx@@ -1,7 +1,6 @@import useAuthStore from "@/store/auth";-import { Redirect, router } from "expo-router";+import { Redirect } from "expo-router";import { useEffect } from "react";-import { View, Text, StyleSheet, Button } from "react-native";export default function HomeScreen() {const { setAuth, auth } = useAuthStore();@@ -16,11 +15,3 @@ export default function HomeScreen() {return <Redirect href="/login" />;}}--const styles = StyleSheet.create({- container: {- flex: 1,- justifyContent: "center",- alignItems: "center",- },-});diff --git a/apps/mobile/app/login.tsx b/apps/mobile/app/login.tsxindex c3da7955..602cf016 100644--- a/apps/mobile/app/login.tsx+++ b/apps/mobile/app/login.tsx@@ -1,13 +1,8 @@+import { Button } from "@/components/ui/Button";+import Input from "@/components/ui/Input";import useAuthStore from "@/store/auth";-import { Link } from "expo-router";import { useState } from "react";-import {- View,- Text,- StyleSheet,- TextInput,- TouchableOpacity,-} from "react-native";+import { View, Text, StyleSheet, TouchableOpacity } from "react-native";export default function HomeScreen() {const { signIn } = useAuthStore();@@ -28,39 +23,21 @@ export default function HomeScreen() {gap: 10,}}>- <TextInput- style={{- height: 40,- width: 250,- borderRadius: 5,- padding: 10,- borderColor: "gray",- borderWidth: 1,- }}+ <Input+ className="w-72"placeholder="Username"value={form.user}onChangeText={(text) => setForm({ ...form, user: text })}/>- <TextInput- style={{- height: 40,- width: 250,- borderRadius: 5,- padding: 10,- borderColor: "gray",- borderWidth: 1,- }}+ <Input+ className="w-72"placeholder="Password"secureTextEntryvalue={form.password}onChangeText={(text) => setForm({ ...form, password: text })}/>- <TouchableOpacity- style={{- backgroundColor: "#000000",- padding: 10,- borderRadius: 5,- }}+ <Button+ variant="accent"onPress={() =>signIn(form.user,@@ -69,8 +46,8 @@ export default function HomeScreen() {)}>- <Text style={{ color: "#fff", textAlign: "center" }}>Login</Text>- </TouchableOpacity>+ Login+ </Button></View></View>);@@ -81,5 +58,6 @@ const styles = StyleSheet.create({flex: 1,justifyContent: "center",alignItems: "center",+ backgroundColor: "#ffffff",},});diff --git a/apps/mobile/components/LinkListing.tsx b/apps/mobile/components/LinkListing.tsxindex 3e9f2d30..6072a0c9 100644--- a/apps/mobile/components/LinkListing.tsx+++ b/apps/mobile/components/LinkListing.tsx@@ -1,4 +1,4 @@-import { View, Text, Image, Pressable, Platform } from "react-native";+import { View, Text, Image, Pressable, Platform, Alert } from "react-native";import { decode } from "html-entities";import { LinkIncludingShortenedCollectionAndTags } from "@linkwarden/types";import { IconSymbol } from "@/components/ui/IconSymbol";@@ -10,6 +10,7 @@ import {import useAuthStore from "@/store/auth";import { useRouter } from "expo-router";import * as ContextMenu from "zeego/context-menu";+import { useDeleteLink } from "@linkwarden/router/links";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -19,6 +20,8 @@ const LinkListing = ({ link }: Props) => {const { auth } = useAuthStore();const router = useRouter();+ const deleteLink = useDeleteLink(auth);+let shortendURL;try {@@ -43,7 +46,7 @@ const LinkListing = ({ link }: Props) => {onPress={() => router.push(`/links/${link.id}`)}android_ripple={{ color: "#ddd", borderless: false }}>- <View className="flex-row justify-between">+ <View className="flex-row justify-between w-full"><View className="w-[70%] flex-col justify-between"><Text numberOfLines={2} className="font-medium text-lg">{decode(link.name || link.description || link.url)}@@ -179,7 +182,23 @@ const LinkListing = ({ link }: Props) => {<ContextMenu.Itemkey="delete-link"onSelect={() => {- /* delete link */+ return Alert.alert(+ "Delete Link",+ "Are you sure you want to delete this link? This action cannot be undone.",+ [+ {+ text: "Cancel",+ style: "cancel",+ },+ {+ text: "Delete",+ style: "destructive",+ onPress: () => {+ deleteLink.mutate(link.id as number);+ },+ },+ ]+ );}}><ContextMenu.ItemTitle>Delete</ContextMenu.ItemTitle>diff --git a/apps/mobile/components/ModalBase.tsx b/apps/mobile/components/ModalBase.tsxdeleted file mode 100644index 541c842e..00000000--- a/apps/mobile/components/ModalBase.tsx+++ /dev/null@@ -1,32 +0,0 @@-import { Modal, View, Text, TouchableOpacity, Platform } from "react-native";-import { PropsWithChildren } from "react";-import { IconSymbol } from "./ui/IconSymbol";--type Props = PropsWithChildren<{- isVisible: boolean;- onClose: () => void;- children?: React.ReactNode;-}>;--export default function ModalBase({ isVisible, children, onClose }: Props) {- return (- <Modal- animationType="slide"- visible={isVisible}- onRequestClose={onClose}- transparent={false}- presentationStyle={Platform.OS === "ios" ? "formSheet" : "overFullScreen"}- >- <TouchableOpacity onPress={onClose} className="absolute top-5 right-5">- <IconSymbol name="xmark" size={16} color="" />- </TouchableOpacity>- {/* Overlay */}- <View className="flex-1 justify-center items-center">- {/* Modal content */}- <View className="bg-white rounded-2xl p-8 mx-5 items-center shadow-lg w-full">- {children}- </View>- </View>- </Modal>- );-}diff --git a/apps/mobile/components/ui/Button.tsx b/apps/mobile/components/ui/Button.tsxnew file mode 100644index 00000000..fb5e52c1--- /dev/null+++ b/apps/mobile/components/ui/Button.tsx@@ -0,0 +1,109 @@+import React, { forwardRef } from "react";+import {+ TouchableOpacity,+ Text,+ View,+ ActivityIndicator,+ type TouchableOpacityProps,+} from "react-native";+import { cva, type VariantProps } from "class-variance-authority";+import { cn } from "@linkwarden/lib/utils";++const buttonVariants = cva(+ "inline-flex items-center justify-center gap-2 rounded-lg disabled:opacity-50 disabled:pointer-events-none",+ {+ variants: {+ variant: {+ default: "bg-slate-500",+ primary: "bg-primary text-primary-foreground",+ accent: "bg-violet-600 border border-violet-400",+ destructive: "bg-destructive",+ outline: "border",+ secondary: "bg-secondary text-secondary-foreground",+ metal: "bg-neutral-content text-base-content border border-neutral/30",+ ghost: "",+ simple: "bg-base-200",+ link: "text-primary underline-offset-",+ },+ size: {+ default: "h-10 px-4 py-2",+ sm: "h-8 px-2 py-1 text-xs",+ lg: "h-11 px-8",+ full: "w-full px-4 py-2",+ icon: "h-8 w-8",+ },+ },+ defaultVariants: {+ variant: "default",+ size: "default",+ },+ }+);++export type ButtonProps = TouchableOpacityProps &+ VariantProps<typeof buttonVariants> & {+ /**+ * Render this instead of children when loading.+ * Disables the button while true.+ */+ isLoading?: boolean;+ /** Optional icon element, placed before the text */+ icon?: React.ReactNode;+ /** Contents of the button */+ children: React.ReactNode;+ /** Merge additional Tailwind classes */+ className?: string;+ };++export const Button = forwardRef<+ React.ElementRef<typeof TouchableOpacity>,+ ButtonProps+>(+ (+ {+ variant = "default",+ size,+ className,+ isLoading = false,+ icon,+ children,+ disabled,+ ...props+ },+ ref+ ) => {+ const combinedClasses = cn(buttonVariants({ variant, size }), className);++ return (+ <TouchableOpacity+ ref={ref}+ className={combinedClasses}+ activeOpacity={0.8}+ disabled={disabled || isLoading}+ {...props}+ >+ {isLoading ? (+ <ActivityIndicator />+ ) : (+ <View className="flex-row items-center">+ {icon && <View className="mr-2">{icon}</View>}+ <Text+ className={cn(+ "text-sm font-medium",+ variant === "default" ||+ variant === "accent" ||+ variant === "destructive"+ ? "text-white"+ : "text-black"+ )}+ >+ {children}+ </Text>+ </View>+ )}+ </TouchableOpacity>+ );+ }+);++Button.displayName = "Button";diff --git a/apps/mobile/components/ui/Input.tsx b/apps/mobile/components/ui/Input.tsxnew file mode 100644index 00000000..e020fa74--- /dev/null+++ b/apps/mobile/components/ui/Input.tsx@@ -0,0 +1,17 @@+import React, { forwardRef } from "react";+import { TextInput, TextInputProps } from "react-native";+import { cn } from "@linkwarden/lib/utils";++const Input = forwardRef<TextInput, TextInputProps>(+ ({ className, ...props }, ref) => {+ return (+ <TextInput+ ref={ref}+ className={cn("bg-gray-100 rounded-lg px-4 py-2", className)}+ {...props}+ />+ );+ }+);++export default Input;diff --git a/apps/mobile/package.json b/apps/mobile/package.jsonindex 61e22e85..affd799b 100644--- a/apps/mobile/package.json+++ b/apps/mobile/package.json@@ -45,7 +45,9 @@"nativewind": "^4.1.23","react": "18.3.1","react-dom": "18.3.1",+ "class-variance-authority": "^0.7.1","react-native": "0.76.9",+ "react-native-actions-sheet": "^0.9.7","react-native-gesture-handler": "~2.20.2","react-native-ios-context-menu": "3.1.0","react-native-ios-utilities": "5.1.2",diff --git a/packages/lib/package.json b/packages/lib/package.jsonindex a685ba6a..9cb40bde 100644--- a/packages/lib/package.json+++ b/packages/lib/package.json@@ -9,6 +9,8 @@"@linkwarden/filesystem": "*","jimp": "^0.22.10","meilisearch": "^0.48.2",- "rss-parser": "^3.13.0"+ "rss-parser": "^3.13.0",+ "clsx": "^2.1.1",+ "tailwind-merge": "^3.3.0"}}diff --git a/packages/lib/utils.ts b/packages/lib/utils.tsindex 6fc2f738..cba641b2 100644--- a/packages/lib/utils.ts+++ b/packages/lib/utils.ts@@ -1,3 +1,6 @@+import { clsx, type ClassValue } from "clsx";+import { twMerge } from "tailwind-merge";+export function titleCase(str: string) {var splitStr = str.toLowerCase().split(" ");for (var i = 0; i < splitStr.length; i++) {@@ -10,3 +13,7 @@ export function titleCase(str: string) {export function delay(sec: number) {return new Promise((resolve) => setTimeout(resolve, sec * 1000));}++export function cn(...inputs: ClassValue[]) {+ return twMerge(clsx(inputs));+}diff --git a/packages/router/links.tsx b/packages/router/links.tsxindex 68f0ac26..502c650c 100644--- a/packages/router/links.tsx+++ b/packages/router/links.tsx@@ -105,7 +105,7 @@ const buildQueryString = (params: LinkRequestQuery) => {.join("&");};-const useAddLink = () => {+const useAddLink = (auth?: MobileAuth) => {const queryClient = useQueryClient();return useMutation({@@ -118,13 +118,19 @@ const useAddLink = () => {}}- const response = await fetch("/api/v1/links", {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify(link),- });+ const response = await fetch(+ (auth?.instance ? auth?.instance : "") + "/api/v1/links",+ {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ ...(auth?.session+ ? { Authorization: `Bearer ${auth.session}` }+ : {}),+ },+ body: JSON.stringify(link),+ }+ );const data = await response.json();@@ -192,14 +198,22 @@ const useUpdateLink = () => {});};-const useDeleteLink = () => {+const useDeleteLink = (auth?: MobileAuth) => {const queryClient = useQueryClient();return useMutation({mutationFn: async (id: number) => {- const response = await fetch(`/api/v1/links/${id}`, {- method: "DELETE",- });+ const response = await fetch(+ (auth?.instance ? auth?.instance : "") + `/api/v1/links/${id}`,+ {+ method: "DELETE",+ headers: {+ ...(auth?.session+ ? { Authorization: `Bearer ${auth.session}` }+ : {}),+ },+ }+ );const data = await response.json();diff --git a/yarn.lock b/yarn.lockindex 577db147..4a5d1bb1 100644--- a/yarn.lock+++ b/yarn.lock@@ -11252,6 +11252,11 @@ react-masonry-css@^1.0.16:resolved "https://registry.yarnpkg.com/react-masonry-css/-/react-masonry-css-1.0.16.tgz#72b28b4ae3484e250534700860597553a10f1a2c"integrity sha512-KSW0hR2VQmltt/qAa3eXOctQDyOu7+ZBevtKgpNDSzT7k5LA/0XntNa9z9HKCdz3QlxmJHglTZ18e4sX4V8zZQ==+react-native-actions-sheet@^0.9.7:+ version "0.9.7"+ resolved "https://registry.yarnpkg.com/react-native-actions-sheet/-/react-native-actions-sheet-0.9.7.tgz#43ff2d9252f7af2da6dc051be5a5c375a844cdfb"+ integrity sha512-rjUwxUr5dxbdSLDtLDUFAdSlFxpNSpJsbXLhHkBzEBMxEMPUhRT3zqbvKqsPj0JUkjwuRligxrhbIJZkg/6ZDw==+version "0.1.22"resolved "https://registry.yarnpkg.com/react-native-css-interop/-/react-native-css-interop-0.1.22.tgz#70cc6ca7a8f14126e123e44a19ceed74dd2a167a"