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

68 lines
1.9 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'
import {
Divider,
List,
ListItem,
Text,
StyleService,
useStyleSheet,
} 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, View } from 'react-native'
import { Typography } from '../styles'
import { useChild } from './childContext.component'
2021-02-20 08:38:08 +00:00
import { CalendarOutlineIcon } from './icon.component'
import { SaveToCalendar } from './saveToCalendar.component'
import { Week } from './week.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)
const styles = useStyleSheet(themedStyles)
2020-12-07 20:59:14 +00:00
return (
<View style={styles.container}>
<Week child={child} />
{data && data.length > 0 && (
<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}`}
description={(props) => (
<Text style={[props?.style, styles.description]}>
2021-05-10 09:54:25 +00:00
{`${moment(item.startDate).format('dddd')} ${moment(
item.startDate
2021-05-10 09:54:25 +00:00
).format('ll')} (${moment(item.startDate).fromNow()})`}
</Text>
)}
accessoryLeft={CalendarOutlineIcon}
accessoryRight={() => <SaveToCalendar event={item} />}
/>
)}
/>
)}
2021-04-07 22:53:31 +00:00
</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 themedStyles = StyleService.create({
2020-12-15 01:38:36 +00:00
container: {
2021-05-10 09:43:43 +00:00
backgroundColor: 'background-basic-color-2',
height: '100%',
width: '100%',
2020-12-15 01:38:36 +00:00
},
description: {
...Typography.fontSize.xs,
color: 'color-basic-600',
},
2020-12-31 03:23:03 +00:00
})