Files
jellyfin-audio-player/src/utility/ErrorReportingAlert.ts

59 lines
2.1 KiB
TypeScript
Raw Normal View History

import { useEffect } from 'react';
import { Alert } from 'react-native';
2023-06-19 22:26:41 +02:00
import { useAppDispatch, useTypedSelector } from '@/store';
import { t } from '@/localisation';
import { setReceivedErrorReportingAlert } from '@/store/settings/actions';
import { setSentryStatus } from './Sentry';
import { useNavigation } from '@react-navigation/native';
2023-06-19 23:03:17 +02:00
import { NavigationProp } from '@/screens/types';
/**
* This will send out an alert message asking the user if they want to enable
* error reporting.
*/
export default function ErrorReportingAlert() {
const { hasReceivedErrorReportingAlert } = useTypedSelector(state => state.settings);
2023-04-23 01:15:07 +02:00
const navigation = useNavigation<NavigationProp>();
2022-05-18 22:10:06 +02:00
const dispatch = useAppDispatch();
useEffect(() => {
// Only send out alert if we haven't done so ever
if (!hasReceivedErrorReportingAlert) {
// Generate the alert
Alert.alert(
t('enable-error-reporting'),
t('enable-error-reporting-description'),
[
{
text: t('enable'),
style: 'default',
onPress: () => {
setSentryStatus(true);
}
},
{
text: t('disable'),
style: 'destructive',
onPress: () => {
setSentryStatus(false);
}
},
{
text: t('more-info'),
style: 'cancel',
onPress: () => {
navigation.navigate('ErrorReporting');
}
}
]
);
// Store the flag that we have sent out the alert, so that we don't
// have to do so anymore in the future.
dispatch(setReceivedErrorReportingAlert());
}
2022-01-01 22:36:05 +01:00
}, [dispatch, hasReceivedErrorReportingAlert, navigation]);
return null;
}