Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ fix: Add timestamp on newsroom #2800 #2820

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions web/components/src/FormattedDateTime/FormattedTime.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { HTMLAttributes } from 'react'
import { FormattedTime as ReactIntlTime } from 'react-intl'
import { StyledDate, TimeIcon } from './shared'
import styled from 'styled-components'

export type FormattedTimeProps = {
datetime: string
Expand All @@ -10,11 +9,6 @@ export type FormattedTimeProps = {
small?: boolean
} & HTMLAttributes<HTMLSpanElement>

const SmallText = styled.span<{ small?: boolean }>`
font-size: ${(props) => (props.small ? 'var(--typeScale-0)' : 'var(--typeScale-1)')};
margin-top: ${(props) => (props.small ? 'var(--space-3)' : '0')};
`

export const FormattedTime = ({
datetime,
icon = false,
Expand All @@ -26,7 +20,7 @@ export const FormattedTime = ({
return (
<StyledDate {...rest}>
{icon && <TimeIcon />}
<SmallText small={small}>
<span className={`${small ? 'text-2xs mt-1' : 'mt-0'}`}>
<time suppressHydrationWarning dateTime={datetime}>
<ReactIntlTime value={date} />
</time>
Expand All @@ -35,7 +29,7 @@ export const FormattedTime = ({
({date.toLocaleTimeString('es-NO', { timeZoneName: 'short' }).split(' ')[1]})
</span>
)}
</SmallText>
</span>
</StyledDate>
)
}
13 changes: 11 additions & 2 deletions web/templates/newsroom/NewsSections/NewsHeadliner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormattedDate } from '@components/FormattedDateTime'
import { FormattedDate, FormattedTime } from '@components/FormattedDateTime'
import { forwardRef, HTMLAttributes } from 'react'
import { BaseLink } from '@core/Link'
import { Typography } from '@core/Typography'
Expand Down Expand Up @@ -50,7 +50,16 @@ const NewsHeadliner = forwardRef<HTMLLIElement, NewsHeadlinerProps>(function New
</div>
)}
{publishDateTime && (
<FormattedDate datetime={publishDateTime} uppercase className="text-2xs font-normal leading-normal" />
<div>
<FormattedDate datetime={publishDateTime} uppercase className="text-2xs font-normal leading-normal" />
<span className="mx-2 text-2xs font-normal leading-normal pb-1">|</span>
<FormattedTime
small
timezone
datetime={publishDateTime}
className="text-2xs font-normal leading-normal pb-1"
/>
</div>
)}
{title && (
<Typography as="h2" variant="md" className="group-hover:underline">
Expand Down
17 changes: 15 additions & 2 deletions web/templates/newsroom/NewsSections/NewsItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormattedDate } from '@components/FormattedDateTime'
import { FormattedDate, FormattedTime } from '@components/FormattedDateTime'
import { forwardRef, HTMLAttributes } from 'react'
import { BaseLink } from '@core/Link'
import { Typography } from '@core/Typography'
Expand All @@ -24,7 +24,20 @@ const NewsItem = forwardRef<HTMLLIElement, NewsListItemProps>(function NewsItem(
<BaseLink href={slug} className="group flex justify-between gap-4 lg:gap-6">
<div className="max-w-[65%]">
{publishDateTime && (
<FormattedDate datetime={publishDateTime} uppercase className="text-2xs font-normal leading-normal pb-1" />
<div>
<FormattedDate
datetime={publishDateTime}
uppercase
className="text-2xs font-normal leading-normal pb-1"
/>
<span className="mx-2 text-2xs font-normal leading-normal pb-1">|</span>
<FormattedTime
small
timezone
datetime={publishDateTime}
className="text-2xs font-normal leading-normal pb-1"
/>
</div>
)}
{title && (
<Typography as="h2" variant="base" className="max-w-text text-pretty group-hover:underline">
Expand Down
Loading