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(core): tasks UpdatedTimeAgo should be a hook #8011

Merged
merged 1 commit into from
Dec 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Box, Flex, Text} from '@sanity/ui'
import {memo} from 'react'

import {Tooltip} from '../../../../ui-components'
import {getChangeDetails, NoWrap, UpdatedTimeAgo, UserName} from './helpers'
import {getChangeDetails, NoWrap, UserName, useUpdatedTimeAgo} from './helpers'
import {type FieldChange} from './helpers/parseTransactions'

interface EditedAtProps {
Expand All @@ -12,7 +12,7 @@ interface EditedAtProps {
export const EditedAt = memo(
function EditedAt(props: EditedAtProps) {
const {activity} = props
const {formattedDate, timeAgo} = UpdatedTimeAgo(activity.timestamp)
const {formattedDate, timeAgo} = useUpdatedTimeAgo(activity.timestamp)
const {icon, text, changeTo} = getChangeDetails(activity)

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Tooltip} from '../../../../ui-components'
import {useTranslation} from '../../../i18n'
import {useUser} from '../../../store'
import {tasksLocaleNamespace} from '../../i18n'
import {NoWrap, UpdatedTimeAgo} from './helpers'
import {NoWrap, useUpdatedTimeAgo} from './helpers'
import {ActivityItem} from './TasksActivityItem'

const UserSkeleton = styled(TextSkeleton)`
Expand All @@ -23,7 +23,7 @@ export const TasksActivityCreatedAt = memo(
function TasksActivityCreatedAt(props: TasksActivityCreatedAtProps) {
const {createdAt, authorId} = props
const [user, loading] = useUser(authorId)
const {timeAgo, formattedDate} = UpdatedTimeAgo(createdAt)
const {timeAgo, formattedDate} = useUpdatedTimeAgo(createdAt)
const {t} = useTranslation(tasksLocaleNamespace)
return (
<ActivityItem userId={authorId}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const NoWrap = styled.span`
white-space: nowrap;
`

export function UpdatedTimeAgo(timestamp: string) {
export function useUpdatedTimeAgo(timestamp: string) {
const date = new Date(timestamp)
const dateFormatter = useDateTimeFormat(DATE_FORMAT_OPTIONS)
const formattedDate = dateFormatter.format(date)
Expand Down
Loading