2021-04-09 09:47:35 +00:00
|
|
|
import {
|
|
|
|
List,
|
|
|
|
ListItem,
|
|
|
|
ViewPager,
|
|
|
|
Text,
|
|
|
|
TabBar,
|
|
|
|
Tab,
|
|
|
|
} from '@ui-kitten/components'
|
2021-04-30 06:08:08 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2021-04-25 19:40:45 +00:00
|
|
|
import moment from 'moment'
|
2021-04-09 09:47:35 +00:00
|
|
|
import { StyleSheet, View } from 'react-native'
|
2021-04-25 19:40:45 +00:00
|
|
|
import { useMenu, useTimetable } from '@skolplattformen/api-hooks'
|
2021-04-28 19:22:40 +00:00
|
|
|
import { TimetableEntry, Child, MenuItem } from '@skolplattformen/embedded-api'
|
2021-04-27 13:26:50 +00:00
|
|
|
import { LanguageService } from '../services/languageService'
|
2021-04-28 12:43:38 +00:00
|
|
|
import { translate } from '../utils/translation'
|
2021-04-09 09:47:35 +00:00
|
|
|
|
2021-04-25 19:16:24 +00:00
|
|
|
interface WeekProps {
|
|
|
|
child: Child
|
|
|
|
}
|
|
|
|
|
|
|
|
interface LessonListProps {
|
|
|
|
lessons: TimetableEntry[]
|
|
|
|
header: string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface DayProps {
|
|
|
|
weekDay: string
|
2021-04-28 19:22:40 +00:00
|
|
|
lunch?: MenuItem
|
2021-04-25 19:16:24 +00:00
|
|
|
lessons: TimetableEntry[]
|
|
|
|
}
|
2021-04-09 09:47:35 +00:00
|
|
|
|
2021-04-25 19:16:24 +00:00
|
|
|
const LessonList = ({ lessons, header }: LessonListProps) => (
|
2021-04-09 09:47:35 +00:00
|
|
|
<List
|
2021-04-25 19:16:24 +00:00
|
|
|
style={styles.part}
|
2021-04-09 09:47:35 +00:00
|
|
|
data={lessons}
|
2021-04-11 19:50:00 +00:00
|
|
|
ListHeaderComponent={() => (
|
|
|
|
<Text category="c1" style={styles.header}>
|
|
|
|
{header}
|
|
|
|
</Text>
|
|
|
|
)}
|
2021-04-27 07:45:34 +00:00
|
|
|
renderItem={({
|
|
|
|
item: { id, name, timeStart, timeEnd, teacher, location },
|
|
|
|
}) => (
|
2021-04-09 09:47:35 +00:00
|
|
|
<ListItem
|
|
|
|
key={id}
|
|
|
|
style={styles.item}
|
2021-04-27 07:45:34 +00:00
|
|
|
title={name}
|
2021-04-25 11:54:18 +00:00
|
|
|
description={`${timeStart.slice(0, 5)}-${timeEnd.slice(0, 5)} ${
|
2021-04-27 07:45:34 +00:00
|
|
|
location ? `(${location})` : ''
|
2021-04-25 11:54:18 +00:00
|
|
|
} ${teacher}`}
|
2021-04-09 09:47:35 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
2021-04-25 19:40:45 +00:00
|
|
|
export const Day = ({ weekDay, lunch, lessons }: DayProps) =>
|
2021-04-25 19:16:24 +00:00
|
|
|
lessons.length ? (
|
|
|
|
<View style={styles.tab} key={weekDay}>
|
|
|
|
<View style={styles.summary}>
|
2021-04-25 19:40:45 +00:00
|
|
|
<Text category="c1" style={styles.startTime}>
|
2021-04-28 13:35:32 +00:00
|
|
|
{translate('schedule.start', { defaultValue: 'Börjar' })}
|
2021-04-25 19:16:24 +00:00
|
|
|
</Text>
|
|
|
|
<Text category="h4">{lessons[0].timeStart.slice(0, 5)}</Text>
|
2021-04-25 20:03:56 +00:00
|
|
|
<Text category="c1" style={styles.lunchLabel}>
|
2021-04-28 13:35:32 +00:00
|
|
|
{translate('schedule.lunch', { defaultValue: 'Lunch' })}
|
2021-04-25 20:03:56 +00:00
|
|
|
</Text>
|
2021-04-25 20:20:34 +00:00
|
|
|
<Text category="c2" style={styles.lunch}>
|
2021-04-28 19:22:40 +00:00
|
|
|
{lunch?.description}
|
2021-04-25 20:20:34 +00:00
|
|
|
</Text>
|
2021-04-25 20:03:56 +00:00
|
|
|
<Text category="c1" style={styles.endTime}>
|
2021-04-28 13:35:32 +00:00
|
|
|
{translate('schedule.end', { defaultValue: 'Slutar' })}
|
2021-04-25 20:03:56 +00:00
|
|
|
</Text>
|
2021-04-25 19:16:24 +00:00
|
|
|
<Text category="h4">
|
|
|
|
{lessons[lessons.length - 1].timeEnd.slice(0, 5)}
|
|
|
|
</Text>
|
|
|
|
<Text category="c2">
|
|
|
|
{lessons.some((lesson) => lesson.code === 'IDH')
|
2021-04-28 13:35:32 +00:00
|
|
|
? `🤼♀️ ${translate('schedule.gymBag', {
|
|
|
|
defaultValue: 'Gympapåse',
|
|
|
|
})}`
|
2021-04-25 19:16:24 +00:00
|
|
|
: ''}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<LessonList
|
|
|
|
header="FM"
|
|
|
|
lessons={lessons.filter(({ timeStart }) => timeStart < '12:00')}
|
|
|
|
/>
|
|
|
|
<LessonList
|
|
|
|
header="EM"
|
|
|
|
lessons={lessons.filter(({ timeStart }) => timeStart >= '12:00')}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
) : null
|
|
|
|
|
|
|
|
export const Week = ({ child }: WeekProps) => {
|
2021-04-27 13:26:50 +00:00
|
|
|
moment.locale(LanguageService.getLanguageCode())
|
|
|
|
const days = moment.weekdaysShort().slice(1, 6)
|
2021-04-30 06:08:08 +00:00
|
|
|
const [selectedIndex, setSelectedIndex] = useState(0)
|
2021-04-25 19:16:24 +00:00
|
|
|
const [year, week] = [moment().isoWeekYear(), moment().isoWeek()]
|
2021-04-28 12:28:21 +00:00
|
|
|
const { data: lessons } = useTimetable(
|
|
|
|
child,
|
|
|
|
week,
|
|
|
|
year,
|
|
|
|
LanguageService.getLanguageCode()
|
|
|
|
)
|
2021-04-25 19:40:45 +00:00
|
|
|
const { data: menu } = useMenu(child)
|
2021-04-21 21:57:07 +00:00
|
|
|
|
2021-04-30 06:08:08 +00:00
|
|
|
useEffect(() => {
|
2021-04-30 06:53:48 +00:00
|
|
|
const updatedSelectedIndex = Math.min(moment().isoWeekday() - 1, 5)
|
|
|
|
setSelectedIndex(updatedSelectedIndex)
|
2021-04-30 06:08:08 +00:00
|
|
|
}, [lessons])
|
|
|
|
|
2021-04-09 09:47:35 +00:00
|
|
|
return (
|
2021-04-11 19:50:00 +00:00
|
|
|
<View style={styles.view}>
|
2021-04-09 09:47:35 +00:00
|
|
|
<TabBar
|
|
|
|
selectedIndex={selectedIndex}
|
|
|
|
onSelect={(index) => setSelectedIndex(index)}
|
|
|
|
>
|
2021-04-25 19:16:24 +00:00
|
|
|
{days.map((weekDay) => (
|
|
|
|
<Tab key={weekDay} title={weekDay} />
|
2021-04-09 09:47:35 +00:00
|
|
|
))}
|
|
|
|
</TabBar>
|
|
|
|
|
2021-04-25 19:16:24 +00:00
|
|
|
<ViewPager
|
|
|
|
selectedIndex={selectedIndex}
|
|
|
|
style={styles.pager}
|
|
|
|
onSelect={(index) => setSelectedIndex(index)}
|
|
|
|
>
|
2021-04-28 19:22:40 +00:00
|
|
|
{days.map((weekDay, index) => (
|
2021-04-25 19:16:24 +00:00
|
|
|
<Day
|
2021-04-25 19:40:45 +00:00
|
|
|
key={weekDay}
|
2021-04-25 19:16:24 +00:00
|
|
|
weekDay={weekDay}
|
2021-04-28 19:22:40 +00:00
|
|
|
lunch={menu[index] || {}}
|
2021-04-25 19:40:45 +00:00
|
|
|
lessons={lessons
|
|
|
|
.filter((lesson) => days[lesson.dayOfWeek - 1] === weekDay)
|
|
|
|
.sort((a, b) => a.dateStart.localeCompare(b.dateStart))}
|
2021-04-25 19:16:24 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ViewPager>
|
2021-04-09 09:47:35 +00:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2021-04-11 19:50:00 +00:00
|
|
|
view: {
|
|
|
|
backgroundColor: '#fafafa',
|
|
|
|
},
|
2021-04-11 20:02:30 +00:00
|
|
|
part: {
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
width: '33%',
|
|
|
|
},
|
2021-04-09 09:47:35 +00:00
|
|
|
tab: {
|
|
|
|
flexDirection: 'row',
|
2021-04-12 19:39:29 +00:00
|
|
|
padding: 0,
|
2021-04-09 09:47:35 +00:00
|
|
|
},
|
|
|
|
item: {
|
2021-04-11 20:02:30 +00:00
|
|
|
height: 45,
|
|
|
|
backgroundColor: 'white',
|
2021-04-11 19:50:00 +00:00
|
|
|
paddingHorizontal: 0,
|
2021-04-11 20:02:30 +00:00
|
|
|
borderRadius: 2,
|
|
|
|
margin: 2,
|
2021-04-11 20:04:59 +00:00
|
|
|
width: '90%',
|
2021-04-09 09:47:35 +00:00
|
|
|
},
|
|
|
|
time: {
|
|
|
|
color: '#333',
|
|
|
|
fontSize: 9,
|
|
|
|
},
|
|
|
|
dayTab: {
|
|
|
|
textAlign: 'left',
|
|
|
|
},
|
2021-04-11 19:50:00 +00:00
|
|
|
summary: {
|
2021-04-11 20:02:30 +00:00
|
|
|
paddingRight: 20,
|
2021-04-11 19:50:00 +00:00
|
|
|
paddingLeft: 2,
|
|
|
|
},
|
2021-04-25 19:40:45 +00:00
|
|
|
startTime: {
|
2021-04-25 19:16:24 +00:00
|
|
|
paddingBottom: 2,
|
|
|
|
},
|
2021-04-25 20:03:56 +00:00
|
|
|
lunchLabel: {
|
2021-04-25 19:40:45 +00:00
|
|
|
paddingTop: 10,
|
|
|
|
paddingBottom: 2,
|
|
|
|
},
|
2021-04-25 20:03:56 +00:00
|
|
|
lunch: {
|
|
|
|
width: 100,
|
|
|
|
},
|
2021-04-25 19:40:45 +00:00
|
|
|
endTime: {
|
|
|
|
paddingTop: 10,
|
|
|
|
},
|
2021-04-11 19:50:00 +00:00
|
|
|
pager: {
|
|
|
|
margin: 10,
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
paddingLeft: 8,
|
2021-04-12 19:39:29 +00:00
|
|
|
},
|
2021-04-09 09:47:35 +00:00
|
|
|
})
|