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
|
import { Pressable, View } from "react-native";
import { useRouter } from "expo-router";
import CustomSafeAreaView from "@/components/ui/CustomSafeAreaView";
import { Divider } from "@/components/ui/Divider";
import { Text } from "@/components/ui/Text";
import { useToast } from "@/components/ui/Toast";
import useAppSettings from "@/lib/settings";
import { Check } from "lucide-react-native";
export default function BookmarkDefaultViewSettings() {
const router = useRouter();
const { toast } = useToast();
const { settings, setSettings } = useAppSettings();
const handleUpdate = async (mode: "reader" | "browser") => {
try {
await setSettings({
...settings,
defaultBookmarkView: mode,
});
toast({
message: "Default Bookmark View updated!",
showProgress: false,
});
router.back();
} catch {
toast({
message: "Something went wrong",
variant: "destructive",
showProgress: false,
});
}
};
const options = (["reader", "browser"] as const)
.map((mode) => {
const currentMode = settings.defaultBookmarkView;
const isChecked = currentMode === mode;
return [
<Pressable
onPress={() => handleUpdate(mode)}
className="flex flex-row justify-between"
key={mode}
>
<Text>{{ browser: "Browser", reader: "Reader" }[mode]}</Text>
{isChecked && <Check color="rgb(0, 122, 255)" />}
</Pressable>,
<Divider
key={mode + "-divider"}
orientation="horizontal"
className="my-3 h-0.5 w-full"
/>,
];
})
.flat();
options.pop();
return (
<CustomSafeAreaView>
<View className="flex h-full w-full items-center px-4 py-2">
<View className="w-full rounded-lg bg-card bg-card px-4 py-2">
{options}
</View>
</View>
</CustomSafeAreaView>
);
}
|