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

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2021-10-05 15:44:14 +00:00
import { Notification as NotificationType } from '@skolplattformen/api-skolplattformen'
import { StyleService, Text, useStyleSheet } from '@ui-kitten/components'
import moment from 'moment'
2021-02-20 08:38:08 +00:00
import React from 'react'
2021-09-12 20:29:26 +00:00
import { TouchableOpacity, View } from 'react-native'
import { Layout, Sizing, Typography } from '../styles'
import { ModalWebView } from './modalWebView.component'
2021-01-26 11:02:24 +00:00
2021-03-26 08:38:15 +00:00
interface NotificationProps {
item: NotificationType
}
export const Notification = ({ item }: NotificationProps) => {
const styles = useStyleSheet(themedStyles)
2021-02-20 08:38:08 +00:00
const [isOpen, setIsOpen] = React.useState(false)
2021-01-26 11:02:24 +00:00
const open = () => setIsOpen(true)
const close = () => setIsOpen(false)
const date = item.dateModified || item.dateCreated
const displayDate = date ? moment(date).fromNow() : null
2021-10-06 20:47:50 +00:00
const sharedCookiesEnabled = Boolean(
item.url && item.url.startsWith('https://start.unikum.net/')
)
2021-01-26 11:02:24 +00:00
return (
<>
2021-09-12 20:29:26 +00:00
<TouchableOpacity onPress={open}>
<View style={styles.card}>
<View>
2021-02-19 10:42:13 +00:00
<Text style={styles.title}>{item.sender}</Text>
<Text style={styles.subtitle}>
{item.category ? item.category : ''}
2021-02-19 10:42:13 +00:00
{item.category && displayDate ? ' • ' : ''}
{displayDate ? displayDate : ''}
</Text>
2021-01-26 11:02:24 +00:00
</View>
<Text>{item.message}</Text>
</View>
2021-09-12 20:29:26 +00:00
</TouchableOpacity>
{isOpen && (
<ModalWebView
url={item.url}
onClose={close}
sharedCookiesEnabled={sharedCookiesEnabled}
/>
)}
2021-01-26 11:02:24 +00:00
</>
)
}
const themedStyles = StyleService.create({
2021-01-26 11:02:24 +00:00
card: {
...Layout.flex.full,
borderRadius: 15,
paddingVertical: Sizing.t4,
paddingHorizontal: Sizing.t4,
marginBottom: Sizing.t3,
backgroundColor: 'background-basic-color-1',
2021-02-19 10:42:13 +00:00
},
title: {
...Typography.header,
marginBottom: Sizing.t1,
2021-02-19 10:42:13 +00:00
},
subtitle: {
...Typography.fontSize.xs,
color: 'text-hint-color',
marginBottom: Sizing.t2,
2021-01-26 11:02:24 +00:00
},
})