diff --git a/example/sandbox/index.html b/example/sandbox/index.html
index 6ae8902..cc94d1d 100644
--- a/example/sandbox/index.html
+++ b/example/sandbox/index.html
@@ -10,7 +10,7 @@
-
+
diff --git a/example/sandbox/src/components/App.js b/example/sandbox/src/components/App.js
index e66b204..5a7b016 100644
--- a/example/sandbox/src/components/App.js
+++ b/example/sandbox/src/components/App.js
@@ -4,13 +4,15 @@ import Drawer from 'material-ui/Drawer';
import FloatingActionButton from 'material-ui/FloatingActionButton';
import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';
-import {Card, CardTitle, CardText} from 'material-ui/Card';
+import {Card, CardText} from 'material-ui/Card';
import IconButton from 'material-ui/IconButton';
import TuneIcon from 'material-ui/svg-icons/image/tune';
import Scanner from './Scanner';
import ScanIcon from './ScanIcon';
+import ScannedCode from './ScannedCode';
import ConfigView from './ConfigView';
+import {persist, load} from '../utils/Storage';
const cleanConfig = config => {
if (typeof config.inputStream.constraints.deviceId === 'number') {
@@ -19,50 +21,46 @@ const cleanConfig = config => {
return config;
};
+const defaultConfig = {
+ frequency: 5,
+ numOfWorkers: 2,
+ locate: true,
+ inputStream: {
+ name: "Live",
+ type: "LiveStream",
+ constraints: {
+ width: 800,
+ height: 600,
+ deviceId: 0,
+ facingMode: "environment",
+ },
+ area: {
+ top: "0%",
+ right: "0%",
+ left: "0%",
+ bottom: "0%",
+ },
+ },
+ decoder: {
+ readers: [
+ 'ean_reader',
+ 'code_39_reader',
+ 'code_128_reader',
+ ],
+ },
+ locator: {
+ halfSample: true,
+ patchSize: "medium",
+ },
+};
+
export default class App extends React.Component {
state = {
drawerOpen: false,
scanning: false,
currentView: 'root',
- config: {
- frequency: 5,
- numOfWorkers: 2,
- locate: true,
- inputStream: {
- name: "Live",
- type: "LiveStream",
- constraints: {
- width: 640,
- height: 480,
- deviceId: 0,
- facingMode: "environment",
- },
- area: {
- top: "0%",
- right: "0%",
- left: "0%",
- bottom: "0%",
- },
- },
- decoder: {
- readers: [
- 'ean_reader',
- 'code_39_reader',
- 'code_128_reader',
- ],
- },
- locator: {
- halfSample: true,
- patchSize: "medium",
- },
- },
- scannedCodes: [{
- codeResult: {
- code: "FANAVF1461710",
- format: "code_128",
- },
- timestamp: new Date(),
- }],
+ config: load("config") || defaultConfig,
+ scannedCodes: load('scannedCodes') || [],
};
_handleToggle = () => {
@@ -86,9 +84,20 @@ export default class App extends React.Component {
_handleResult = (result) => {
this._stopScanning();
- this.setState({
- scannedCodes: [{...result, timestamp: new Date()}]
- .concat(this.state.scannedCodes)});
+ const scannedCodes =
+ [{
+ angle: result.angle,
+ box: result.box,
+ codeResult: {
+ code: result.codeResult.code,
+ direction: result.codeResult.direction,
+ format: result.codeResult.format,
+ },
+ line: result.line,
+ }]
+ .concat(this.state.scannedCodes);
+ this.setState({scannedCodes});
+ persist('scannedCodes', scannedCodes);
}
_navigateTo = (route) => {
@@ -100,7 +109,17 @@ export default class App extends React.Component {
_handleConfigChange = config => {
this.setState({config: cleanConfig(config)});
- console.log(config);
+ persist("config", config);
+ }
+
+ _handleDelete = (scannedCode) => {
+ const index = this.state.scannedCodes.indexOf(scannedCode);
+ if (index !== -1) {
+ const newArray = this.state.scannedCodes.slice();
+ newArray.splice(index, 1);
+ this.setState({scannedCodes: newArray});
+ persist('scannedCodes', newArray);
+ }
}
render() {
@@ -119,13 +138,6 @@ export default class App extends React.Component {
iconElementLeft={