diff --git a/client.js b/client.js index 42182e2..d6d013f 100644 --- a/client.js +++ b/client.js @@ -1,18 +1,45 @@ 'use strict' const choo = require('choo') +const xtend = require('xtend') +const css = require('sheetify') +const stylesMap = require('./styles-map') + +css('css-wipe') +css('./styles.css') const app = choo() const width = 8 const height = 8 +const stylesMapLength = Object.keys(stylesMap).length +const grid = [] + +for (let m = 0; m < height; m++) { + const column = [] + for (let n = 0; n < width; n++) { + column.push({ + element: '', + styleID: 0 + }) + } + + grid.push(column) +} app.model({ - state: { - grid: { - rows: Array.from({ length: width }) - .map(item => Array.from({ length: height }) - .map((/* item */) => ({ element: 'x' })) - ) + state: { grid }, + reducers: { + changeBorder: (state, { m, n }) => { + const newState = xtend(state) + const potentialNewID = newState.grid[m][n].styleID + 1 + + if (potentialNewID === stylesMapLength) { + newState.grid[m][n].styleID = 0 + } else { + newState.grid[m][n].styleID++ + } + + return newState } } }) diff --git a/package.json b/package.json index dd8120b..add5244 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "license": "ISC", "dependencies": { "choo": "^4.1.0", + "css-wipe": "^4.2.2", "sheetify": "^6.0.1", "xtend": "^4.0.1" }, diff --git a/pages/grid.js b/pages/grid.js index d5dd63c..610f1ac 100644 --- a/pages/grid.js +++ b/pages/grid.js @@ -1,21 +1,25 @@ 'use strict' const html = require('choo/html') -const css = require('sheetify') -const prefix = css('../styles.css') +const stylesMap = require('../styles-map') module.exports = (state, prev, send) => { - const rows = state.grid.rows return html`
- ${column.element}
- |
- `)}
+ ${row.map((value, n) => {
+ const { element, styleID } = state.grid[m][n]
+
+ return html`
+
+ send('changeBorder', { m, n })}>
+ ${element}
+
+ |
+ `
+ })}