Skip to content

Commit

Permalink
fix(core): tasks UpdatedTimeAgo should be a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Dec 11, 2024
1 parent 17cfc6c commit 94ce4a6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
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

0 comments on commit 94ce4a6

Please sign in to comment.