navidrome/ui/src/common/Writable.js

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

27 lines
688 B
JavaScript
Raw Normal View History

import { cloneElement, Children, isValidElement } from 'react'
2020-06-05 10:22:31 -04:00
2021-10-29 22:55:28 -04:00
export const isWritable = (ownerId) => {
2020-06-05 10:22:31 -04:00
return (
2021-10-29 22:55:28 -04:00
localStorage.getItem('userId') === ownerId ||
2020-06-05 10:22:31 -04:00
localStorage.getItem('role') === 'admin'
)
}
2021-10-29 22:55:28 -04:00
export const isReadOnly = (ownerId) => {
return !isWritable(ownerId)
2020-06-05 10:22:31 -04:00
}
export const Writable = (props) => {
const { record = {}, children } = props
2021-10-29 22:55:28 -04:00
if (isWritable(record.ownerId)) {
return Children.map(children, (child) =>
isValidElement(child) ? cloneElement(child, props) : child
)
2020-06-05 10:22:31 -04:00
}
return null
}
2021-10-22 21:11:44 -04:00
export const isSmartPlaylist = (pls) => !!pls.rules
export const canChangeTracks = (pls) =>
2021-10-29 22:55:28 -04:00
isWritable(pls.ownerId) && !isSmartPlaylist(pls)