quintodrome/ui/src/common/Writable.js

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

28 lines
688 B
JavaScript
Raw Normal View History

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
}
export const Writable = (props) => {
const { record = {}, children } = props
2021-10-29 18:55:28 -08:00
if (isWritable(record.ownerId)) {
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)