Compare commits
4 Commits
amalia/07-
...
amalia/08-
| Author | SHA1 | Date | |
|---|---|---|---|
| fce5465d4b | |||
| 3060ea84a5 | |||
| cd16b8ba04 | |||
| 602860d9c3 |
@@ -14,7 +14,8 @@ import { pushToPage } from "@/lib/pushToPage";
|
||||
import store from "@/lib/store";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import firebase from '@react-native-firebase/app';
|
||||
import { getApp } from "@react-native-firebase/app";
|
||||
import { getMessaging, onMessage } from "@react-native-firebase/messaging";
|
||||
import { Redirect, router, Stack, usePathname } from "expo-router";
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import { useEffect } from "react";
|
||||
@@ -51,16 +52,18 @@ export default function RootLayout() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = firebase.app().messaging().onMessage(async remoteMessage => {
|
||||
const mess = getMessaging(getApp());
|
||||
|
||||
const unsubscribe = onMessage(mess, async remoteMessage => {
|
||||
const id = remoteMessage?.data?.id;
|
||||
const category = remoteMessage?.data?.category;
|
||||
const content = remoteMessage?.data?.content;
|
||||
const title = remoteMessage?.notification?.title;
|
||||
|
||||
if (remoteMessage.notification != undefined && remoteMessage.notification.title != undefined && remoteMessage.notification.body != undefined) {
|
||||
if (category == 'discussion-general' && pathname == '/discussion/' + content) {
|
||||
return null
|
||||
} else if (pathname != `/${category}/${content}`) {
|
||||
if (remoteMessage.notification?.title && remoteMessage.notification?.body) {
|
||||
if (category === 'discussion-general' && pathname === '/discussion/' + content) {
|
||||
return null;
|
||||
} else if (pathname !== `/${category}/${content}`) {
|
||||
Notifier.showNotification({
|
||||
title: title,
|
||||
description: remoteMessage.notification?.body,
|
||||
|
||||
@@ -149,9 +149,9 @@ export default function CreateAnnouncement() {
|
||||
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
|
||||
{
|
||||
item.Division.map((division: any, i: any) => (
|
||||
<View key={i} style={[Styles.rowItemsCenter]}>
|
||||
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
|
||||
<Entypo name="dot-single" size={24} color="black" />
|
||||
<Text style={[Styles.textDefault]}>{division.name}</Text>
|
||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
|
||||
</View>
|
||||
))
|
||||
}
|
||||
|
||||
@@ -193,9 +193,9 @@ export default function EditAnnouncement() {
|
||||
<Text style={[Styles.textDefaultSemiBold]}>{item.name}</Text>
|
||||
{
|
||||
item.Division.map((division: any, i: any) => (
|
||||
<View key={i} style={[Styles.rowItemsCenter]}>
|
||||
<View key={i} style={[Styles.rowItemsCenter, Styles.w90]}>
|
||||
<Entypo name="dot-single" size={24} color="black" />
|
||||
<Text style={[Styles.textDefault]}>{division.name}</Text>
|
||||
<Text style={[Styles.textDefault]} numberOfLines={1} ellipsizeMode='tail'>{division.name}</Text>
|
||||
</View>
|
||||
))
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export default function Announcement() {
|
||||
<View>
|
||||
<InputSearch onChange={setSearch} />
|
||||
</View>
|
||||
<View style={[{ flex: 2 }, Styles.mb50]}>
|
||||
<View style={[{ flex: 2 }]}>
|
||||
{
|
||||
loading ?
|
||||
arrSkeleton.map((item, index) => {
|
||||
|
||||
@@ -10,14 +10,15 @@ import Text from '@/components/Text';
|
||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
||||
import Styles from "@/constants/Styles";
|
||||
import { apiGetDiscussionGeneralOne, apiSendDiscussionGeneralCommentar } from "@/lib/api";
|
||||
import { getDB } from "@/lib/firebaseDatabase";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
|
||||
import { firebase } from '@react-native-firebase/database';
|
||||
import { ref } from '@react-native-firebase/database';
|
||||
import { useHeaderHeight } from '@react-navigation/elements';
|
||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { KeyboardAvoidingView, Platform, Pressable, ScrollView, View } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useHeaderHeight } from '@react-navigation/elements';
|
||||
|
||||
type Props = {
|
||||
id: string
|
||||
@@ -49,7 +50,7 @@ export default function DetailDiscussionGeneral() {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadingKomentar, setLoadingKomentar] = useState(true)
|
||||
const arrSkeleton = Array.from({ length: 3 }, (_, index) => index)
|
||||
const reference = firebase.app().database('https://mobile-darmasaba-default-rtdb.asia-southeast1.firebasedatabase.app').ref(`/discussion-general/${id}`);
|
||||
const reference = ref(getDB(), `/discussion-general/${id}`);
|
||||
const headerHeight = useHeaderHeight();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -8,7 +8,6 @@ import Styles from "@/constants/Styles";
|
||||
import { apiGetCalendarByDateDivision, apiGetIndicatorCalendar } from "@/lib/api";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { Feather } from "@expo/vector-icons";
|
||||
import dayjs from "dayjs";
|
||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||
import 'intl';
|
||||
import 'intl/locale-data/jsonp/id';
|
||||
@@ -53,7 +52,7 @@ export default function CalendarDivision() {
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const response = await apiGetCalendarByDateDivision({
|
||||
user: hasil,
|
||||
date: dayjs(selected).format("YYYY-MM-DD"),
|
||||
date: moment(selected).format("YYYY-MM-DD"),
|
||||
division: id,
|
||||
});
|
||||
setData(response.data);
|
||||
@@ -71,7 +70,7 @@ export default function CalendarDivision() {
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const response = await apiGetIndicatorCalendar({
|
||||
user: hasil,
|
||||
date: dayjs(newDate).format("YYYY-MM-DD"),
|
||||
date: moment(newDate).format("YYYY-MM-DD"),
|
||||
division: id,
|
||||
});
|
||||
setDataIndicator(response.data);
|
||||
@@ -113,6 +112,7 @@ export default function CalendarDivision() {
|
||||
text={day.text}
|
||||
isSelected={day.isSelected}
|
||||
isSign={sign}
|
||||
onPress={() => setSelected(new Date(today))}
|
||||
/>
|
||||
);
|
||||
},
|
||||
@@ -156,7 +156,6 @@ export default function CalendarDivision() {
|
||||
mode="single"
|
||||
date={selected}
|
||||
month={month}
|
||||
onChange={({ date }) => setSelected(date)}
|
||||
onMonthChange={(month) => setMonth(month)}
|
||||
styles={{
|
||||
selected: Styles.selectedDate,
|
||||
|
||||
@@ -13,14 +13,15 @@ import {
|
||||
apiGetDivisionOneFeature,
|
||||
apiSendDiscussionCommentar,
|
||||
} from "@/lib/api";
|
||||
import { getDB } from "@/lib/firebaseDatabase";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
|
||||
import { firebase } from "@react-native-firebase/database";
|
||||
import { ref } from "@react-native-firebase/database";
|
||||
import { useHeaderHeight } from '@react-navigation/elements';
|
||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { KeyboardAvoidingView, Platform, Pressable, RefreshControl, ScrollView, View } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useHeaderHeight } from '@react-navigation/elements';
|
||||
|
||||
type Props = {
|
||||
id: string;
|
||||
@@ -58,7 +59,7 @@ export default function DiscussionDetail() {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [loadingKomentar, setLoadingKomentar] = useState(true)
|
||||
const arrSkeleton = Array.from({ length: 3 })
|
||||
const reference = firebase.app().database('https://mobile-darmasaba-default-rtdb.asia-southeast1.firebasedatabase.app').ref(`/discussion-division/${detail}`);
|
||||
const reference = ref(getDB(), `/discussion-division/${detail}`);
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
const headerHeight = useHeaderHeight();
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
import Styles from "@/constants/Styles";
|
||||
import { View } from "react-native";
|
||||
import { Pressable, View } from "react-native";
|
||||
import Text from "../Text";
|
||||
|
||||
type Props = {
|
||||
text: string;
|
||||
isSelected: boolean;
|
||||
isSign: boolean;
|
||||
onPress?: () => void;
|
||||
}
|
||||
|
||||
|
||||
export default function ItemDateCalendar({ text, isSelected, isSign }: Props) {
|
||||
export default function ItemDateCalendar({ text, isSelected, isSign, onPress }: Props) {
|
||||
return (
|
||||
<>
|
||||
<View style={{ alignItems: 'center' }}>
|
||||
<Pressable style={{ alignItems: 'center' }} onPress={onPress}>
|
||||
<Text style={[isSelected ? Styles.cWhite : Styles.cBlack]}>{text}</Text>
|
||||
<View style={[Styles.signDate, { backgroundColor: isSign ? 'red' : 'transparent' }]}></View>
|
||||
</View>
|
||||
</Pressable>
|
||||
</>
|
||||
)
|
||||
}
|
||||
9
index.js
9
index.js
@@ -1,12 +1,15 @@
|
||||
// index.js
|
||||
import 'expo-router/entry'; // ⬅️ wajib ada agar expo-router tetap bekerja
|
||||
|
||||
import messaging from '@react-native-firebase/messaging';
|
||||
import { getApp } from '@react-native-firebase/app';
|
||||
import { getMessaging, setBackgroundMessageHandler } from '@react-native-firebase/messaging';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
// ✅ Firebase background handler — wajib diletakkan DI SINI
|
||||
messaging().setBackgroundMessageHandler(async remoteMessage => {
|
||||
// ✅ Ambil instance messaging modular
|
||||
const mess = getMessaging(getApp());
|
||||
|
||||
// ✅ Firebase background handler — wajib diletakkan DI SINI
|
||||
setBackgroundMessageHandler(mess, async remoteMessage => {
|
||||
const screen = remoteMessage?.data?.category;
|
||||
const content = remoteMessage?.data?.content;
|
||||
|
||||
|
||||
9
lib/firebaseDatabase.ts
Normal file
9
lib/firebaseDatabase.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { getApp } from '@react-native-firebase/app';
|
||||
import { getDatabase } from '@react-native-firebase/database';
|
||||
|
||||
// Ganti URL sesuai punya kamu
|
||||
const DATABASE_URL = 'https://mobile-darmasaba-default-rtdb.asia-southeast1.firebasedatabase.app';
|
||||
|
||||
export function getDB() {
|
||||
return getDatabase(getApp(), DATABASE_URL);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { getApp, getApps, initializeApp } from '@react-native-firebase/app';
|
||||
import messaging, { getMessaging } from '@react-native-firebase/messaging';
|
||||
import { getMessaging, registerDeviceForRemoteMessages, setAutoInitEnabled } from '@react-native-firebase/messaging';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import { useEffect } from 'react';
|
||||
import { PermissionsAndroid, Platform } from 'react-native';
|
||||
|
||||
@@ -20,20 +20,8 @@ const initializeFirebase = async () => {
|
||||
try {
|
||||
const app = getApps().length ? getApp() : initializeApp(RNfirebaseConfig);
|
||||
const mess = getMessaging(app);
|
||||
|
||||
await messaging().registerDeviceForRemoteMessages();
|
||||
|
||||
// Set auto initialization and background message handler
|
||||
mess.setAutoInitEnabled(true);
|
||||
// mess.setBackgroundMessageHandler(async remoteMessage => {
|
||||
// const screen = remoteMessage?.data?.category;
|
||||
// const content = remoteMessage?.data?.content;
|
||||
|
||||
// if (screen && content) {
|
||||
// await AsyncStorage.setItem('navigateOnOpen', JSON.stringify({ screen, content }));
|
||||
// }
|
||||
// });
|
||||
|
||||
await registerDeviceForRemoteMessages(mess);
|
||||
setAutoInitEnabled(mess, true);
|
||||
return mess
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize Firebase:', error);
|
||||
@@ -53,8 +41,10 @@ export const requestPermission = async () => {
|
||||
}
|
||||
return false
|
||||
}
|
||||
} else if (Platform.OS === 'ios') {
|
||||
const { status } = await Notifications.requestPermissionsAsync();
|
||||
return status === 'granted';
|
||||
}
|
||||
return true
|
||||
} catch (err) {
|
||||
console.warn('Error requesting notification permissions:', err);
|
||||
}
|
||||
@@ -62,8 +52,8 @@ export const requestPermission = async () => {
|
||||
|
||||
export const getToken = async () => {
|
||||
try {
|
||||
await initializeFirebase();
|
||||
const token = await messaging().getToken();
|
||||
const mess = await initializeFirebase();
|
||||
const token = await mess?.getToken();
|
||||
return token;
|
||||
} catch (error) {
|
||||
console.error("Error getting token:", error);
|
||||
@@ -74,8 +64,6 @@ export const useNotification = () => {
|
||||
useEffect(() => {
|
||||
const initializeAndSetup = async () => {
|
||||
try {
|
||||
// await initializeFirebase();
|
||||
// await requestPermission();
|
||||
await getToken();
|
||||
} catch (error) {
|
||||
console.error('Failed to setup notifications:', error);
|
||||
|
||||
@@ -56,6 +56,7 @@ export default function AuthProvider({ children }: { children: ReactNode }): Rea
|
||||
const permission = await requestPermission()
|
||||
if (permission) {
|
||||
try {
|
||||
// COMING SOON
|
||||
if (Platform.OS === 'android') {
|
||||
const tokenDevice = await getToken()
|
||||
const register = await apiRegisteredToken({ user: hasil, token: String(tokenDevice) })
|
||||
@@ -78,8 +79,9 @@ export default function AuthProvider({ children }: { children: ReactNode }): Rea
|
||||
const signOut = useCallback(async () => {
|
||||
try {
|
||||
const hasil = await decryptToken(String(tokenRef.current))
|
||||
const token = await getToken()
|
||||
// COMING SOON
|
||||
if (Platform.OS === 'android') {
|
||||
const token = await getToken()
|
||||
const response = await apiUnregisteredToken({ user: hasil, token: String(token) })
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user