skolplattformen-backup/apps/skolplattformen-sthlm/components/daySummary.component.tsx

80 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-10-05 15:44:14 +00:00
import { Child } from '@skolplattformen/api-skolplattformen'
import { useTimetable } from '@skolplattformen/hooks'
2021-07-01 23:01:49 +00:00
import { StyleService, Text, useStyleSheet } from '@ui-kitten/components'
import moment, { Moment } from 'moment'
2021-09-12 20:29:26 +00:00
import React from 'react'
2021-07-01 23:01:49 +00:00
import { View } from 'react-native'
import { LanguageService } from '../services/languageService'
import { translate } from '../utils/translation'
interface DaySummaryProps {
child: Child
2021-08-31 19:54:56 +00:00
date?: Moment
2021-07-01 23:01:49 +00:00
}
2021-08-31 19:54:56 +00:00
export const DaySummary = ({ child, date = moment() }: DaySummaryProps) => {
2021-07-01 23:01:49 +00:00
const styles = useStyleSheet(themedStyles)
const [year, week] = [moment().isoWeekYear(), moment().isoWeek()]
const { data: weekLessons } = useTimetable(
child,
week,
year,
LanguageService.getLanguageCode()
)
const lessons = weekLessons
.filter((lesson) => lesson.dayOfWeek === date.isoWeekday())
.sort((a, b) => a.dateStart.localeCompare(b.dateStart))
if (lessons.length <= 0) {
return null
}
2021-08-31 19:54:56 +00:00
const gymBag = lessons.some((lesson) => lesson.code === 'IDH')
2021-07-01 23:01:49 +00:00
return (
2021-09-12 20:29:26 +00:00
<View>
<View style={styles.summary}>
<View style={styles.part}>
<View>
<Text category="c2" style={styles.label}>
{translate('schedule.start')}
</Text>
<Text category="h5">{lessons[0].timeStart.slice(0, 5)} - </Text>
</View>
</View>
2021-09-12 20:29:26 +00:00
<View style={styles.part}>
<View>
<Text category="c2" style={styles.label}>
{translate('schedule.end')}
</Text>
<Text category="h5">
{lessons[lessons.length - 1].timeEnd.slice(0, 5)}
</Text>
</View>
</View>
</View>
2021-09-12 20:29:26 +00:00
<Text category="s2">
{gymBag
? ` 🤼‍♀️ ${translate('schedule.gymBag', {
defaultValue: 'Gympapåse',
})}`
: ''}
</Text>
</View>
2021-07-01 23:01:49 +00:00
)
}
const themedStyles = StyleService.create({
part: {
flexDirection: 'column',
},
2021-07-01 23:01:49 +00:00
summary: {
flexDirection: 'row',
},
label: {
marginTop: 10,
},
2021-07-01 23:01:49 +00:00
})