-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js.hold
91 lines (74 loc) · 2.92 KB
/
index.js.hold
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { registerBlockType } from '@wordpress/blocks'
import { TextControl, Flex, FlexBlock, FlexItem, Button, Icon, PanelBody, ColorPalette } from '@wordpress/components'
import { useBlockProps, InspectorControls } from '@wordpress/block-editor'
import block from './block.json'
import icons from '../../icons'
import './index.scss'
registerBlockType(block.name, {
icon: icons.primary,
edit: EditComponent,
save: function () {
return null
}
})
function EditComponent(props) {
const blockProps = useBlockProps()
function updateQuestion(newVal) {
props.setAttributes({question: newVal})
}
function deleteAnswer(x) {
const newAnswers = props.attributes.answers.filter(function(z, index) {
return index != x
})
props.setAttributes({answers: newAnswers})
if(x == props.attributes.correctAnswer) {
props.setAttributes({correctAnswer: undefined})
}
}
function setAnswer(x) {
props.setAttributes({correctAnswer: x})
}
function addQuestion() {
}
return (
<div {...blockProps}>
<InspectorControls>
<PanelBody title="Screw you!">
<p>Hello.</p>
</PanelBody>
</InspectorControls>
<div className="pz-question-block">
<TextControl label="Question:" value={props.attributes.question} onChange={updateQuestion} style={{ fontSize: "20px" }} />
<p style={{fontSize: "13px", margin: "20px 0 8px 0"}}>Answers:</p>
{props.attributes.answers.map(function(answer, index) {
return (
<Flex>
<FlexBlock>
<TextControl value={answer} onChange={x => {
const newAnswers = props.attributes.answers.concat([])
newAnswers[index] = x
props.setAttributes({answers: newAnswers})
} }/>
</FlexBlock>
<FlexItem>
<Button onClick={() => setAnswer(index)}>
<Icon className="pz-star-empty" icon={props.attributes.correctAnswer == index ? "star-filled" : "star-empty" } />
</Button>
</FlexItem>
<FlexItem>
<Button variant="link" className="pz-delete" onClick={() => deleteAnswer(index)}>
Delete
</Button>
</FlexItem>
</Flex>
)
})}
<Button variant="primary" onClick={() => {
props.setAttributes({answers: props.attributes.answers.concat([""])})
}}>
Add another answer
</Button>
</div>
</div>
)
}