mirror of
https://github.com/navidrome/navidrome.git
synced 2025-08-10 00:52:20 +00:00
25 lines
548 B
JavaScript
25 lines
548 B
JavaScript
import { cloneElement, Children, isValidElement } from 'react'
|
|
|
|
export const isWritable = (owner) => {
|
|
return (
|
|
localStorage.getItem('username') === owner ||
|
|
localStorage.getItem('role') === 'admin'
|
|
)
|
|
}
|
|
|
|
export const isReadOnly = (owner) => {
|
|
return !isWritable(owner)
|
|
}
|
|
|
|
const Writable = (props) => {
|
|
const { record, children } = props
|
|
if (isWritable(record.owner)) {
|
|
return Children.map(children, (child) =>
|
|
isValidElement(child) ? cloneElement(child, props) : child
|
|
)
|
|
}
|
|
return null
|
|
}
|
|
|
|
export default Writable
|