mirror of
https://github.com/seigler/triplebyte-react-spa
synced 2025-07-26 07:16:10 +00:00
feat: one hour of progress
This commit is contained in:
parent
5684ef36ec
commit
9242ce66ec
6 changed files with 88 additions and 47 deletions
BIN
assignment.png
Normal file
BIN
assignment.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 KiB |
19
components/addCard.js
Normal file
19
components/addCard.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { useDispatch } from 'react-redux'
|
||||||
|
|
||||||
|
import { withRedux } from '../lib/redux';
|
||||||
|
|
||||||
|
const addCard = ({ columnIndex }) => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
return <a onClick={
|
||||||
|
() => {
|
||||||
|
const userText = window.prompt('New card text:', '(no text)');
|
||||||
|
dispatch({ type: 'ADD_CARD', payload: {
|
||||||
|
column: columnIndex,
|
||||||
|
text: userText
|
||||||
|
} });
|
||||||
|
}
|
||||||
|
}>+ Add a card</a>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withRedux(addCard);
|
7
components/card.js
Normal file
7
components/card.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export default ({ children }) => {
|
||||||
|
return <div className='card'>
|
||||||
|
I am a card
|
||||||
|
</div>
|
||||||
|
}
|
23
components/column.js
Normal file
23
components/column.js
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { useSelector, shallowEqual } from 'react-redux';
|
||||||
|
import { withRedux } from '../lib/redux';
|
||||||
|
|
||||||
|
import Card from './card';
|
||||||
|
import AddCard from './addCard';
|
||||||
|
|
||||||
|
const column = ({ name, index, headerColor }) => {
|
||||||
|
const cards = useSelector(state => state.columns[index].cards);
|
||||||
|
|
||||||
|
return <div className='column'>
|
||||||
|
<h1 className='card-title' style={{ color: 'white', backgroundColor: headerColor }}>{name}</h1>
|
||||||
|
{ cards.map((c, cardIndex) => <Card key={`card-${index}-${cardIndex}`} />) }
|
||||||
|
<AddCard index={index} />
|
||||||
|
<style jsx>{`
|
||||||
|
.column {
|
||||||
|
margin: 12.5px;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withRedux(column);
|
|
@ -1,37 +1,42 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
|
import { useSelector, shallowEqual } from 'react-redux'
|
||||||
import { withRedux } from '../lib/redux'
|
import { withRedux } from '../lib/redux'
|
||||||
import useInterval from '../lib/useInterval'
|
import useInterval from '../lib/useInterval'
|
||||||
import Clock from '../components/clock'
|
|
||||||
import Counter from '../components/counter'
|
import Column from '../components/column';
|
||||||
|
import Card from '../components/card';
|
||||||
|
|
||||||
const IndexPage = () => {
|
const IndexPage = () => {
|
||||||
// Tick the time every second
|
const columns = useSelector(state => state.columns, shallowEqual);
|
||||||
const dispatch = useDispatch()
|
|
||||||
useInterval(() => {
|
|
||||||
dispatch({
|
|
||||||
type: 'TICK',
|
|
||||||
light: true,
|
|
||||||
lastUpdate: Date.now(),
|
|
||||||
})
|
|
||||||
}, 1000)
|
|
||||||
return (
|
return (
|
||||||
<>
|
<main className='App'>
|
||||||
<Clock />
|
{columns.map((c, index) => <Column index={index} key={`column${index}`} name={c.name} headerColor={c.headerColor} />)}
|
||||||
<Counter />
|
<style jsx>{`
|
||||||
</>
|
.App {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
padding: 12.5px;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
<style global jsx>{`
|
||||||
|
body {
|
||||||
|
background: #ECEEEE;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
</main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexPage.getInitialProps = ({ reduxStore }) => {
|
IndexPage.getInitialProps = ({ reduxStore }) => {
|
||||||
// Tick the time once, so we'll have a
|
// // Tick the time once, so we'll have a
|
||||||
// valid time before first render
|
// // valid time before first render
|
||||||
const { dispatch } = reduxStore
|
// const { dispatch } = reduxStore
|
||||||
dispatch({
|
// dispatch({
|
||||||
type: 'TICK',
|
// type: 'TICK',
|
||||||
light: typeof window === 'object',
|
// light: typeof window === 'object',
|
||||||
lastUpdate: Date.now(),
|
// lastUpdate: Date.now(),
|
||||||
})
|
// })
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
35
store.js
35
store.js
|
@ -2,34 +2,21 @@ import { createStore, applyMiddleware } from 'redux'
|
||||||
import { composeWithDevTools } from 'redux-devtools-extension'
|
import { composeWithDevTools } from 'redux-devtools-extension'
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
lastUpdate: 0,
|
columns: [
|
||||||
light: false,
|
{ name: 'Backlog', headerColor: '#8E6E95', cards: [{}, {}] },
|
||||||
count: 0,
|
{ name: 'In Progress', headerColor: '#8E6E95', headerColor: '#39A59C', cards: [{}, {}] },
|
||||||
|
{ name: 'Ready for Review', headerColor: '#344759', cards: [{}, {}] },
|
||||||
|
{ name: 'Completed', headerColor: '#E8741E', cards: [{}, {}] },
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const reducer = (state = initialState, action) => {
|
const reducer = (state = initialState, {type, payload}) => {
|
||||||
switch (action.type) {
|
switch (type) {
|
||||||
case 'TICK':
|
case 'ADD_CARD':
|
||||||
|
newCards = [...state.columns[action.payload.column].cards, { text: payload.text }];
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
lastUpdate: action.lastUpdate,
|
};
|
||||||
light: !!action.light,
|
|
||||||
}
|
|
||||||
case 'INCREMENT':
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
count: state.count + 1,
|
|
||||||
}
|
|
||||||
case 'DECREMENT':
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
count: state.count - 1,
|
|
||||||
}
|
|
||||||
case 'RESET':
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
count: initialState.count,
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue