navidrome/ui/src/user/UserList.jsx
Deluan Quintão be8ec15168
feat(ui): format dates using the selected language (#6160)
Dates were rendered with the browser locale, ignoring the language chosen in
Personal settings, so a user browsing in German still saw US-style dates. All
date rendering now resolves its locale through a useDateLocale hook that returns
the selected language, augmented with the region from navigator.languages when
the language carries none (Intl reads a bare "en" as en-US). Applied to
DateField, the rated/loved tooltips, the mobile user list and album release
dates; the three inline timestamp tooltips now share a formatDateTime helper.

Closes #229
2026-09-19 14:07:42 -04:00

55 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react'
import {
BooleanField,
Datagrid,
Filter,
SearchInput,
SimpleList,
TextField,
} from 'react-admin'
import { useMediaQuery } from '@material-ui/core'
import { List, DateField } from '../common'
import { useDateLocale } from '../i18n/useDateLocale'
import { formatDateTime } from '../utils/formatters'
const UserFilter = (props) => (
<Filter {...props} variant={'outlined'}>
<SearchInput id="search" source="name" alwaysOn />
</Filter>
)
const UserList = (props) => {
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
const locale = useDateLocale()
return (
<List
{...props}
sort={{ field: 'userName', order: 'ASC' }}
exporter={false}
bulkActionButtons={false}
filters={<UserFilter />}
>
{isXsmall ? (
<SimpleList
primaryText={(record) => record.userName}
secondaryText={(record) =>
record.lastLoginAt && formatDateTime(record.lastLoginAt, locale)
}
tertiaryText={(record) => (record.isAdmin ? '[admin]️' : '')}
/>
) : (
<Datagrid rowClick="edit">
<TextField source="userName" />
<TextField source="name" />
<BooleanField source="isAdmin" />
<DateField source="lastLoginAt" sortByOrder={'DESC'} />
<DateField source="lastAccessAt" sortByOrder={'DESC'} />
<DateField source="updatedAt" sortByOrder={'DESC'} />
</Datagrid>
)}
</List>
)
}
export default UserList