aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-09-29 17:22:19 +0530
committerAkshay Nair <phenax5@gmail.com>2024-09-29 17:30:46 +0530
commit0b3257997a97088e22c9b6881c20a4807422ec05 (patch)
tree466bcec99a412e7c8fed6e93fe6bcdfc0cd9edcb
parentf67b2c039f8b60780e8f20bde9146bbe72613b9f (diff)
downloaddaft-launcher-0b3257997a97088e22c9b6881c20a4807422ec05.tar.gz
daft-launcher-0b3257997a97088e22c9b6881c20a4807422ec05.zip
Open alarm when clock is pressed1.0.0
-rw-r--r--README.md10
-rw-r--r--src/components/Clock.tsx17
-rw-r--r--src/hooks/useFavorites.ts7
3 files changed, 24 insertions, 10 deletions
diff --git a/README.md b/README.md
index c54bfd2..5599eb2 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
# Owyn launcher
-Owyn (_Only What You Need_) launcher is a minimal launcher for android
+Owyn (_Only What You Need_) launcher is a minimal launcher for android.
## What I need from my launcher...
-* A clock
-* A searchable list of apps
-* Quick access to favorite apps
-* Ability to uninstall apps
+- A clock
+- A searchable list of apps
+- Quick access to favorite apps
+- Ability to uninstall apps
## Screenshots
diff --git a/src/components/Clock.tsx b/src/components/Clock.tsx
index f41a298..cbf1857 100644
--- a/src/components/Clock.tsx
+++ b/src/components/Clock.tsx
@@ -1,5 +1,8 @@
import React, {useEffect, useMemo, useState} from 'react';
-import {Text, View} from 'react-native';
+import {Pressable, Text, View} from 'react-native';
+// @ts-expect-error No declaration file
+import IntentLauncher from '@angelkrak/react-native-intent-launcher';
+import {useStableCallback} from '../hooks/useStableCallback';
export const Clock: React.FC = React.memo(() => {
const [date, setDate] = useState(() => new Date());
@@ -28,10 +31,18 @@ export const Clock: React.FC = React.memo(() => {
return formatter.format(date);
}, [date]);
+ const showAlarms = useStableCallback(() =>
+ IntentLauncher.startActivity({
+ action: 'android.intent.action.SHOW_ALARMS',
+ }),
+ );
+
return (
<View className="p-6">
- <Text className="text-4xl font-bold">{timeText}</Text>
- <Text className="text-lg">{dateText}</Text>
+ <Pressable onPress={showAlarms} className="self-start">
+ <Text className="text-4xl font-bold">{timeText}</Text>
+ <Text className="text-lg">{dateText}</Text>
+ </Pressable>
</View>
);
});
diff --git a/src/hooks/useFavorites.ts b/src/hooks/useFavorites.ts
index fa96211..625ac08 100644
--- a/src/hooks/useFavorites.ts
+++ b/src/hooks/useFavorites.ts
@@ -10,7 +10,10 @@ const favoriteAppNamesAtom = atomWithStorage<string[]>(
jsonStorage,
);
-const serialize = (packageNames: string[]) => packageNames.join(',');
+const isSameArray = (a: string[], b: string[]): boolean => {
+ if (a.length !== b.length) return false;
+ return a.every((item, index) => item === b[index]);
+};
export const useFavorites = () => {
const [favoriteAppNames, setFavoriteAppNames] = useAtom(favoriteAppNamesAtom);
@@ -20,7 +23,7 @@ export const useFavorites = () => {
updater: (packageNames: string[]) => Promise<string[]> | string[],
) => {
const newNames = [...new Set(await updater(favoriteAppNames))];
- if (serialize(newNames) === serialize(favoriteAppNames)) return newNames;
+ if (isSameArray(newNames, favoriteAppNames)) return newNames;
setFavoriteAppNames(newNames);
return newNames;