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