skolplattformen-backup/packages/app/components/calendar.component.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

import { useCalendar } from '@skolplattformen/api-hooks'
2021-03-26 08:38:15 +00:00
import { CalendarItem } from '@skolplattformen/embedded-api'
2021-02-20 08:38:08 +00:00
import { Divider, List, ListItem, Text } from '@ui-kitten/components'
2021-01-30 17:46:31 +00:00
import moment from 'moment'
2021-02-20 08:38:08 +00:00
import React from 'react'
import { ListRenderItemInfo, StyleSheet, View } from 'react-native'
import { Colors, Typography } from '../styles'
import { useChild } from './childContext.component'
2021-02-20 08:38:08 +00:00
import { CalendarOutlineIcon } from './icon.component'
2021-04-07 22:53:31 +00:00
import { Week } from './week.component'
import { SaveToCalendar } from './saveToCalendar.component'
2021-01-30 17:46:31 +00:00
2021-02-20 08:38:08 +00:00
export const Calendar = () => {
const child = useChild()
2021-02-20 08:38:08 +00:00
const { data } = useCalendar(child)
2020-12-07 20:59:14 +00:00
return !data?.length ? (
<View>
<Week child={child} />
</View>
) : (
2021-04-07 22:53:31 +00:00
<View>
2021-04-21 21:57:07 +00:00
<Week child={child} />
2021-04-07 22:53:31 +00:00
<List
data={data.sort((a, b) =>
a.startDate && b.startDate
? a.startDate.localeCompare(b.startDate)
: 0
)}
ItemSeparatorComponent={Divider}
renderItem={({ item }: ListRenderItemInfo<CalendarItem>) => (
<ListItem
disabled={true}
title={`${item.title}`}
2021-04-28 12:10:14 +00:00
description={(props) => (
<Text style={[props?.style, styles.description]}>
{`${moment(item.startDate).format('YYYY-MM-DD')} (${moment(
item.startDate
).fromNow()})`}
</Text>
)}
2021-04-07 22:53:31 +00:00
accessoryLeft={CalendarOutlineIcon}
accessoryRight={() => <SaveToCalendar event={item} />}
/>
)}
style={styles.container}
/>
</View>
2021-02-20 08:38:08 +00:00
)
2020-12-22 22:29:42 +00:00
}
2020-12-07 20:59:14 +00:00
const styles = StyleSheet.create({
emptyStateImage: {
height: 200,
width: '100%',
},
2020-12-15 01:38:36 +00:00
container: {
height: '100%',
width: '100%',
2020-12-15 01:38:36 +00:00
},
description: {
...Typography.fontSize.xs,
color: Colors.neutral.gray500,
},
2020-12-31 03:23:03 +00:00
})