-
Notifications
You must be signed in to change notification settings - Fork 7
/
credit-add.js
56 lines (49 loc) · 1.39 KB
/
credit-add.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {createElement as el} from 'react'
import NavItem from 'rebass/dist/NavItem'
import NavItemConfirm from './nav-item-confirm'
export default function CreditAdd (props) {
const {schema, metadata, onClick} = props
return el('div'
, { style: {} }
, makeLinks(schema, metadata, onClick)
)
}
function makeLinks (schema, metadata = {}, onClick) {
let links = []
if (schema.isBasedOnUrl && metadata.isBasedOnUrl == null) {
links.push(makeLink('isBasedOnUrl', 'Add Source Link', onClick))
}
// TODO allow multiple authors?
if (schema.author && (!metadata.author || !metadata.author[0])) {
links.push(makeLink('author', 'Add Credit', onClick))
}
if (schema.via && !metadata.via) {
links.push(makeLink('via', 'Add Via', onClick))
}
if (schema.publisher && !metadata.publisher) {
links.push(makeLink('publisher', 'Add Publisher', onClick))
}
links.push(makeLink('delete', 'Remove Block', onClick, true))
return links
}
function makeLink (key, label, onClick, confirm = false) {
let Component = NavItem
let props = {
key,
children: label,
label,
style: { display: 'block' },
onClick: makeClick(key, onClick),
}
if (confirm) {
Component = NavItemConfirm
props.confirm = 'Delete forever now.'
props.theme = 'warning'
}
return el(Component, props)
}
function makeClick (key, onClick) {
return function () {
onClick(key)
}
}