import { NavigationProp, useNavigation } from '@react-navigation/core' import { NativeStackNavigationOptions } from '@react-navigation/native-stack' import { Child } from '@skolplattformen/api' import { useApi, useChildList } from '@skolplattformen/hooks' import { Button, List, Spinner, StyleService, Text, TopNavigationAction, useStyleSheet, } from '@ui-kitten/components' import moment from 'moment' import React, { useCallback, useEffect, useState } from 'react' import { Image, ImageStyle, Linking, ListRenderItemInfo, View, } from 'react-native' import { defaultStackStyling } from '../design/navigationThemes' import AppStorage from '../services/appStorage' import { Layout as LayoutStyle, Sizing, Typography } from '../styles' import { translate } from '../utils/translation' import { ChildListItem } from './childListItem.component' import { RefreshIcon, SettingsIcon } from './icon.component' import { RootStackParamList } from './navigation.component' const colors = ['primary', 'success', 'info', 'warning', 'danger'] export const childenRouteOptions = (darkMode: boolean) => (): NativeStackNavigationOptions => { return { ...defaultStackStyling(darkMode), title: translate('children.title'), headerLargeTitle: true, headerLargeTitleShadowVisible: false, } } export const Children = () => { const styles = useStyleSheet(themedStyles) const navigation = useNavigation>() const { api } = useApi() const { data: childList, status, reload } = useChildList() const reloadChildren = useCallback(() => { reload() setUpdated(moment().toISOString()) }, [reload]) const [updatedAt, setUpdated] = useState('') const logout = useCallback(() => { AppStorage.clearTemporaryItems().then(() => api.logout()) }, [api]) useEffect(() => { navigation.setOptions({ headerLeft: () => { return ( navigation.navigate('Settings')} /> ) }, headerRight: () => { return ( reloadChildren()} accessibilityHint="Reload" accessibilityLabel="Reload" /> ) }, }) }, [navigation, reloadChildren]) // We need to skip safe area view here, due to the reason that it's adding a white border // when this view is actually lightgrey. Taking the padding top value from the use inset hook. return status === 'loaded' ? ( {translate('children.noKids_title')} {translate('children.noKids_description')} } renderItem={({ item: child, index }: ListRenderItemInfo) => ( )} /> ) : ( {status === 'error' ? ( {translate('children.loadingErrorHeading')} {translate('children.loadingErrorInformationText')} ) : ( {translate('general.loading')} )} ) } const themedStyles = StyleService.create({ topContainer: { ...LayoutStyle.flex.full, paddingBottom: 0, }, loading: { ...LayoutStyle.center, ...LayoutStyle.flex.full, }, loadingImage: { ...Sizing.aspectRatio(), }, loadingMessage: { ...LayoutStyle.mainAxis.center, ...LayoutStyle.flex.row, marginTop: Sizing.t2, }, loadingText: { marginLeft: Sizing.t5, }, errorButtons: { height: Sizing.screen.height * 0.2, width: Sizing.screen.width * 0.73, justifyContent: 'space-evenly', }, errorMessage: { height: Sizing.screen.height * 0.4, width: Sizing.screen.width * 0.73, justifyContent: 'space-evenly', alignItems: 'center', marginTop: Sizing.t2, }, errorText: { marginBottom: Sizing.t3, }, childList: { ...LayoutStyle.flex.full, }, childListContainer: { paddingVertical: Sizing.t4, paddingHorizontal: Sizing.t3, }, emptyState: { ...LayoutStyle.center, ...LayoutStyle.flex.full, paddingHorizontal: Sizing.t5, }, emptyStateDescription: { ...Typography.align.center, lineHeight: 21, marginTop: Sizing.t2, }, emptyStateImage: { ...Sizing.aspectRatio(0.8), marginTop: Sizing.t5, }, topNavigationTitle: { ...Typography.fontWeight.semibold, }, })