@olea-bps/views 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/Callmanager/index.js +148 -0
  2. package/Callmanager/styles.js +62 -0
  3. package/Canteens/index.js +383 -0
  4. package/Canteens/styles.js +89 -0
  5. package/Dashboard/index.js +176 -0
  6. package/Dashboard/styles.js +16 -0
  7. package/DashboardHtwk/index.js +197 -0
  8. package/DashboardHtwk/styles.js +24 -0
  9. package/Event/index.js +369 -0
  10. package/Event/styles.js +63 -0
  11. package/FeedList/index.js +165 -0
  12. package/FeedList/styles.js +15 -0
  13. package/FeedNews/index.js +243 -0
  14. package/FeedNews/styles.js +32 -0
  15. package/Flexmenu/index.js +185 -0
  16. package/Flexmenu/styles.js +62 -0
  17. package/FlexmenuWebview/index.js +167 -0
  18. package/FlexmenuWebview/styles.js +16 -0
  19. package/Howhy/index.js +151 -0
  20. package/Howhy/styles.js +11 -0
  21. package/Jobs/index.js +217 -0
  22. package/Jobs/styles.js +41 -0
  23. package/MainMenu/index.js +329 -0
  24. package/MainMenu/styles.js +36 -0
  25. package/NewsTabbar/index.js +164 -0
  26. package/NewsTabbar/styles.js +27 -0
  27. package/Opal/index.js +136 -0
  28. package/Opal/styles.js +11 -0
  29. package/PublicTransportTicket/index.js +173 -0
  30. package/PublicTransportTicket/styles.js +17 -0
  31. package/Search/index.js +186 -0
  32. package/Search/styles.js +67 -0
  33. package/SettingsAccessibility/index.js +148 -0
  34. package/SettingsAccessibility/styles.js +13 -0
  35. package/SettingsAppInfo/index.js +86 -0
  36. package/SettingsAppInfo/styles.js +18 -0
  37. package/SettingsCanteens/index.js +249 -0
  38. package/SettingsCanteens/styles.js +33 -0
  39. package/SettingsGeneral/index.js +173 -0
  40. package/SettingsGeneral/styles.js +28 -0
  41. package/SettingsNotifications/index.js +204 -0
  42. package/SettingsNotifications/styles.js +38 -0
  43. package/SettingsUser/index.js +170 -0
  44. package/SettingsUser/styles.js +17 -0
  45. package/TimetableCalendar/index.js +322 -0
  46. package/TimetableCalendar/styles.js +117 -0
  47. package/TimetableList/index.js +397 -0
  48. package/TimetableList/styles.js +55 -0
  49. package/Webviews/index.js +158 -0
  50. package/Webviews/styles.js +11 -0
  51. package/index.js +25 -0
  52. package/package.json +41 -0
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Licensed under the Apache License, Version 2.0 (the "License");
3
+ * you may not use this file except in compliance with the License.
4
+ * You may obtain a copy of the License at
5
+ *
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software
9
+ * distributed under the License is distributed on an "AS IS" BASIS,
10
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the License for the specific language governing permissions and
12
+ * limitations under the License.
13
+ */
14
+
15
+ import { useState, useMemo, useCallback, useEffect } from 'react';
16
+ import { View, Text, TextInput, TouchableOpacity, StyleSheet, Dimensions, SafeAreaView, KeyboardAvoidingView, Platform, ActivityIndicator } from 'react-native';
17
+ import { connect } from 'react-redux';
18
+ import { withTheme, Headline } from 'react-native-paper';
19
+ import componentStyles from "./styles";
20
+ import { withTranslation } from 'react-i18next';
21
+
22
+ import { DateTime, Duration } from 'luxon';
23
+ import moment from 'moment';
24
+ import 'moment/locale/de';
25
+
26
+ import { onUpdateRefreshing, useLanguage } from '@olea-bps/core';
27
+ import { useTimetableCode } from '@olea-bps/context-timetable';
28
+ import { Ionicons } from '@expo/vector-icons';
29
+ import { AppBar as AppbarComponent } from '@olea-bps/components';
30
+ import { TabView, TabBar } from 'react-native-tab-view';
31
+ import { TimetableDay as CalendarDay } from '@olea-bps/components';
32
+ import { TimetableWeek as CalendarWeek } from '@olea-bps/components';
33
+ import { TimetableMonth as CalendarMonth } from '@olea-bps/components';
34
+ import { useCourses, TimetableNotFoundError } from '@olea-bps/context-timetable';
35
+ import { CourseDetailDialog } from '@olea-bps/components';
36
+
37
+ function TimetableViewCalendar(props) {
38
+ const { theme, theme: { themeStyles, colors, appSettings, appSettings: { modules: { timetable: { code, calendarStarttime } } } }, t, settings } = props;
39
+ const language = useLanguage();
40
+
41
+ const styles = useMemo(
42
+ () => StyleSheet.create(componentStyles(theme)),
43
+ [theme]
44
+ );
45
+
46
+ const whiteAppbar = theme?.appSettings?.modules?.timetable?.whiteAppbar ?? colors.primary;
47
+ const [timetableCode, saveTimetableCode, deleteTimetableCode] = useTimetableCode();
48
+
49
+ const [timetableCodeInput, setTimetableCodeInput] = useState(timetableCode);
50
+ const [selectedDayModeDate, setSelectedDayModeDate] = useState(() => DateTime.now());
51
+ const [selectedWeekModeISOWeekDate, setSelectedWeekModeISOWeekDate] = useState(() => DateTime.now().startOf('week').toISOWeekDate());
52
+ const [index, setIndex] = useState(0);
53
+ const [formVisible, setFormVisible] = useState(false);
54
+ const [infoVisible, setInfoVisible] = useState(timetableCode ? false : true);
55
+ const [loading, setLoading] = useState(false);
56
+ const [today, setToday] = useState(new Date());
57
+ const [selectedEvent, setSelectedEvent] = useState(null);
58
+
59
+ const [errorMessage, setErrorMessage] = useState('');
60
+ const [infoMessage, setInfoMessage] = useState('');
61
+
62
+ // Berechnen der Uhrzeit zu der beim Öffnen des Stundenplan Kalenders hingepsrungen werden soll.
63
+ // Wird in einem State gespeichert, weil später noch beim Focus-Wechsel erneut berechnet werden muss.
64
+ const [calendarScrollOffsetMinutes, setCalendarScrollOffsetMinutes] = useState(
65
+ () => {
66
+ // Berechnen der Uhrzeit, falls im Custemizing eine angegeben ist, ansonsten wird die jetzige Stunde verwendet.
67
+ // Speichern als Duration.
68
+ const calendarScrollOffsetDuration = calendarStarttime
69
+ ? Duration.fromISOTime(calendarStarttime)
70
+ : Duration.fromObject({ hours: DateTime.now().hour });
71
+
72
+ // Duration wird in Minuten umgewandelt, weil der Kalender ein Minutenoffset erwartet
73
+ return calendarScrollOffsetDuration.as('minutes');
74
+ }
75
+ );
76
+
77
+ const [courses, refreshCourses] = useCourses();
78
+
79
+ // Einstellungen für den Stundenplan-Code
80
+ const timetableCodeInputLength = code?.length ?? 0;
81
+ const timetableCodeInputFilters = code?.filters;
82
+ const timetableCodeInputPreSaveFilters = Array.isArray(code?.preSaveFilters) ? code.preSaveFilters : [];
83
+ const timetableCodeInputFilterToUpperCase = timetableCodeInputFilters?.toUpperCase ?? false;
84
+
85
+ const routes = [
86
+ appSettings?.modules?.timetable?.enableDayTab ? { key: 'day', title: t('timetable:day') } : null,
87
+ appSettings?.modules?.timetable?.enableWeekTab ? { key: 'week', title: t('timetable:week') } : null,
88
+ appSettings?.modules?.timetable?.enableMonthTab ? { key: 'month', title: t('timetable:month') } : null,
89
+ ].filter(Boolean); // Filter out null values
90
+
91
+ const activeMode = routes?.[index]?.key;
92
+ const activeHeaderDate =
93
+ activeMode === 'day'
94
+ ? selectedDayModeDate
95
+ : DateTime.fromISO(selectedWeekModeISOWeekDate);
96
+
97
+ const unsetSelectedEvent = useCallback(
98
+ () => setSelectedEvent(null),
99
+ [setSelectedEvent]
100
+ );
101
+
102
+ const renderScene = useCallback(({ route }) => {
103
+ switch (route.key) {
104
+ case 'day':
105
+ return <CalendarDay
106
+ selectedDate={selectedDayModeDate}
107
+ calendarScrollOffsetMinutes={calendarScrollOffsetMinutes}
108
+ onDateChanged={setSelectedDayModeDate}
109
+ onCourseSelected={setSelectedEvent}
110
+ />;
111
+ case 'week':
112
+ return <CalendarWeek
113
+ selectedISOWeek={selectedWeekModeISOWeekDate}
114
+ calendarScrollOffsetMinutes={calendarScrollOffsetMinutes}
115
+ onWeekChanged={setSelectedWeekModeISOWeekDate}
116
+ onCourseSelected={setSelectedEvent}
117
+ />;
118
+ case 'month':
119
+ return <CalendarMonth today={today} setToday={setToday} month={month} setMonth={setMonth} calendarScrollOffsetMinutes={calendarScrollOffsetMinutes} />;
120
+ default:
121
+ return null;
122
+ }
123
+ },
124
+ [language, selectedDayModeDate, calendarScrollOffsetMinutes, selectedDayModeDate, setSelectedDayModeDate, selectedWeekModeISOWeekDate, setSelectedWeekModeISOWeekDate]
125
+ );
126
+
127
+ // Unter verwendung von Luxon wird eine Liste der Monatsnamen generiert, dabei wird die eingestellte Sprache berücksichtigt
128
+ const months = moment.months();
129
+
130
+ const handleImportButtonPress = async () => {
131
+ setLoading(true);
132
+ setErrorMessage('');
133
+ setInfoMessage('');
134
+ await saveTimetableCode(
135
+ // Falls Filter eingestellt sind, werden diese nacheinander auf den Stundenplancode angewendet
136
+ timetableCodeInputPreSaveFilters.reduce(
137
+ (currentTimetableCode, preSaveFilter) => preSaveFilter?.(currentTimetableCode) ?? currentTimetableCode,
138
+ timetableCodeInput
139
+ )
140
+ );
141
+ const copyToday = new Date(today);
142
+ const startDate = new Date(copyToday.setDate(copyToday.getDate() - 30));
143
+ const endDate = new Date(copyToday.setDate(copyToday.getDate() + 151));
144
+ await refreshCourses(startDate.toISOString().split('T')[0], endDate.toISOString().split('T')[0])
145
+ .then(() => {
146
+ setFormVisible(false);
147
+ setLoading(false);
148
+ })
149
+ .catch((error) => {
150
+ if (error instanceof TimetableNotFoundError) {
151
+ setErrorMessage(t('timetable:codeNotFoundError', { timetableCode: timetableCodeInput }));
152
+ setLoading(false);
153
+ }
154
+ else {
155
+ setErrorMessage(t('timetable:importError'));
156
+ setLoading(false);
157
+ }
158
+ });
159
+ };
160
+
161
+ useEffect(() => {
162
+ setErrorMessage('')
163
+ if (infoVisible) {
164
+ setInfoMessage(t(timetableCode ? 'timetable:inputTimetableCode' : 'timetable:notImportedYet', { timetableCodeInputLength }));
165
+ } else {
166
+ setInfoMessage('');
167
+ }
168
+ }, [infoVisible]);
169
+ const tabView = useMemo(() => {
170
+ return (
171
+ <TabView
172
+ style={{ backgroundColor: '#fff' }}
173
+ navigationState={{ index, routes }}
174
+ renderScene={renderScene}
175
+ onIndexChange={setIndex}
176
+ initialLayout={{ width: Dimensions.get('window').width }}
177
+ swipeEnabled={false}
178
+ lazy={true}
179
+ lazyPreloadDistance={0}
180
+ renderTabBar={props => (
181
+ <TabBar
182
+ {...props}
183
+ activeColor={themeStyles.tabs.activeColor}
184
+ inactiveColor={themeStyles.tabs.inactiveColor}
185
+ style={themeStyles.tabs}
186
+ labelStyle={themeStyles.tab}
187
+ indicatorStyle={themeStyles.tabIndicator}
188
+ />
189
+ )}
190
+ />
191
+ )
192
+ }, [renderScene, index, routes, setIndex, themeStyles.tab, themeStyles.tabIndicator]);
193
+
194
+ const renderForm = () => (
195
+ <View style={styles.formContainer}>
196
+ <View style={styles.inputContainer}>
197
+ <TextInput
198
+ style={styles.codeInput}
199
+ placeholder={t('timetable:inputPlaceholder')}
200
+ value={timetableCodeInput}
201
+ onChangeText={(code) => {
202
+ setTimetableCodeInput(code);
203
+ setErrorMessage('');
204
+ }}
205
+ autoCapitalize={timetableCodeInputFilterToUpperCase ? 'characters' : 'none'}
206
+ maxLength={timetableCodeInputLength ? timetableCodeInputLength : undefined}
207
+ contextMenuHidden={false}
208
+ />
209
+ <TouchableOpacity style={styles.infoIcon} onPress={() => {
210
+ setInfoVisible(!infoVisible);
211
+ }}>
212
+ <Ionicons name="information-circle-outline" size={30} color={colors.icon} />
213
+ </TouchableOpacity>
214
+ </View>
215
+ {loading ? <ActivityIndicator size="large" color={colors.loadingIndicator} /> : null}
216
+ {errorMessage ? <Text style={styles.errorText}>{errorMessage}</Text> : null}
217
+ {infoMessage ? (
218
+ <Text
219
+ style={styles.infoText}
220
+ dataDetectorType="link"
221
+ selectable
222
+ >
223
+ {infoMessage}
224
+ </Text>
225
+ ) : null}
226
+
227
+ <TouchableOpacity
228
+ style={styles.importButton}
229
+ labelStyle={styles.importButtonLabel}
230
+ label={t('eventCode:importButton')}
231
+ onPress={() => {
232
+ handleImportButtonPress();
233
+ }}
234
+ >
235
+ <Headline style={styles.importButtonLabel} color={colors.buttonText}>
236
+ {t('timetable:importButton')}
237
+ </Headline>
238
+ </TouchableOpacity>
239
+ <View style={styles.buttonContainer}>
240
+ <TouchableOpacity
241
+ style={styles.deleteButtonContainer}
242
+ onPress={() => {
243
+ deleteTimetableCode();
244
+ setTimetableCodeInput('');
245
+ }}
246
+ >
247
+ <Text style={styles.deleteButton}>{t('timetable:deleteCode')}</Text>
248
+ <Ionicons name="trash-outline" size={20} color="red" />
249
+ </TouchableOpacity>
250
+ <TouchableOpacity
251
+ onPress={() => {
252
+ setFormVisible(false);
253
+ setErrorMessage('');
254
+ setInfoVisible(false);
255
+ }}
256
+ >
257
+ <Text style={styles.dismissButton}>{t("timetable:close")}</Text>
258
+ </TouchableOpacity>
259
+ </View>
260
+ </View>
261
+ );
262
+
263
+ return (
264
+ <SafeAreaView style={{ flex: 1, backgroundColor: whiteAppbar }}>
265
+ <AppbarComponent
266
+ rightAction={
267
+ <TouchableOpacity
268
+ onPress={
269
+ activeMode === 'day'
270
+ ? () => setSelectedDayModeDate(() => DateTime.now())
271
+ : () => setSelectedWeekModeISOWeekDate(() => DateTime.now().startOf('week').toISOWeekDate())
272
+ }
273
+ >
274
+ <Text style={{ color: whiteAppbar === colors.primary ? '#fff' : '#000' }}>{t("timetable:today")}</Text>
275
+ </TouchableOpacity>
276
+ }
277
+ style={{ backgroundColor: colors.primary /* whiteAppbar */ }}//hintergrundappbar
278
+ title={
279
+ activeMode === 'month'
280
+ ? `${months[activeHeaderDate.month - 1]}`
281
+ : `${months[activeHeaderDate.month - 1]} ${t('timetable:weekNumber', { kw: activeHeaderDate.weekNumber })}`
282
+ }
283
+ />
284
+ {tabView}
285
+ {formVisible && (
286
+ <KeyboardAvoidingView
287
+ behavior='position'
288
+ keyboardVerticalOffset={Platform.OS === 'android' ? 50 : 0}
289
+ >
290
+ {renderForm()}
291
+ </KeyboardAvoidingView>
292
+ )}
293
+
294
+ {!formVisible && (
295
+ <TouchableOpacity
296
+ style={styles.floatingButton}
297
+ onPress={() => setFormVisible(true)}
298
+ >
299
+ <Ionicons name="add-outline" size={40} color="#000" />
300
+ </TouchableOpacity>
301
+ )}
302
+
303
+ {
304
+ selectedEvent
305
+ ? <CourseDetailDialog
306
+ course={selectedEvent}
307
+ visible={selectedEvent ? true : false}
308
+ onClose={unsetSelectedEvent}
309
+ onDismiss={unsetSelectedEvent}
310
+ />
311
+ : null
312
+ }
313
+
314
+ </SafeAreaView>
315
+ );
316
+ }
317
+
318
+ const mapStateToProps = state => ({
319
+ settings: state.settingReducer,
320
+ });
321
+
322
+ export default connect(mapStateToProps, { onUpdateRefreshing })(withTranslation()(withTheme(TimetableViewCalendar)));
@@ -0,0 +1,117 @@
1
+ export default function (theme) {
2
+ return {
3
+ formContainer: {
4
+ backgroundColor: '#F6F7F7',
5
+ borderRadius: 10,
6
+ padding: 20,
7
+ elevation: 5,
8
+ shadowColor: '#000',
9
+ shadowOffset: { width: 0, height: 2 },
10
+ shadowOpacity: 0.3,
11
+ shadowRadius: 3,
12
+ left: '5%',
13
+ right: '5%',
14
+ position: 'absolute',
15
+ bottom: 100,
16
+ },
17
+ inputContainer: {
18
+ flex: 1,
19
+ width: '100%',
20
+ justifyContent: 'flex-end',
21
+ alignItems: 'center',
22
+ flexDirection: 'row',
23
+ marginBottom: 15,
24
+ },
25
+ infoIcon: {
26
+ width: '10%',
27
+ marginLeft: '3%',
28
+ },
29
+ codeInput: {
30
+ height: 50,
31
+ width: '87%',
32
+ borderColor: '#ddd',
33
+ borderWidth: 1,
34
+ borderRadius: 8,
35
+ paddingLeft: 10,
36
+ },
37
+ checkboxContainer: {
38
+ flexDirection: 'row',
39
+ alignItems: 'center',
40
+ marginBottom: 20,
41
+ },
42
+ checkboxLabel: {
43
+ marginLeft: 10,
44
+ fontSize: 16,
45
+ },
46
+ buttonContainer: {
47
+ marginTop: 20,
48
+ justifyContent: 'space-between',
49
+ alignItems: 'center',
50
+ flexDirection: 'row',
51
+ },
52
+ dismissButton: {
53
+ color: '#007bff',
54
+ textAlign: 'right',
55
+ fontWeight: 'bold',
56
+ fontSize: 16,
57
+ },
58
+ deleteButtonContainer: {
59
+ flexDirection: 'row',
60
+ },
61
+ deleteButton: {
62
+ color: 'red',
63
+ fontWeight: 'bold',
64
+ textAlign: 'left',
65
+ fontSize: 16,
66
+ marginRight: 3,
67
+ },
68
+ floatingButton: {
69
+ position: 'absolute',
70
+ bottom: 20,
71
+ right: 20,
72
+ width: 60,
73
+ height: 60,
74
+ borderRadius: 40,
75
+ backgroundColor: '#fff',
76
+ justifyContent: 'center',
77
+ alignItems: 'center',
78
+ shadowColor: '#000',
79
+ shadowOffset: { width: 0, height: 2 },
80
+ shadowOpacity: 0.3,
81
+ shadowRadius: 3,
82
+ elevation: 5,
83
+ },
84
+ importButton: {
85
+ width: '100%',
86
+ flexDirection: 'row',
87
+ flexWrap: 'wrap',
88
+ justifyContent: 'center',
89
+ alignItems: 'center',
90
+ marginTop: 10,
91
+ padding: theme.paddings.small,
92
+ flex: 1,
93
+ backgroundColor: theme.colors.primary,
94
+ borderBottomRightRadius: 10,
95
+ borderBottomLeftRadius: 10,
96
+ borderTopRightRadius: 10,
97
+ borderTopLeftRadius: 10
98
+
99
+ },
100
+ importButtonLabel: {
101
+ color: theme.colors.messages.noticeText,
102
+ ...theme.fonts.medium,
103
+ fontSize: theme.fontSizes.xl,
104
+ lineHeight: theme.lineHeights.l,
105
+ marginLeft: theme.paddings.small
106
+ },
107
+ errorText: {
108
+ color: 'red',
109
+ marginLeft: 5,
110
+ marginBottom: 10,
111
+ },
112
+ infoText: {
113
+ color: 'black',
114
+ marginLeft: 5,
115
+ }
116
+ };
117
+ };