ClipSync-Mobile/src/components/notif/NotifViewRemote.tsx
Djalim Simaila 9d8cf5730f
Some checks failed
Building APK / build-apk (push) Failing after 2m35s
🔧 chore(deploy.yaml): add new GitHub Actions workflow for building APK
🔄 refactor(ClipView.tsx, NotifView.tsx): reorder tabs to show 'Remote' before 'Local'
🌐 fix(ClipViewRemote.tsx, NotifViewRemote.tsx): change API calls from http to https
🔤 fix(ClipViewLocal.tsx, NotifViewLocal.tsx): translate button text to English
🔇 fix(ClipViewRemote.tsx, NotifViewRemote.tsx): remove unnecessary toast messages
🔧 chore(NotifViewLocal.tsx): add platform check to disable feature on non-Android platforms
🔤 fix(NotifViewLocal.tsx): translate button text to English
🔧 chore(reducers.tsx): remove unused action parameters in clear functions
2024-04-12 12:43:10 +02:00

56 lines
1.6 KiB
TypeScript

import React from 'react';
import axios from 'axios';
import {ScrollView, View, Text, useWindowDimensions} from 'react-native';
import NotifListfrom from './NotifList';
import {store} from '../../redux/store';
import {useToast} from 'react-native-toast-notifications';
import {Button} from 'react-native-paper';
import {ps} from '../../utils';
import NotifList from './NotifList';
import {useDispatch} from 'react-redux';
import {remoteNotifAddToList} from '../../redux/reducers';
export default function NotifViewRemote() {
const [clips, setClips] = React.useState(
store.getState().remoteNotif.remoteNotif,
);
const toast = useToast();
const dispatch = useDispatch();
const {height, width} = useWindowDimensions();
async function getNotif(dispatch) {
axios
.get(
'https://notifysync.simailadjalim.fr/notification?token=' +
store.getState().user.token,
)
.then((response, status) => {
let remoteNotif = Object.values(response['data']['notifications']);
setClips(remoteNotif);
dispatch(remoteNotifAddToList(remoteNotif));
toast.show('fetched latest notifications from remote');
})
.catch(response => {
toast.show('failed to fetch latest notifications');
});
}
return (
<View
style={{
width: '100%',
height: '100%',
flex: 1,
margin: width > 600 ? ps(10) : 0,
}}>
<Button mode="elevated" onPress={() => dispatch(getNotif)}>
Refresh
</Button>
<ScrollView>
<NotifList type="remote" notifs={clips} />
</ScrollView>
</View>
);
}