Skip to content

Commit 0938427

Browse files
committed
Added notification feature
1 parent 6e9396b commit 0938427

16 files changed

Lines changed: 394 additions & 152 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ yarn-error.*
4141
*.tsbuildinfo
4242

4343
app-example
44+
google-services.json
4445

app.config.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { ConfigContext, ExpoConfig } from "@expo/config";
2+
3+
export default ({ config }: ConfigContext): ExpoConfig => ({
4+
...config,
5+
"name": "HackNet",
6+
"slug": "HackNet",
7+
"version": "1.0.0",
8+
"orientation": "portrait",
9+
"icon": "./assets/images/icon.png",
10+
"scheme": "hacknet",
11+
"userInterfaceStyle": "automatic",
12+
"newArchEnabled": true,
13+
"ios": {
14+
"supportsTablet": true,
15+
"bundleIdentifier": "com.shibamroy.hacknet"
16+
},
17+
"android": {
18+
"adaptiveIcon": {
19+
"foregroundImage": "./assets/images/adaptive-icon/foreground.png",
20+
"backgroundColor": "#17171d"
21+
},
22+
"edgeToEdgeEnabled": true,
23+
"googleServicesFile": process.env.GOOGLE_SERVICES_JSON ?? "./google-services.json",
24+
"permissions": [
25+
"android.permission.RECORD_AUDIO"
26+
],
27+
"package": "com.shibamroy.hacknet"
28+
},
29+
"notification": {
30+
"icon": "./assets/images/adaptive-icon/foreground.png",
31+
"color": "#ec3750"
32+
},
33+
"web": {
34+
"bundler": "metro",
35+
"output": "static",
36+
"favicon": "./assets/images/favicon.png"
37+
},
38+
"plugins": [
39+
[
40+
"expo-notifications",
41+
{
42+
"icon": "./assets/images/adaptive-icon/foreground.png",
43+
"color": "#ec3750",
44+
"defaultChannel": "default",
45+
"sounds": [
46+
"./assets/sounds/notification-ping.mp3",
47+
],
48+
"enableBackgroundRemoteNotifications": true
49+
}
50+
],
51+
[
52+
"expo-image-picker",
53+
{
54+
"photosPermission": "The app accesses your photos to make posts, or to customize profile"
55+
}
56+
],
57+
"expo-router",
58+
[
59+
"expo-splash-screen",
60+
{
61+
"image": "./assets/images/splash.png",
62+
"imageWidth": 200,
63+
"resizeMode": "contain",
64+
"backgroundColor": "#17171d"
65+
}
66+
],
67+
"expo-web-browser",
68+
[
69+
"expo-video",
70+
{
71+
"supportsBackgroundPlayback": true,
72+
"supportsPictureInPicture": true
73+
}
74+
],
75+
[
76+
"expo-font",
77+
{
78+
"fonts": [
79+
"./assets/fonts/PhantomSans-Regular.otf"
80+
],
81+
"android": {
82+
"fonts": [
83+
{
84+
"fontFamily": "PhantomSans",
85+
"fontDefinitions": [
86+
{
87+
"path": "./assets/fonts/PhantomSans-Regular.otf",
88+
"weight": 400,
89+
"style": "normal"
90+
},
91+
{
92+
"path": "./assets/fonts/PhantomSans-Italic.otf",
93+
"weight": 400,
94+
"style": "italic"
95+
},
96+
{
97+
"path": "./assets/fonts/PhantomSans-Bold.otf",
98+
"weight": 700
99+
}
100+
]
101+
}
102+
]
103+
},
104+
"ios": {
105+
"fonts": [
106+
"./assets/fonts/PhantomSans-Regular.otf",
107+
"./assets/fonts/PhantomSans-Bold.otf",
108+
"./assets/fonts/PhantomSans-Italic.otf"
109+
]
110+
}
111+
}
112+
]
113+
],
114+
"experiments": {
115+
"typedRoutes": true
116+
},
117+
"extra": {
118+
"router": {},
119+
"eas": {
120+
"projectId": "14749a4f-8461-4113-8c2b-238775dfce1c"
121+
}
122+
}
123+
});

app.json

Lines changed: 0 additions & 105 deletions
This file was deleted.

