-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
117 lines (108 loc) · 3.15 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React, {useEffect, useState} from 'react';
import {
Appbar,
Card,
Paragraph,
Provider as PaperProvider,
Text,
Title,
} from 'react-native-paper';
import {SafeAreaProvider, SafeAreaView} from 'react-native-safe-area-context';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {Linking, FlatList} from 'react-native';
interface YomTov {
title: string;
date: string;
hebrew: string;
category: string;
memo: string;
link: string;
location: string;
}
function YomTovCard({yomTov}: {yomTov: YomTov}) {
return (
<Card style={{margin: 10}}>
<Card.Content>
<Title>{yomTov.title}</Title>
<Text>
{yomTov.date} - {generateDayOfWeek(yomTov.date)}
</Text>
<Text>{generateDaysUntil(yomTov.date)}</Text>
<Text>{yomTov.hebrew}</Text>
<Text>{yomTov.category}</Text>
<Paragraph>{yomTov.memo}</Paragraph>
<Text
onPress={() => Linking.openURL(yomTov.link)}
style={{color: 'teal'}}>
Learn more
</Text>
<Text>{yomTov.location}</Text>
</Card.Content>
</Card>
);
}
function YomTovList({yomTovs}: {yomTovs: YomTov[]}) {
return (
<SafeAreaView style={{flex: 1}}>
<FlatList
data={yomTovs}
renderItem={({item}) => <YomTovCard yomTov={item} />}
keyExtractor={(item, index) => index.toString()}
/>
</SafeAreaView>
);
}
function generateDaysUntil(date: string): string {
const currentDate = new Date();
let targetDate = new Date(date);
const difference = targetDate.getTime() - currentDate.getTime();
const days = Math.ceil(difference / (1000 * 3600 * 24));
return `Days until: ${days}`;
}
function generateDayOfWeek(date: string) {
const days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
];
const dateObj = new Date(date).getDay() + 1;
return days[dateObj];
}
function App() {
const [yomTovs, setYomTovs] = useState<YomTov[]>([]);
useEffect(() => {
const date = new Date();
const currentYear = date.getFullYear();
const currentMonth = (date.getMonth() + 1).toString().padStart(2, '0');
const currentDay = date.getDate().toString().padStart(2, '0');
const startDate = `${currentYear}-${currentMonth}-${currentDay}`;
const endDate = `${currentYear + 1}-${currentMonth}-01`;
(async () => {
try {
const response = await fetch(
`https://www.hebcal.com/hebcal?start=${startDate}&end=${endDate}&v=1&cfg=json&maj=on&min=on&mod=off&nx=on&month=x&ss=on&mf=on&c=off&s=off&D=off&d=off&o=off&F=off&myomi=off&leyning=off`,
);
const data = await response.json();
setYomTovs(data.items);
// await AsyncStorage.setItem('yomTovs', JSON.stringify(yomTovs));
} catch (error) {
console.error('Error getting holidays: ' + error);
}
})();
}, []);
return (
<SafeAreaProvider>
<PaperProvider>
<Appbar.Header>
<Appbar.Content title="Yom Tov Reminders" />
</Appbar.Header>
<YomTovList yomTovs={yomTovs} />
</PaperProvider>
</SafeAreaProvider>
);
}
export default App;