Skip to content
Snippets Groups Projects
Commit b4b3ac16 authored by chris's avatar chris
Browse files

set Checked

parent 63cbfe2e
No related branches found
No related tags found
1 merge request!308Answer nodeview
...@@ -21,10 +21,7 @@ const FeedBackInput = styled.input` ...@@ -21,10 +21,7 @@ const FeedBackInput = styled.input`
export default ({ node, view, getPos }) => { export default ({ node, view, getPos }) => {
const context = useContext(WaxContext); const context = useContext(WaxContext);
const { const { activeViewId } = context;
view: { main },
activeViewId,
} = context;
const [feedBack, setFeedBack] = useState(node.attrs.feedback); const [feedBack, setFeedBack] = useState(node.attrs.feedback);
const feedBackRef = useRef(null); const feedBackRef = useRef(null);
......
...@@ -132,7 +132,7 @@ export default ({ node, view, getPos }) => { ...@@ -132,7 +132,7 @@ export default ({ node, view, getPos }) => {
<QuestionData> <QuestionData>
<EditorComponent node={node} view={view} getPos={getPos} /> <EditorComponent node={node} view={view} getPos={getPos} />
<SwitchComponent node={node} /> <SwitchComponent node={node} getPos={getPos} />
</QuestionData> </QuestionData>
<FeedbackComponent node={node} view={view} getPos={getPos} /> <FeedbackComponent node={node} view={view} getPos={getPos} />
</QuestionWrapper> </QuestionWrapper>
......
import React, { useState } from 'react'; import React, { useState, useContext } from 'react';
import { WaxContext } from 'wax-prosemirror-core';
import styled from 'styled-components'; import styled from 'styled-components';
import Switch from './Switch'; import Switch from './Switch';
...@@ -19,10 +20,19 @@ const StyledSwitch = styled(Switch)` ...@@ -19,10 +20,19 @@ const StyledSwitch = styled(Switch)`
} }
`; `;
const CustomSwitch = ({ node }) => { const CustomSwitch = ({ node, getPos }) => {
const context = useContext(WaxContext);
const { activeViewId } = context;
const [checked, setChecked] = useState(false); const [checked, setChecked] = useState(false);
const handleChange = () => { const handleChange = () => {
setChecked(!checked); setChecked(!checked);
context.view.main.dispatch(
context.view.main.state.tr.setNodeMarkup(getPos(), undefined, {
...node.attrs,
correct: !checked,
}),
);
}; };
return ( return (
......
...@@ -23,7 +23,7 @@ export default class AbstractNodeView { ...@@ -23,7 +23,7 @@ export default class AbstractNodeView {
} }
update(node) { update(node) {
if (!node.sameMarkup(this.node)) return false; // if (!node.sameMarkup(this.node)) return false;
this.node = node; this.node = node;
if (this.context.view[node.attrs.id]) { if (this.context.view[node.attrs.id]) {
const { state } = this.context.view[node.attrs.id]; const { state } = this.context.view[node.attrs.id];
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment