This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from education/feature/frontend-setup
Setup react, photon-kit and flux architecture
- Loading branch information
Showing
19 changed files
with
309 additions
and
38 deletions.
There are no files selected for viewing
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,4 @@ | ||
{ | ||
"presets": ["es2015", "react"], | ||
"plugins": ["transform-object-assign"] | ||
} |
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 @@ | ||
dist |
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,16 @@ | ||
import React from "react" | ||
|
||
import { createDevTools } from "redux-devtools" | ||
|
||
import LogMonitor from "redux-devtools-log-monitor" | ||
import DockMonitor from "redux-devtools-dock-monitor" | ||
|
||
const DevTools = createDevTools( | ||
<DockMonitor toggleVisibilityKey="ctrl-h" | ||
changePositionKey="ctrl-q" | ||
defaultIsVisible={true}> | ||
<LogMonitor theme="tomorrow" /> | ||
</DockMonitor> | ||
) | ||
|
||
export default DevTools |
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,8 @@ | ||
import {SELECT_ITEM} from "../constants/actionTypes" | ||
|
||
export const selectItem = (id) => { | ||
return { | ||
type: SELECT_ITEM, | ||
id: id | ||
} | ||
} |
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,25 @@ | ||
import React, { PropTypes } from "react" | ||
import {ListItem} from "react-photonkit" | ||
|
||
const Item = ({ | ||
text, | ||
active, | ||
handleClick | ||
}) => ( | ||
<div | ||
onClick={handleClick}> | ||
<ListItem | ||
image="https://avatars3.githubusercontent.com/u/1744446?v=3&s=400" | ||
title={text} | ||
subtitle="subtitle" | ||
active={active} /> | ||
</div> | ||
) | ||
|
||
Item.propTypes = { | ||
text: PropTypes.string.isRequired, | ||
active: PropTypes.bool.isRequired, | ||
handleClick: PropTypes.func.isRequired | ||
} | ||
|
||
export default Item |
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,30 @@ | ||
import React, { PropTypes } from "react" | ||
import { Pane, ListGroup } from "react-photonkit" | ||
import Item from "./Item" | ||
|
||
const ItemList = ({ | ||
items, | ||
handleItemClick | ||
}) => ( | ||
<Pane> | ||
<ListGroup> | ||
{items.map((todo) => { | ||
return ( | ||
<Item | ||
key={todo.id} | ||
text={todo.text} | ||
active={todo.active} | ||
handleClick={function () { handleItemClick(todo.id) }} | ||
/> | ||
) | ||
})} | ||
</ListGroup> | ||
</Pane> | ||
) | ||
|
||
ItemList.propTypes = { | ||
items: PropTypes.array.isRequired, | ||
handleItemClick: PropTypes.func.isRequired | ||
} | ||
|
||
export default ItemList |
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 @@ | ||
export const SELECT_ITEM = "SELECT_ITEM" |
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,19 @@ | ||
import { connect } from "react-redux" | ||
import { selectItem } from "../actions" | ||
import ItemList from "../components/ItemList" | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
items: state.items | ||
} | ||
} | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return { | ||
handleItemClick: (id) => { | ||
dispatch(selectItem(id)) | ||
} | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(ItemList) |
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,35 @@ | ||
import * as React from "react" | ||
import * as ReactDOM from "react-dom" | ||
import {Window, Toolbar, Content} from "react-photonkit" | ||
import {createStore, compose} from "redux" | ||
import { Provider } from "react-redux" | ||
import isDev from "electron-is-dev" | ||
import DevTools from "./DevTools" | ||
|
||
import reducer from "./reducers" | ||
import SelectableItemList from "./containers/SelectableItemList" | ||
|
||
let devToolsInstance | ||
if (isDev) { | ||
devToolsInstance = <DevTools /> | ||
} | ||
|
||
const store = createStore(reducer, compose(DevTools.instrument())) | ||
|
||
const render = () => { | ||
ReactDOM.render( | ||
<Provider store={store}> | ||
<Window> | ||
<Toolbar title="header" /> | ||
<Content> | ||
<SelectableItemList /> | ||
</Content> | ||
<Toolbar psType="footer" title="footer" /> | ||
{devToolsInstance} | ||
</Window> | ||
</Provider> | ||
, document.getElementById("app")) | ||
} | ||
|
||
store.subscribe(render) | ||
render() |
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,7 @@ | ||
import { combineReducers } from "redux" | ||
|
||
import items from "./items" | ||
|
||
export default combineReducers({ | ||
items | ||
}) |
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,43 @@ | ||
const initialState = [ | ||
{ | ||
id: 1, | ||
text: "Item 1", | ||
active: false | ||
}, | ||
{ | ||
id: 2, | ||
text: "Item 2", | ||
active: true | ||
} | ||
] | ||
|
||
const item = (state, action) => { | ||
switch (action.type) { | ||
case "SELECT_ITEM": | ||
if (action.id === state.id) { | ||
return Object.assign({}, state, {active: !state.active}) | ||
} else { | ||
return state | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
const items = (state, action) => { | ||
if (typeof state === "undefined") { | ||
return initialState | ||
} | ||
|
||
switch (action.type) { | ||
case "SELECT_ITEM": | ||
return state.map((each) => { | ||
return item(each, action) | ||
}) | ||
|
||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default items |
This file was deleted.
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,17 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { assert } from "chai" | ||
import { SELECT_ITEM } from "../app/constants/actionTypes" | ||
import { selectItem } from "../app/actions" | ||
|
||
describe("actions", () => { | ||
it("should create an action to select an item", () => { | ||
const id = 1 | ||
const expectedAction = { | ||
type: SELECT_ITEM, | ||
id: id | ||
} | ||
|
||
assert.deepEqual(expectedAction, selectItem(id)) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { assert } from "chai" | ||
import { SELECT_ITEM } from "../app/constants/actionTypes" | ||
import deepFreeze from "deep-freeze" | ||
|
||
import itemsReducer from "../app/reducers/items" | ||
|
||
describe("reducers", () => { | ||
describe("items reducer", () => { | ||
it("should return the initial state", () => { | ||
let expectedState = [ | ||
{ | ||
id: 1, | ||
text: "Item 1", | ||
active: false | ||
}, | ||
{ | ||
id: 2, | ||
text: "Item 2", | ||
active: true | ||
} | ||
] | ||
|
||
assert.deepEqual( | ||
expectedState, | ||
itemsReducer(undefined, {}) | ||
) | ||
}) | ||
|
||
it("should select the correct item", () => { | ||
let initialState = [ | ||
{ | ||
id: 1, | ||
text: "Item 1", | ||
active: false | ||
}, | ||
{ | ||
id: 2, | ||
text: "Item 2", | ||
active: true | ||
} | ||
] | ||
|
||
let expectedState = [ | ||
{ | ||
id: 1, | ||
text: "Item 1", | ||
active: true | ||
}, | ||
{ | ||
id: 2, | ||
text: "Item 2", | ||
active: true | ||
} | ||
] | ||
|
||
let action = { | ||
type: SELECT_ITEM, | ||
id: 1 | ||
} | ||
|
||
deepFreeze(initialState) | ||
|
||
assert.deepEqual( | ||
expectedState, | ||
itemsReducer(initialState, action) | ||
) | ||
}) | ||
}) | ||
}) |