Kalender ics link und Bugfix

This commit is contained in:
2024-10-14 20:50:52 +02:00
parent faece890f8
commit c564108c5d
2 changed files with 47 additions and 36 deletions

View File

@@ -76,13 +76,20 @@ const Interface = ({ children }) => {
}; };
const fetchUserInformation = async (username) => { const fetchUserInformation = async (username) => {
const userinformation = await requestGet(`userinformation/?username=${username}`, false); try {
if (!userinformation) { return await requestGet(`userinformation/?username=${username}`, false);
console.log("Using Demoinformation"); } catch (error) {
showToast(ToastType.Info, "You are using a DEMOUSER", 5000); if (error.response.status === 404) {
return await requestGet(`demoinformation/`); const demoinformation = await requestGet(`demoinformation/`);
if (demoinformation) {
console.log("Using Demoinformation");
showToast(ToastType.Info, "You are using a DEMOUSER", 5000);
}
return demoinformation;
}
console.error("Error fetching user information:", error);
return Null;
} }
return userinformation;
}; };
const fetchTimes = async () => { const fetchTimes = async () => {
@@ -127,7 +134,7 @@ const Interface = ({ children }) => {
} }
} catch (error) { } catch (error) {
if (!handleError) { if (!handleError) {
return null throw(error);
} else if (error.response) { } else if (error.response) {
if (error.response.data.message) { if (error.response.data.message) {
throw new NetworkError(error.response.status + ": " + error.response.data.message, url); throw new NetworkError(error.response.status + ": " + error.response.data.message, url);

View File

@@ -1,6 +1,6 @@
import { addMonths, addDays, format, isSameDay, isWithinInterval, parseISO, getDay, parse, differenceInDays } from 'date-fns'; import { addMonths, addDays, format, isSameDay, isWithinInterval, parseISO, getDay, parse, differenceInDays } from 'date-fns';
import React, { useContext, useEffect, useState, useMemo, useCallback } from 'react'; import React, { useContext, useEffect, useState, useMemo, useCallback } from 'react';
import { FlatList, ScrollView, StyleSheet, View, Text, TouchableOpacity, Modal } from 'react-native'; import { FlatList, ScrollView, StyleSheet, View, Text, TouchableOpacity, Modal, Linking } from 'react-native';
import ErrorBoundary from 'react-native-error-boundary'; import ErrorBoundary from 'react-native-error-boundary';
import { RefreshControl } from 'react-native-web-refresh-control'; import { RefreshControl } from 'react-native-web-refresh-control';
import { InterfaceContext } from '../Interface'; import { InterfaceContext } from '../Interface';
@@ -107,34 +107,39 @@ const Calendar = () => {
); );
} else if (selectedView === 'tests') { } else if (selectedView === 'tests') {
return ( return (
<FlatList <View style={{ marginLeft: 5 }}>
refreshControl={<RefreshControl refreshing={loading} onRefresh={refresh} colors={[colors.primary]} />} <TouchableOpacity onPress={() => Linking.openURL('https://ux4.edvschule-plattling.de/~hthaler/tests-calendar/')}>
data={calendarData.tests} <Text style={{ color: colors.primary }}>Prüfungen in einen Kalender importieren (.ics)</Text>
keyExtractor={(item) => item.date + item.hourFrom + item.hourUntil + item.subject} </TouchableOpacity>
<FlatList
refreshControl={<RefreshControl refreshing={loading} onRefresh={refresh} colors={[colors.primary]} />}
data={calendarData.tests}
keyExtractor={(item) => item.date + item.hourFrom + item.hourUntil + item.subject}
renderItem={({ item }) => ( renderItem={({ item }) => (
<View style={{ marginLeft: 5, marginBottom: 5, borderBottomWidth: 1, borderColor: '#ccc' }}> <View style={{ marginTop: 5, borderBottomWidth: 1, borderColor: '#ccc', flexDirection: 'row', flexWrap: 'wrap' }}>
<View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 3 }}> <View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 5, marginRight: 20 }}>
<ThemeText style={{ fontWeight: 'bold', marginRight: 5 }}>{format(item.date, 'dd.MM.yyyy')}</ThemeText> <ThemeText style={{ fontWeight: 'bold', marginRight: 5 }}>{format(item.date, 'dd.MM.yyyy')}</ThemeText>
<ThemeText>{`${item.timeFrom}-${item.timeUntil}`}</ThemeText> <ThemeText>{`${item.timeFrom}-${item.timeUntil}`}</ThemeText>
</View> </View>
<View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 5 }}> <View style={{ flexDirection: 'row', alignItems: 'center', marginBottom: 5 }}>
<ThemeText style={{ marginRight: 5 }}>{item.subject}</ThemeText> <ThemeText style={{ marginRight: 5 }}>{item.subject}</ThemeText>
<ThemeText style={{ marginRight: 5 }}>{item.type}</ThemeText> <ThemeText style={{ marginRight: 5 }}>{item.type}</ThemeText>
{userInformation.usertype === 'teacher' && ( {userInformation.usertype === 'teacher' && (
<ThemeText style={{ marginRight: 5 }}>{item.class}</ThemeText> <ThemeText style={{ marginRight: 5 }}>{item.class}</ThemeText>
)} )}
{userInformation.usertype === 'pupil' && ( {userInformation.usertype === 'pupil' && (
<ThemeText style={{ marginRight: 5 }}>{item.teacher}</ThemeText> <ThemeText style={{ marginRight: 5 }}>{item.teacher}</ThemeText>
)} )}
<ThemeText style={{ marginRight: 5 }}>{item.room}</ThemeText> <ThemeText style={{ marginRight: 5 }}>{item.room}</ThemeText>
<ThemeText style={{ marginRight: 5 }}>{`${item.hourFrom||'n'}-${item.hourUntil||'n'}`}</ThemeText> <ThemeText style={{ marginRight: 5 }}>{`${item.hourFrom||'n'}-${item.hourUntil||'n'}`}</ThemeText>
</View> </View>
</View> </View>
)} )}
getItemLayout={(data, index) => ( getItemLayout={(data, index) => (
{ length: 70, offset: 70 * index, index } { length: 70, offset: 70 * index, index }
)} )}
/> />
</View>
); );
} else if (selectedView === 'appointments') { } else if (selectedView === 'appointments') {
// Group appointments by day // Group appointments by day
@@ -401,7 +406,6 @@ const getDayType = (date, calendarData) => {
return fromDate <= targetDate && targetDate <= untilDate; return fromDate <= targetDate && targetDate <= untilDate;
}); });
console.log(targetDate, dayType);
return dayType ? dayType.type : "schultag"; return dayType ? dayType.type : "schultag";
}; };