mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
refactor(ui): add isDateSet util function
Signed-off-by: zacaj <zacaj@zacaj.com>
This commit is contained in:
parent
e97298bdc6
commit
a3013a2750
@ -1,10 +1,11 @@
|
||||
import React from 'react'
|
||||
import { isDateSet } from '../utils/validations'
|
||||
import { DateField as RADateField } from 'react-admin'
|
||||
|
||||
export const DateField = (props) => {
|
||||
const { record, source } = props
|
||||
const value = record?.[source]
|
||||
if (value === '0001-01-01T00:00:00Z' || value === null) return null
|
||||
if (!isDateSet(value)) return null
|
||||
return <RADateField {...props} />
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
||||
import { useToggleLove } from './useToggleLove'
|
||||
import { useRecordContext } from 'react-admin'
|
||||
import config from '../config'
|
||||
import { isDateSet } from '../utils/validations'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
love: {
|
||||
@ -49,7 +50,7 @@ export const LoveButton = ({
|
||||
disabled={disabled || loading || record.missing}
|
||||
className={classes.love}
|
||||
title={
|
||||
record.starredAt && record.starredAt !== '0001-01-01T00:00:00Z'
|
||||
isDateSet(record.starredAt)
|
||||
? new Date(record.starredAt).toLocaleString()
|
||||
: undefined
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import React, { useCallback } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import Rating from '@material-ui/lab/Rating'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import { isDateSet } from '../utils/validations'
|
||||
import StarBorderIcon from '@material-ui/icons/StarBorder'
|
||||
import clsx from 'clsx'
|
||||
import { useRating } from './useRating'
|
||||
@ -48,7 +49,7 @@ export const RatingField = ({
|
||||
<span
|
||||
onClick={(e) => stopPropagation(e)}
|
||||
title={
|
||||
record.ratedAt && record.ratedAt !== '0001-01-01T00:00:00Z'
|
||||
isDateSet(record.ratedAt)
|
||||
? new Date(record.ratedAt).toLocaleString()
|
||||
: undefined
|
||||
}
|
||||
|
||||
@ -10,3 +10,16 @@ export const urlValidate = (value) => {
|
||||
return 'ra.validation.url'
|
||||
}
|
||||
}
|
||||
|
||||
export function isDateSet(date) {
|
||||
if (!date) {
|
||||
return false
|
||||
}
|
||||
if (typeof date === 'string') {
|
||||
return date !== '0001-01-01T00:00:00Z'
|
||||
}
|
||||
if (date instanceof Date) {
|
||||
return date.toISOString() !== '0001-01-01T00:00:00Z'
|
||||
}
|
||||
return !!date
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user