-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add axios and setup babel polyfill * hookup select tag with App.list * fix cleanwebpackplugin config * fix cleanwebpackplugin config * update cube names * add optgroup, remove clean-wepback-plugin weird interaction between optgroup and clean-webpack-plugin causes page to lose styling after refresh * move none option * selecting none clear textarea * remove webpack plugin import
- Loading branch information
1 parent
9933610
commit 5f578cf
Showing
14 changed files
with
3,598 additions
and
69 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, {useState, useEffect} from 'react' | ||
import axios from 'axios' | ||
|
||
import { Textarea } from "../utils"; | ||
import App from '../app'; | ||
|
||
const CubeList = () => { | ||
const [cubes, setCubes] = useState('') | ||
const [selectedCube, selectCube] = useState('none') | ||
let cubeOptions = [] | ||
|
||
const getCubes = async function() { | ||
const {data: cubes} = await axios.get('/api/cubes') | ||
setCubes(cubes) | ||
} | ||
|
||
useEffect(() => {!cubes && getCubes()}) | ||
|
||
Object.keys(cubes).forEach(key => { | ||
const option = <option value={key} key={key}>{key}</option> | ||
cubeOptions.push(option) | ||
}) | ||
|
||
const handleChange = (e) => { | ||
e.preventDefault() | ||
selectCube(e.target.value) | ||
App.state['list'] = | ||
e.target.value === 'none' | ||
? '' | ||
: cubes[e.target.value] | ||
} | ||
|
||
return <div id='cube-list'> | ||
<div className='column'> | ||
<div>one card per line</div> | ||
<Textarea | ||
placeholder='cube list' | ||
link='list' | ||
/> | ||
</div> | ||
{cubes && <div id='preset-cubes'> | ||
<div>Preset Cubes:</div> | ||
<select onChange={handleChange}> | ||
<option value='none' key='none'>None</option> | ||
<optgroup label="Cube Tutor"> | ||
{cubeOptions} | ||
</optgroup> | ||
</select> | ||
</div>} | ||
</div> | ||
} | ||
|
||
export default CubeList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require("fs"); | ||
const express = require("express"); | ||
const cubesRouter = express.Router(); | ||
const logger = require("../logger"); | ||
|
||
cubesRouter | ||
.get("/", (req, res) => { | ||
|
||
fs.readdir('src/cubes', function(err, fileNames) { | ||
if (err) { | ||
console.error(err) | ||
res.status(500).end() | ||
} else { | ||
let cubes = {} | ||
fileNames.forEach(name => { | ||
if (name.includes('.txt')) { | ||
const cube = fs.readFileSync(`src/cubes/${name}`) | ||
const key = name.slice(0, name.length-4) | ||
cubes[key] = cube.toString() | ||
} | ||
}) | ||
res.status(200).send(cubes) | ||
} | ||
}); | ||
|
||
}); | ||
|
||
module.exports = cubesRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.