2019-04-23 18:34:18 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import PropTypes from "prop-types";
|
2019-04-27 10:50:44 +02:00
|
|
|
import Pct from "./PatternOptionPercentage";
|
|
|
|
import Deg from "./PatternOptionDegree";
|
|
|
|
import Mm from "./PatternOptionMillimeter";
|
|
|
|
import Bool from "./PatternOptionBool";
|
|
|
|
import OptionGroup from "./OptionGroup";
|
2019-04-27 12:21:41 +02:00
|
|
|
import { optionType, gistDefaults } from "../.utils";
|
2019-04-23 18:34:18 +02:00
|
|
|
import { patternInfo, patternList } from "@freesewing/patterns";
|
2019-04-27 10:50:44 +02:00
|
|
|
import { FormattedMessage } from "react-intl";
|
|
|
|
import PatternOptions from "./PatternOptions";
|
|
|
|
import DraftSettings from "./DraftSettings";
|
|
|
|
//import DraftActions from "DraftActions";
|
|
|
|
import withGist from "../withGist";
|
2019-04-23 18:34:18 +02:00
|
|
|
|
2019-04-27 10:50:44 +02:00
|
|
|
const DraftConfigurator = props => {
|
|
|
|
const [gist, setGist] = useState(props.gist.get);
|
2019-04-25 08:03:20 +02:00
|
|
|
const [expanded, setExpanded] = useState([]);
|
2019-04-23 18:34:18 +02:00
|
|
|
|
|
|
|
const update = (type, name, value) => {
|
|
|
|
console.log("updating", type, name, value);
|
|
|
|
};
|
|
|
|
|
2019-04-25 08:03:20 +02:00
|
|
|
const toggleGroup = group => {
|
|
|
|
let shown = expanded.slice(0);
|
|
|
|
let index = shown.indexOf(group);
|
|
|
|
if (index === -1) shown.push(group);
|
|
|
|
else shown.splice(index, 1);
|
|
|
|
setExpanded(shown);
|
|
|
|
};
|
2019-04-23 18:34:18 +02:00
|
|
|
let pattern = patternInfo[props.pattern];
|
2019-04-27 10:50:44 +02:00
|
|
|
let dflts = gistDefaults(pattern.config, props.gist.get);
|
2019-04-23 18:34:18 +02:00
|
|
|
|
|
|
|
return (
|
2019-04-25 16:51:15 +02:00
|
|
|
<ul className="nav l1">
|
|
|
|
<li>
|
2019-04-23 18:34:18 +02:00
|
|
|
<h2>
|
|
|
|
<FormattedMessage id="app.patternOptions" />
|
|
|
|
</h2>
|
2019-04-25 08:03:20 +02:00
|
|
|
<PatternOptions
|
|
|
|
pattern={props.pattern}
|
|
|
|
units={props.units}
|
2019-04-27 10:50:44 +02:00
|
|
|
updateValue={(name, value) => props.gist.set(value, 'settings', 'options', name)}
|
2019-04-25 08:03:20 +02:00
|
|
|
triggerAction={props.triggerAction}
|
|
|
|
/>
|
2019-04-25 16:51:15 +02:00
|
|
|
</li>
|
|
|
|
<li>
|
2019-04-23 18:34:18 +02:00
|
|
|
<h2>
|
|
|
|
<FormattedMessage id="app.draftSettings" />
|
|
|
|
</h2>
|
2019-04-25 08:03:20 +02:00
|
|
|
<DraftSettings
|
|
|
|
pattern={props.pattern}
|
|
|
|
units={props.units}
|
2019-04-27 10:50:44 +02:00
|
|
|
updateValue={(name, value) => props.gist.set(value, 'settings', name)}
|
2019-04-25 08:03:20 +02:00
|
|
|
triggerAction={props.triggerAction}
|
|
|
|
/>
|
2019-04-25 16:51:15 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
2019-04-23 18:34:18 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-04-27 10:50:44 +02:00
|
|
|
DraftConfigurator.propTypes = {
|
2019-04-23 18:34:18 +02:00
|
|
|
pattern: PropTypes.oneOf(patternList),
|
|
|
|
units: PropTypes.oneOf(["metric", "imperial"]).isRequired
|
|
|
|
};
|
|
|
|
|
2019-04-27 10:50:44 +02:00
|
|
|
DraftConfigurator.defaultProps = {};
|
2019-04-23 18:34:18 +02:00
|
|
|
|
2019-04-27 10:50:44 +02:00
|
|
|
export default withGist(DraftConfigurator, {gist: {}, store: "yes"});
|