Skip to content

Commit 5b3823f

Browse files
Add slider & CSS importing
1 parent bfab37e commit 5b3823f

8 files changed

+47
-10
lines changed

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>N Queens Solver</title>
5+
<title>N Queens Visualizer</title>
66
<link rel="stylesheet" type="text/css" href="src/css/main.css"/>
77
</head>
88
<body>

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "https://github.com/haseeb-qureshi/n-queens"
11+
"url": "https://github.com/haseeb-qureshi/n-queens-visualizer"
1212
},
1313
"keywords": [
1414
"react",
@@ -35,9 +35,12 @@
3535
"webpack-dev-server": "^1.12.1"
3636
},
3737
"dependencies": {
38+
"css-loader": "^0.23.1",
39+
"flux": "^2.0.0",
40+
"object-assign": "^1.0.0",
41+
"rc-slider": "^3.3.2",
3842
"react": "^0.14.0",
3943
"react-dom": "^0.14.0",
40-
"flux": "^2.0.0",
41-
"object-assign": "^1.0.0"
44+
"style-loader": "^0.13.0"
4245
}
4346
}

src/actions/action-creator.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ module.exports = {
1212
updateBoard: function (board) {
1313
AppDispatcher.dispatch({
1414
actionType: "UPDATE_BOARD",
15-
data: board
15+
newBoard: board
1616
});
1717
},
1818

1919
swapQueens: function (indices) {
2020
AppDispatcher.dispatch({
2121
actionType: "SWAP_QUEENS",
22-
data: indices
22+
indices: indices
2323
});
2424
},
2525

@@ -53,7 +53,7 @@ module.exports = {
5353
failure: function (iterations) {
5454
AppDispatcher.dispatch({
5555
actionType: "FAILURE",
56-
data: iterations
56+
iterations: iterations
5757
});
5858
}
5959
};

src/components/container.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
require('rc-slider/assets/index.css');
2+
13
var React = require('react');
24
var Board = require('./board');
35
var AlgoSelector = require('./algo-selector');
6+
var Slider = require('rc-slider');
7+
var SliderProps = require('./slider');
48

59
var Container = React.createClass({
610

@@ -17,6 +21,9 @@ var Container = React.createClass({
1721
<div className="container">
1822
<Board />
1923
<AlgoSelector algos={algos} />
24+
<Slider min={SliderProps.min}
25+
onChange={SliderProps.onChange}
26+
marks={SliderProps.marks} />
2027
</div>
2128
)
2229
}

src/components/slider.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var ActionCreator = require('../actions/action-creator');
2+
3+
var marks = {
4+
1: "1 ms",
5+
25: "25 ms",
6+
50: "50 ms",
7+
75: "75 ms",
8+
100: "100 ms"
9+
};
10+
11+
var min = 1;
12+
13+
function changeSpeed(newSpeed) {
14+
ActionCreator.changeSpeed(newSpeed);
15+
}
16+
17+
module.exports = {
18+
onChange: changeSpeed,
19+
marks: marks,
20+
min: min
21+
};

src/stores/board-store.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ BoardStore.dispatchToken = AppDispatcher.register(function (action) {
6262
break;
6363
case "UPDATE_BOARD":
6464
AppDispatcher.waitFor([ScriptStore.dispatchToken]);
65-
BoardStore._updateBoard(action.data);
65+
BoardStore._updateBoard(action.newBoard);
6666
break;
6767
case "SWAP_QUEENS":
6868
AppDispatcher.waitFor([ScriptStore.dispatchToken]);
69-
BoardStore._swapQueens(action.data);
69+
BoardStore._swapQueens(action.indices);
7070
break;
7171
case "FAILURE":
72-
console.log("failed after " + action.data + " iterations");
72+
alert("failed after " + action.iterations + " iterations");
7373
break;
7474
case "RUN_SCRIPT":
7575
BoardStore._resetBoard();

src/stores/script-store.js

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ ScriptStore.dispatchToken = AppDispatcher.register(function (action) {
4747
ScriptStore._runScript(action.scriptName);
4848
ScriptStore.emitChange();
4949
break;
50+
case "CHANGE_SPEED":
51+
console.log(action.newSpeed);
52+
break;
5053
default:
5154
}
5255
});

webpack.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module.exports = {
2121
test: /\.js$/,
2222
loaders: ['react-hot', 'babel?presets[]=react,presets[]=es2015'],
2323
include: path.join(__dirname, 'src')
24+
}, {
25+
test: /\.css$/, // Only .css files
26+
loader: 'style!css' // Run both loaders
2427
}]
2528
}
2629
};

0 commit comments

Comments
 (0)