app/(tabs)/home/settings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function SettingsScreen() {
2121
const insets = useSafeAreaInsets();
2222

2323
function logout() {
24+
auth.signOut();
2425
signOut(auth).then(async () => {
2526
await AsyncStorage.clear();
2627
router.navigate("/auth/login");

app/_layout.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Stack } from "expo-router";
44
//contexts
55
import { BottomSheetProvider } from "@contexts/BottomSheetContext";
66
import { ModalProvider } from "@contexts/modalContext";
7+
import { NotificationProvider } from "@contexts/notificationContext";
78
import { UserDataProvider } from "@contexts/userContext";
89

910
//react
@@ -16,6 +17,20 @@ import { GestureHandlerRootView } from "react-native-gesture-handler";
1617
import LoadingScreen from "./loading";
1718

1819

20+
//notifications
21+
import * as Notifications from 'expo-notifications';
22+
23+
24+
Notifications.setNotificationHandler({
25+
handleNotification: async () => ({
26+
shouldPlaySound: true,
27+
shouldSetBadge: true,
28+
shouldShowBanner: true,
29+
shouldShowList: true,
30+
}),
31+
});
32+
33+
1934
export default function RootLayout() {
2035
// handling loading state
2136
const [user, setUser] = useState<User | null>(null);
@@ -40,14 +55,16 @@ export default function RootLayout() {
4055

4156
return (
4257
<GestureHandlerRootView>
43-
<BottomSheetProvider>
44-
<ModalProvider>
45-
<UserDataProvider>
46-
<Stack initialRouteName={"auth/login"} screenOptions={{ contentStyle: { backgroundColor: "#17171d" }, headerShown: false, animation: "fade" }}>
47-
</Stack>
48-
</UserDataProvider>
49-
</ModalProvider>
50-
</BottomSheetProvider>
58+
<NotificationProvider>
59+
<BottomSheetProvider>
60+
<ModalProvider>
61+
<UserDataProvider>
62+
<Stack initialRouteName={"auth/login"} screenOptions={{ contentStyle: { backgroundColor: "#17171d" }, headerShown: false, animation: "fade" }}>
63+
</Stack>
64+
</UserDataProvider>
65+
</ModalProvider>
66+
</BottomSheetProvider>
67+
</NotificationProvider>
5168
</GestureHandlerRootView>
5269
);
5370
}

app/auth/login.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import { StyleSheet, View } from "react-native";
77

88
//firebase
99
import { signInWithEmailAndPassword } from "firebase/auth";
10+
import { doc, updateDoc } from "firebase/firestore";
1011

1112
//contexts
12-
import { auth } from '@auth/firebase';
13+
import { auth, db } from '@auth/firebase';
14+
import { useNotificationContext } from "@contexts/notificationContext";
1315
import { useModalContext } from "../../src/contexts/modalContext";
1416

1517
//func
@@ -28,9 +30,12 @@ export default function LoginScreen() {
2830
const [password, setPassword] = useState("");
2931
const user = auth.currentUser;
3032
const { alert, updateActivity, setActivityVisible, setActivityText } = useModalContext();
33+
const { expoPushToken, notification } = useNotificationContext();
3134

3235
if (user) {
33-
return <Redirect href={"/(tabs)/home"} />
36+
if (user.emailVerified) {
37+
return <Redirect href={"/(tabs)/home"} />
38+
}
3439
}
3540

3641
setActivityText("Logging in");
@@ -48,6 +53,10 @@ export default function LoginScreen() {
4853
} else {
4954
updateActivity(1, "Done!");
5055
setActivityVisible(false);
56+
updateDoc(doc(db, "users", user.uid),
57+
{
58+
notificationToken: expoPushToken
59+
});
5160
router.replace("/(tabs)/home");
5261
}
5362
} else {

app/auth/signup.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { createUserWithEmailAndPassword, sendEmailVerification, updateProfile }
1414
import { doc, setDoc } from "firebase/firestore";
1515

1616
//contexts
17+
import { useNotificationContext } from "@contexts/notificationContext";
1718
import { useModalContext } from "../../src/contexts/modalContext";
1819

1920
//func
@@ -33,6 +34,7 @@ export default function SignUpScreen() {
3334
const [email, setEmail] = useState("");
3435
const [password, setPassword] = useState("");
3536
const [confirmpassword, setCpassword] = useState("");
37+
const { expoPushToken, notification } = useNotificationContext();
3638

3739
const registerUser = async (email: string, password: string, name: string) => {
3840
setActivityVisible(true);
@@ -50,14 +52,16 @@ export default function SignUpScreen() {
5052
await setDoc(doc(db, "users", user.uid), {
5153
uid: user.uid,
5254
email: user.email,
55+
banner: "3",
5356
displayName: user.displayName,
5457
displayNameLower: user.displayName?.toLowerCase(),
5558
createdAt: new Date(),
5659
avatar: user.photoURL || null,
5760
num_tracking: 0,
5861
num_logs: 0,
5962
friends: [],
60-
bio: "This Hacker hasn't set up their bio yet :("
63+
bio: "This Hacker hasn't set up their bio yet :(",
64+
notificationToken: expoPushToken
6165

6266
}).then().catch((e) => { console.log("Error occured while making db changes.", e.code, e.message) });
6367

@@ -102,10 +106,12 @@ export default function SignUpScreen() {
102106
(error) => {
103107
if (error.code === 'auth/email-already-in-use') {
104108
alert("Failed", "Email already in use, please use some other email! If you recently tried to sign up, check your email for verification")
109+
setActivityVisible(false);
105110
}
106111

107112
if (error.code === 'auth/invalid-email') {
108113
alert("Failed", 'Hey, That email address is invalid!');
114+
setActivityVisible(false);
109115
}
110116
}
111117
)
66.1 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"expo-clipboard": "~7.1.5",
2929
"expo-constants": "~17.1.7",
3030
"expo-dev-client": "^5.2.4",
31-
"expo-device": "^7.1.4",
31+
"expo-device": "~7.1.4",
3232
"expo-doctor": "^1.17.0",
3333
"expo-font": "~13.3.2",
3434
"expo-haptics": "~14.1.4",

0 commit comments

Comments
 (0)