mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { memo } from 'react'
|
|
import { Text } from 'react-native'
|
|
import {
|
|
NATIVE_CHAT_MESSAGE_FULL_TIME_FORMAT,
|
|
NATIVE_CHAT_MESSAGE_TIME_FORMAT
|
|
} from '../../../../../src/shared/native-chat/transcript/native-chat-message-time'
|
|
import { colors, typography } from '../../../theme/mobile-theme'
|
|
import { themedStyleSheet } from '../../../theme/themed-styles'
|
|
import { useMobileColorScheme } from '../../../theme/use-mobile-color-scheme'
|
|
import { scaledType } from './mobile-native-chat-message-styles'
|
|
|
|
let formatters: { time: Intl.DateTimeFormat; full: Intl.DateTimeFormat } | null = null
|
|
|
|
export const MobileNativeChatMessageTime = memo(function MobileNativeChatMessageTime({
|
|
timestamp,
|
|
fontScale
|
|
}: {
|
|
timestamp: number | null | undefined
|
|
fontScale: number
|
|
}): React.JSX.Element | null {
|
|
useMobileColorScheme()
|
|
const date = timestamp == null ? null : new Date(timestamp)
|
|
if (!date || Number.isNaN(date.getTime())) {
|
|
return null
|
|
}
|
|
formatters ??= {
|
|
time: new Intl.DateTimeFormat(undefined, NATIVE_CHAT_MESSAGE_TIME_FORMAT),
|
|
full: new Intl.DateTimeFormat(undefined, NATIVE_CHAT_MESSAGE_FULL_TIME_FORMAT)
|
|
}
|
|
return (
|
|
<Text
|
|
style={[styles.time, scaledType(typography.metaSize, fontScale, 5)]}
|
|
accessibilityLabel={formatters.full.format(date)}
|
|
>
|
|
{formatters.time.format(date)}
|
|
</Text>
|
|
)
|
|
})
|
|
|
|
const styles = themedStyleSheet(() => ({
|
|
time: {
|
|
color: colors.textMuted,
|
|
fontVariant: ['tabular-nums']
|
|
}
|
|
}))
|