navidrome/ui/src/share/ShareList.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-01-20 04:52:55 +01:00
import {
Datagrid,
FunctionField,
List,
NumberField,
2023-01-24 02:11:46 +01:00
SimpleList,
2023-01-20 04:52:55 +01:00
TextField,
2023-01-24 02:11:46 +01:00
useTranslate,
2023-01-20 04:52:55 +01:00
} from 'react-admin'
import React from 'react'
import { DateField, QualityInfo } from '../common'
import { shareUrl } from '../utils'
2023-01-24 02:11:46 +01:00
import { Link, useMediaQuery } from '@material-ui/core'
import config from '../config'
2023-01-20 04:52:55 +01:00
export const FormatInfo = ({ record, size }) => {
const r = { suffix: record.format, bitRate: record.maxBitRate }
r.suffix =
r.suffix || (r.bitRate ? config.defaultDownsamplingFormat : 'Original')
2023-01-20 04:52:55 +01:00
return <QualityInfo record={r} size={size} />
}
const ShareList = (props) => {
2023-01-24 02:11:46 +01:00
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
const translate = useTranslate()
2023-01-20 04:52:55 +01:00
return (
<List
{...props}
sort={{ field: 'createdAt', order: 'DESC' }}
exporter={false}
>
2023-01-24 02:11:46 +01:00
{isXsmall ? (
<SimpleList
primaryText={(r) => r.description || r.contents || r.id}
secondaryText={(r) => (
<>
{translate('resources.share.fields.expiresAt')}:{' '}
<DateField record={r} source={'expiresAt'} showTime />
</>
2023-01-20 04:52:55 +01:00
)}
/>
2023-01-24 02:11:46 +01:00
) : (
<Datagrid rowClick="edit">
<FunctionField
source={'id'}
render={(r) => (
<Link
href={shareUrl(r.id)}
label="URL"
target="_blank"
rel="noopener noreferrer"
onClick={(e) => {
e.stopPropagation()
}}
>
{r.id}
</Link>
)}
/>
<TextField source="username" />
<TextField source="description" />
<TextField source="contents" />
<FormatInfo source="format" />
<NumberField source="visitCount" />
<DateField source="lastVisitedAt" showTime sortByOrder={'DESC'} />
<DateField source="expiresAt" showTime />
</Datagrid>
)}
2023-01-20 04:52:55 +01:00
</List>
)
}
export default ShareList