delete firebase
This commit is contained in:
239
App.tsx
239
App.tsx
@@ -13,8 +13,6 @@ import {
|
||||
Animated,
|
||||
Dimensions,
|
||||
LogBox,
|
||||
PermissionsAndroid,
|
||||
Platform,
|
||||
StatusBar,
|
||||
StyleSheet,
|
||||
View,
|
||||
@@ -22,16 +20,6 @@ import {
|
||||
import Toast from 'react-native-toast-message';
|
||||
|
||||
// Screens
|
||||
import notifee, { AndroidImportance } from '@notifee/react-native';
|
||||
import { getApp } from '@react-native-firebase/app';
|
||||
import {
|
||||
getInitialNotification,
|
||||
getMessaging,
|
||||
getToken,
|
||||
onMessage,
|
||||
onNotificationOpenedApp,
|
||||
} from '@react-native-firebase/messaging';
|
||||
import DeviceInfo from 'react-native-device-info';
|
||||
import Login from 'screens/auth/login/ui';
|
||||
import Confirm from 'screens/auth/login/ui/Confirm';
|
||||
import Register from 'screens/auth/registeration/ui';
|
||||
@@ -46,7 +34,6 @@ import RestrictedProduct from 'screens/home/restrictedProduct/ui/RestrictedProdu
|
||||
import CreatePassword from 'screens/passport/createPassport/ui/CreatePassword';
|
||||
import Passport from 'screens/passport/myPassport/ui/Passport';
|
||||
import Profile from 'screens/profile/myProfile/ui/Profile';
|
||||
import Notifications from 'screens/profile/notifications/ui/Notifications';
|
||||
import AddedLock from 'screens/profile/settings/ui/AddedLock';
|
||||
import Settings from 'screens/profile/settings/ui/Settings';
|
||||
import SettingsLock from 'screens/profile/settings/ui/SettingsLock';
|
||||
@@ -68,107 +55,107 @@ const Stack = createNativeStackNavigator();
|
||||
const screenWidth = Dimensions.get('window').width;
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
const saveNotification = async (remoteMessage: any) => {
|
||||
try {
|
||||
const stored = await AsyncStorage.getItem('notifications');
|
||||
const notifications = stored ? JSON.parse(stored) : [];
|
||||
// const saveNotification = async (remoteMessage: any) => {
|
||||
// try {
|
||||
// const stored = await AsyncStorage.getItem('notifications');
|
||||
// const notifications = stored ? JSON.parse(stored) : [];
|
||||
|
||||
const newNotification = {
|
||||
id: Date.now(),
|
||||
title:
|
||||
remoteMessage.notification?.title ||
|
||||
remoteMessage.data?.title ||
|
||||
'Yangi bildirishnoma',
|
||||
message:
|
||||
remoteMessage.notification?.body ||
|
||||
remoteMessage.data?.body ||
|
||||
'Matn yo‘q',
|
||||
sentTime: remoteMessage.sentTime || Date.now(),
|
||||
};
|
||||
// const newNotification = {
|
||||
// id: Date.now(),
|
||||
// title:
|
||||
// remoteMessage.notification?.title ||
|
||||
// remoteMessage.data?.title ||
|
||||
// 'Yangi bildirishnoma',
|
||||
// message:
|
||||
// remoteMessage.notification?.body ||
|
||||
// remoteMessage.data?.body ||
|
||||
// 'Matn yo‘q',
|
||||
// sentTime: remoteMessage.sentTime || Date.now(),
|
||||
// };
|
||||
|
||||
await AsyncStorage.setItem(
|
||||
'notifications',
|
||||
JSON.stringify([newNotification, ...notifications]),
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('Notification saqlashda xato:', e);
|
||||
}
|
||||
};
|
||||
// await AsyncStorage.setItem(
|
||||
// 'notifications',
|
||||
// JSON.stringify([newNotification, ...notifications]),
|
||||
// );
|
||||
// } catch (e) {
|
||||
// console.error('Notification saqlashda xato:', e);
|
||||
// }
|
||||
// };
|
||||
|
||||
async function onDisplayNotification(remoteMessage: any) {
|
||||
const channelId = await notifee.createChannel({
|
||||
id: 'default',
|
||||
name: 'Umumiy bildirishnomalar',
|
||||
sound: 'default',
|
||||
importance: AndroidImportance.HIGH,
|
||||
});
|
||||
// async function onDisplayNotification(remoteMessage: any) {
|
||||
// const channelId = await notifee.createChannel({
|
||||
// id: 'default',
|
||||
// name: 'Umumiy bildirishnomalar',
|
||||
// sound: 'default',
|
||||
// importance: AndroidImportance.HIGH,
|
||||
// });
|
||||
|
||||
await notifee.displayNotification({
|
||||
title:
|
||||
remoteMessage.notification?.title ||
|
||||
remoteMessage.data?.title ||
|
||||
'Yangi xabar',
|
||||
body:
|
||||
remoteMessage.notification?.body ||
|
||||
remoteMessage.data?.body ||
|
||||
'Matn yo‘q',
|
||||
android: {
|
||||
channelId,
|
||||
largeIcon: 'ic_launcher_foreground',
|
||||
sound: 'default',
|
||||
pressAction: {
|
||||
id: 'default',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
// await notifee.displayNotification({
|
||||
// title:
|
||||
// remoteMessage.notification?.title ||
|
||||
// remoteMessage.data?.title ||
|
||||
// 'Yangi xabar',
|
||||
// body:
|
||||
// remoteMessage.notification?.body ||
|
||||
// remoteMessage.data?.body ||
|
||||
// 'Matn yo‘q',
|
||||
// android: {
|
||||
// channelId,
|
||||
// largeIcon: 'ic_launcher_foreground',
|
||||
// sound: 'default',
|
||||
// pressAction: {
|
||||
// id: 'default',
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
|
||||
async function requestNotificationPermission() {
|
||||
if (Platform.OS === 'android' && Platform.Version >= 33) {
|
||||
const granted = await PermissionsAndroid.request(
|
||||
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
|
||||
);
|
||||
console.log('POST_NOTIFICATIONS permission:', granted);
|
||||
}
|
||||
}
|
||||
// async function requestNotificationPermission() {
|
||||
// if (Platform.OS === 'android' && Platform.Version >= 33) {
|
||||
// const granted = await PermissionsAndroid.request(
|
||||
// PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
|
||||
// );
|
||||
// console.log('POST_NOTIFICATIONS permission:', granted);
|
||||
// }
|
||||
// }
|
||||
|
||||
export default function App() {
|
||||
const [initialRoute, setInitialRoute] = useState<string | null>(null);
|
||||
const slideAnim = useRef(new Animated.Value(0)).current;
|
||||
const [isSplashVisible, setIsSplashVisible] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
requestNotificationPermission();
|
||||
// useEffect(() => {
|
||||
// requestNotificationPermission();
|
||||
|
||||
const messagingInstance = getMessaging();
|
||||
// const messagingInstance = getMessaging();
|
||||
|
||||
const unsubscribe = onMessage(messagingInstance, async remoteMessage => {
|
||||
console.log('Foreground message:', remoteMessage);
|
||||
await saveNotification(remoteMessage);
|
||||
await onDisplayNotification(remoteMessage);
|
||||
});
|
||||
// const unsubscribe = onMessage(messagingInstance, async remoteMessage => {
|
||||
// console.log('Foreground message:', remoteMessage);
|
||||
// await saveNotification(remoteMessage);
|
||||
// await onDisplayNotification(remoteMessage);
|
||||
// });
|
||||
|
||||
const unsubscribeOpened = onNotificationOpenedApp(
|
||||
messagingInstance,
|
||||
remoteMessage => {
|
||||
console.log('Backgrounddan ochildi:', remoteMessage);
|
||||
saveNotification(remoteMessage);
|
||||
},
|
||||
);
|
||||
// const unsubscribeOpened = onNotificationOpenedApp(
|
||||
// messagingInstance,
|
||||
// remoteMessage => {
|
||||
// console.log('Backgrounddan ochildi:', remoteMessage);
|
||||
// saveNotification(remoteMessage);
|
||||
// },
|
||||
// );
|
||||
|
||||
(async () => {
|
||||
const remoteMessage = await getInitialNotification(messagingInstance);
|
||||
if (remoteMessage) {
|
||||
console.log('Killeddan ochildi:', remoteMessage);
|
||||
saveNotification(remoteMessage);
|
||||
}
|
||||
})();
|
||||
// (async () => {
|
||||
// const remoteMessage = await getInitialNotification(messagingInstance);
|
||||
// if (remoteMessage) {
|
||||
// console.log('Killeddan ochildi:', remoteMessage);
|
||||
// saveNotification(remoteMessage);
|
||||
// }
|
||||
// })();
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
unsubscribeOpened();
|
||||
};
|
||||
}, []);
|
||||
// return () => {
|
||||
// unsubscribe();
|
||||
// unsubscribeOpened();
|
||||
// };
|
||||
// }, []);
|
||||
|
||||
useEffect(() => {
|
||||
const initializeApp = async () => {
|
||||
@@ -214,34 +201,34 @@ export default function App() {
|
||||
},
|
||||
[],
|
||||
);
|
||||
const [firebaseToken, setFirebseToken] = useState<{
|
||||
fcmToken: string;
|
||||
deviceId: string;
|
||||
deviceName: string;
|
||||
} | null>();
|
||||
const app = getApp();
|
||||
const messaging = getMessaging(app);
|
||||
// const [firebaseToken, setFirebseToken] = useState<{
|
||||
// fcmToken: string;
|
||||
// deviceId: string;
|
||||
// deviceName: string;
|
||||
// } | null>();
|
||||
// const app = getApp();
|
||||
// const messaging = getMessaging(app);
|
||||
|
||||
const getDeviceData = async () => {
|
||||
try {
|
||||
const fcmToken = await getToken(messaging);
|
||||
return {
|
||||
fcmToken,
|
||||
deviceId: await DeviceInfo.getUniqueId(),
|
||||
deviceName: await DeviceInfo.getDeviceName(),
|
||||
};
|
||||
} catch (e) {
|
||||
console.log('Xato:', e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
console.log(firebaseToken);
|
||||
// const getDeviceData = async () => {
|
||||
// try {
|
||||
// const fcmToken = await getToken(messaging);
|
||||
// return {
|
||||
// fcmToken,
|
||||
// deviceId: await DeviceInfo.getUniqueId(),
|
||||
// deviceName: await DeviceInfo.getDeviceName(),
|
||||
// };
|
||||
// } catch (e) {
|
||||
// console.log('Xato:', e);
|
||||
// return null;
|
||||
// }
|
||||
// };
|
||||
// console.log(firebaseToken);
|
||||
|
||||
useEffect(() => {
|
||||
getDeviceData().then(data => {
|
||||
setFirebseToken(data);
|
||||
});
|
||||
}, []);
|
||||
// useEffect(() => {
|
||||
// getDeviceData().then(data => {
|
||||
// setFirebseToken(data);
|
||||
// });
|
||||
// }, []);
|
||||
|
||||
if (!initialRoute) return null;
|
||||
|
||||
@@ -285,9 +272,9 @@ export default function App() {
|
||||
<Stack.Screen name="PaymentQrCode" component={PaymentQrCode} />
|
||||
<Stack.Screen name="Profile" component={Profile} />
|
||||
<Stack.Screen name="Settings" component={Settings} />
|
||||
{Platform.OS === 'android' && (
|
||||
{/* {Platform.OS === 'android' && (
|
||||
<Stack.Screen name="Notifications" component={Notifications} />
|
||||
)}
|
||||
)} */}
|
||||
<Stack.Screen name="Warehouses" component={Warehouses} />
|
||||
<Stack.Screen name="Support" component={Support} />
|
||||
<Stack.Screen name="ListBranches" component={ListBranches} />
|
||||
|
||||
Reference in New Issue
Block a user