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

set Label

parent 212963d5
No related branches found
No related tags found
1 merge request!349Multiple single
import React, { useContext, useMemo } from 'react'; import React, { useContext, useMemo, useEffect, useState } from 'react';
import { injectable, inject } from 'inversify'; import { injectable, inject } from 'inversify';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
...@@ -66,9 +66,13 @@ class MultipleDropDown extends ToolGroup { ...@@ -66,9 +66,13 @@ class MultipleDropDown extends ToolGroup {
const { const {
activeView, activeView,
activeViewId,
view: { main }, view: { main },
} = context; } = context;
const { state } = view; const { state } = view;
const [label, setLabel] = useState(null);
const dropDownOptions = [ const dropDownOptions = [
{ {
label: 'Multiple Choice', label: 'Multiple Choice',
...@@ -92,13 +96,15 @@ class MultipleDropDown extends ToolGroup { ...@@ -92,13 +96,15 @@ class MultipleDropDown extends ToolGroup {
}, },
]; ];
useEffect(() => {
dropDownOptions.forEach((option, i) => {
if (option.item.active(main.state)) {
setLabel(option.label);
}
});
}, [activeViewId]);
const isDisabled = this._tools[0].select(state, activeView); const isDisabled = this._tools[0].select(state, activeView);
let found = '';
dropDownOptions.forEach((option, i) => {
if (option.item.active(main.state)) {
found = option.label;
}
});
const onChange = option => { const onChange = option => {
this._tools[option.value].run(main, context); this._tools[option.value].run(main, context);
...@@ -108,7 +114,7 @@ class MultipleDropDown extends ToolGroup { ...@@ -108,7 +114,7 @@ class MultipleDropDown extends ToolGroup {
() => ( () => (
<Wrapper key={uuidv4()}> <Wrapper key={uuidv4()}>
<DropdownStyled <DropdownStyled
value={found} value={label}
key={uuidv4()} key={uuidv4()}
options={dropDownOptions} options={dropDownOptions}
onChange={option => onChange(option)} onChange={option => onChange(option)}
...@@ -117,7 +123,7 @@ class MultipleDropDown extends ToolGroup { ...@@ -117,7 +123,7 @@ class MultipleDropDown extends ToolGroup {
/> />
</Wrapper> </Wrapper>
), ),
[isDisabled], [isDisabled, label],
); );
return MultipleDropDown; return MultipleDropDown;
......
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