1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
import { Alert, Linking, Pressable, View } from "react-native";
import { useRouter } from "expo-router";
import { TailwindResolver } from "@/components/TailwindResolver";
import { useToast } from "@/components/ui/Toast";
import { ClipboardList, Globe, Info, Tag, Trash2 } from "lucide-react-native";
import { useDeleteBookmark } from "@karakeep/shared-react/hooks/bookmarks";
import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks";
interface BottomActionsProps {
bookmark: ZBookmark;
}
export default function BottomActions({ bookmark }: BottomActionsProps) {
const { toast } = useToast();
const router = useRouter();
const { mutate: deleteBookmark, isPending: isDeletionPending } =
useDeleteBookmark({
onSuccess: () => {
router.back();
toast({
message: "The bookmark has been deleted!",
showProgress: false,
});
},
onError: () => {
toast({
message: "Something went wrong",
variant: "destructive",
showProgress: false,
});
},
});
const deleteBookmarkAlert = () =>
Alert.alert(
"Delete bookmark?",
"Are you sure you want to delete this bookmark?",
[
{ text: "Cancel", style: "cancel" },
{
text: "Delete",
onPress: () => deleteBookmark({ bookmarkId: bookmark.id }),
style: "destructive",
},
],
);
const actions = [
{
id: "lists",
icon: (
<TailwindResolver
className="text-foreground"
comp={(styles) => <ClipboardList color={styles?.color?.toString()} />}
/>
),
shouldRender: true,
onClick: () =>
router.push(`/dashboard/bookmarks/${bookmark.id}/manage_lists`),
disabled: false,
},
{
id: "tags",
icon: (
<TailwindResolver
className="text-foreground"
comp={(styles) => <Tag color={styles?.color?.toString()} />}
/>
),
shouldRender: true,
onClick: () =>
router.push(`/dashboard/bookmarks/${bookmark.id}/manage_tags`),
disabled: false,
},
{
id: "open",
icon: (
<TailwindResolver
className="text-foreground"
comp={(styles) => <Info color={styles?.color?.toString()} />}
/>
),
shouldRender: true,
onClick: () => router.push(`/dashboard/bookmarks/${bookmark.id}/info`),
disabled: false,
},
{
id: "delete",
icon: (
<TailwindResolver
className="text-foreground"
comp={(styles) => <Trash2 color={styles?.color?.toString()} />}
/>
),
shouldRender: true,
onClick: deleteBookmarkAlert,
disabled: isDeletionPending,
},
{
id: "browser",
icon: (
<TailwindResolver
className="text-foreground"
comp={(styles) => <Globe color={styles?.color?.toString()} />}
/>
),
shouldRender: bookmark.content.type == BookmarkTypes.LINK,
onClick: () =>
bookmark.content.type == BookmarkTypes.LINK &&
Linking.openURL(bookmark.content.url),
disabled: false,
},
];
return (
<View>
<View className="flex flex-row items-center justify-between px-10 pb-2 pt-4">
{actions.map(
(a) =>
a.shouldRender && (
<Pressable
disabled={a.disabled}
key={a.id}
onPress={a.onClick}
className="py-auto"
>
{a.icon}
</Pressable>
),
)}
</View>
</View>
);
}
|