2020-12-16 15:39:22 +00:00
|
|
|
import React from 'react'
|
2021-02-10 10:08:17 +00:00
|
|
|
import {StyleSheet} from 'react-native'
|
2021-01-26 11:02:24 +00:00
|
|
|
import {
|
|
|
|
TopNavigation,
|
|
|
|
TopNavigationAction,
|
|
|
|
Tab,
|
2021-02-10 10:08:17 +00:00
|
|
|
TabBar,
|
2021-01-26 11:02:24 +00:00
|
|
|
Layout,
|
|
|
|
Text,
|
|
|
|
Icon,
|
|
|
|
} from '@ui-kitten/components'
|
2021-02-07 16:14:45 +00:00
|
|
|
import {DateTime} from 'luxon'
|
|
|
|
import {NewsList} from './newsList.component'
|
|
|
|
import {Calendar} from './calendar.component'
|
|
|
|
import {Classmates} from './classmates.component'
|
|
|
|
import {NotificationsList} from './notificationsList.component'
|
|
|
|
import {SafeAreaView} from 'react-native-safe-area-context'
|
2021-01-26 11:02:24 +00:00
|
|
|
import {
|
|
|
|
useNotifications,
|
|
|
|
useNews,
|
|
|
|
useClassmates,
|
|
|
|
useCalendar,
|
|
|
|
useSchedule,
|
2021-02-07 16:14:45 +00:00
|
|
|
} from '@skolplattformen/api-hooks'
|
2021-02-10 10:08:17 +00:00
|
|
|
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'
|
2020-12-07 20:59:14 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const {Navigator, Screen} = createMaterialTopTabNavigator()
|
|
|
|
|
|
|
|
const ChildContext = React.createContext({})
|
|
|
|
const useChild = () => React.useContext(ChildContext)
|
|
|
|
|
|
|
|
const NewsScreen = () => {
|
|
|
|
const child = useChild()
|
|
|
|
const {data: news} = useNews(child)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<NewsList news={news} />
|
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const NotificationsScreen = () => {
|
|
|
|
const child = useChild()
|
2021-02-07 16:14:45 +00:00
|
|
|
const {data: notifications, status: notificationsStatus} = useNotifications(
|
|
|
|
child,
|
|
|
|
)
|
2021-02-10 10:08:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<NotificationsList
|
|
|
|
notifications={notifications}
|
|
|
|
status={notificationsStatus}
|
|
|
|
/>
|
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const CalendarScreen = () => {
|
|
|
|
const child = useChild()
|
|
|
|
const {data: calendar} = useCalendar(child)
|
|
|
|
const {data: schedule} = useSchedule(
|
2021-02-07 16:14:45 +00:00
|
|
|
child,
|
|
|
|
DateTime.local(),
|
|
|
|
DateTime.local().plus({days: 7}),
|
|
|
|
)
|
2020-12-07 20:59:14 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<Calendar calendar={[...(calendar ?? []), ...(schedule ?? [])]} />
|
|
|
|
</Layout>
|
2020-12-16 22:07:15 +00:00
|
|
|
)
|
2021-02-10 10:08:17 +00:00
|
|
|
}
|
2020-12-22 01:12:08 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const ClassmatesScreen = () => {
|
|
|
|
const child = useChild()
|
|
|
|
const {data: classmates} = useClassmates(child)
|
2020-12-22 01:12:08 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<Classmates classmates={classmates} />
|
|
|
|
</Layout>
|
2020-12-16 22:07:15 +00:00
|
|
|
)
|
2021-02-10 10:08:17 +00:00
|
|
|
}
|
2020-12-30 15:11:42 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const TabTitle = ({style, children}) => (
|
|
|
|
<Text adjustsFontSizeToFit numberOfLines={1} style={style}>
|
|
|
|
{children}
|
|
|
|
</Text>
|
|
|
|
)
|
2021-02-08 20:13:13 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const NewsIcon = (props) => <Icon {...props} name="activity-outline" />
|
|
|
|
const NotificationsIcon = (props) => (
|
|
|
|
<Icon {...props} name="alert-circle-outline" />
|
|
|
|
)
|
|
|
|
const CalendarIcon = (props) => <Icon {...props} name="calendar-outline" />
|
|
|
|
const ClassIcon = (props) => <Icon {...props} name="people-outline" />
|
2020-12-16 22:07:15 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const TopTabBar = ({navigation, state}) => (
|
|
|
|
<TabBar
|
|
|
|
selectedIndex={state.index}
|
|
|
|
onSelect={(index) => navigation.navigate(state.routeNames[index])}>
|
|
|
|
<Tab
|
|
|
|
title={(props) => <TabTitle {...props}>Nyheter</TabTitle>}
|
|
|
|
icon={NewsIcon}
|
|
|
|
/>
|
|
|
|
<Tab
|
|
|
|
title={(props) => <TabTitle {...props}>Notifieringar</TabTitle>}
|
|
|
|
icon={NotificationsIcon}
|
|
|
|
/>
|
|
|
|
<Tab
|
|
|
|
title={(props) => <TabTitle {...props}>Kalender</TabTitle>}
|
|
|
|
icon={CalendarIcon}
|
|
|
|
/>
|
|
|
|
<Tab
|
|
|
|
title={(props) => <TabTitle {...props}>Klassen</TabTitle>}
|
|
|
|
icon={ClassIcon}
|
|
|
|
/>
|
|
|
|
</TabBar>
|
|
|
|
)
|
2020-12-22 01:12:08 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const TabNavigator = () => (
|
|
|
|
<Navigator tabBar={(props) => <TopTabBar {...props} />}>
|
|
|
|
<Screen name="Nyheter" component={NewsScreen} />
|
|
|
|
<Screen name="Notifieringar" component={NotificationsScreen} />
|
|
|
|
<Screen name="Kalender" component={CalendarScreen} />
|
|
|
|
<Screen name="Klassen" component={ClassmatesScreen} />
|
|
|
|
</Navigator>
|
|
|
|
)
|
2020-12-22 01:12:08 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
export const Child = ({route, navigation}) => {
|
|
|
|
const {child, color} = route.params
|
2021-01-30 13:07:44 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const BackIcon = (props) => <Icon {...props} name="arrow-back" />
|
|
|
|
|
|
|
|
const BackAction = () => (
|
|
|
|
<TopNavigationAction icon={BackIcon} onPress={navigateBack} />
|
2021-01-26 11:02:24 +00:00
|
|
|
)
|
2020-12-22 01:12:08 +00:00
|
|
|
|
2021-02-10 10:08:17 +00:00
|
|
|
const navigateBack = () => {
|
|
|
|
navigation.goBack()
|
|
|
|
}
|
|
|
|
|
2020-12-16 15:39:22 +00:00
|
|
|
return (
|
2021-02-10 10:08:17 +00:00
|
|
|
<SafeAreaView style={{...styles.wrap, color}}>
|
|
|
|
<ChildContext.Provider value={child}>
|
|
|
|
<TopNavigation
|
|
|
|
title={child.name.split('(')[0]}
|
|
|
|
alignment="center"
|
|
|
|
accessoryLeft={BackAction}
|
|
|
|
style={styles.topBar}
|
|
|
|
/>
|
|
|
|
<TabNavigator />
|
|
|
|
</ChildContext.Provider>
|
2020-12-16 15:39:22 +00:00
|
|
|
</SafeAreaView>
|
|
|
|
)
|
|
|
|
}
|
2020-12-07 20:59:14 +00:00
|
|
|
|
2020-12-16 15:39:22 +00:00
|
|
|
const styles = StyleSheet.create({
|
2021-02-10 10:08:17 +00:00
|
|
|
wrap: {
|
2021-02-07 16:14:45 +00:00
|
|
|
backgroundColor: '#fff',
|
2021-02-10 10:08:17 +00:00
|
|
|
flex: 1,
|
2020-12-19 00:16:35 +00:00
|
|
|
},
|
2021-02-10 10:08:17 +00:00
|
|
|
topBar: {
|
|
|
|
backgroundColor: '#fff',
|
2020-12-16 15:39:22 +00:00
|
|
|
},
|
2020-12-22 01:12:08 +00:00
|
|
|
backdrop: {
|
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
|
|
},
|
2021-02-07 16:14:45 +00:00
|
|
|
})
|