add items page
This commit is contained in:
parent
1ca78c34f1
commit
9f9f8affe0
@ -46,3 +46,29 @@ export const getStoreList = () => dispatch => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getItems = (id) => dispatch => {
|
||||||
|
dispatch(toggleLoading(1))
|
||||||
|
fetch(`${apiUrl}/item/${id}`, genRequest())
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(json => {
|
||||||
|
dispatch(toggleLoading(0))
|
||||||
|
if(json.status != 1) return dispatch(addDialog(json.message))
|
||||||
|
return dispatch({
|
||||||
|
type: 'items',
|
||||||
|
list: json.record || []
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearStore = () => ({
|
||||||
|
type: 'clear_store'
|
||||||
|
})
|
||||||
|
export const clearItems = () => ({
|
||||||
|
type: 'clear_items'
|
||||||
|
})
|
||||||
|
|
||||||
|
export const toPage = (page = 0) => ({
|
||||||
|
type: 'page',
|
||||||
|
page
|
||||||
|
})
|
37
src/components/ItemsPage/index.js
Normal file
37
src/components/ItemsPage/index.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { View, Text, ListView, RefreshControl, TouchableOpacity } from 'react-native'
|
||||||
|
|
||||||
|
const ds = new ListView.DataSource({
|
||||||
|
rowHasChanged: (r1, r2) => {
|
||||||
|
return r1.name != r2.name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default ItemsPage = ({ dev, show, list, refresh, getList, backPage }) => {
|
||||||
|
if (!show) return null
|
||||||
|
console.log('Items')
|
||||||
|
return (
|
||||||
|
<View style={{ flex: 1 }}>
|
||||||
|
<View style={{
|
||||||
|
height: 25,
|
||||||
|
marginTop: 5,
|
||||||
|
marginLeft: 10,
|
||||||
|
marginRight: 10,
|
||||||
|
marginBottom: 5
|
||||||
|
}}>
|
||||||
|
<TouchableOpacity onPress={() => backPage()}>
|
||||||
|
<Text style={{fontSize: 20}}><<Back</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
<ListView
|
||||||
|
refreshControl={<RefreshControl refreshing={refresh} onRefresh={getList} />}
|
||||||
|
enableEmptySections={true}
|
||||||
|
dataSource={ds.cloneWithRows(list)}
|
||||||
|
renderRow={data => {
|
||||||
|
return (
|
||||||
|
<Text>{data.name} / {data.price}</Text>
|
||||||
|
)
|
||||||
|
}} />
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { View, Text, TouchableOpacity } from 'react-native';
|
import { View, Text, TouchableOpacity } from 'react-native';
|
||||||
|
|
||||||
const Item = ({ name }) => {
|
const Item = ({ name, onClick }) => {
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={{
|
<TouchableOpacity style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@ -10,12 +10,14 @@ const Item = ({ name }) => {
|
|||||||
paddingBottom: 5,
|
paddingBottom: 5,
|
||||||
paddingLeft: 10,
|
paddingLeft: 10,
|
||||||
paddingRight: 10
|
paddingRight: 10
|
||||||
}} onPress={() => { console.log(`item press`); }}>
|
}} onPress={() => { onClick() }}>
|
||||||
<View style={{
|
<View style={{
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: 'column'
|
flexDirection: 'column'
|
||||||
}}>
|
}}>
|
||||||
<Text>{name}</Text>
|
<Text style={{
|
||||||
|
fontSize: 20
|
||||||
|
}}>{name}</Text>
|
||||||
</View>
|
</View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {View, Text, ListView, RefreshControl} from 'react-native'
|
import {View, Text, ListView, RefreshControl} from 'react-native'
|
||||||
|
|
||||||
const ds = new ListView.DataSource({
|
import Item from './Item'
|
||||||
|
|
||||||
|
const ds1 = new ListView.DataSource({
|
||||||
rowHasChanged: (r1, r2) => {
|
rowHasChanged: (r1, r2) => {
|
||||||
return r1.name != r2.name
|
return r1.name != r2.name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export default StoreList = ({dev, show, list, refresh, getList}) => {
|
export default StoreList = ({dev, show, list, refresh, getList, loadItems}) => {
|
||||||
if(!show) return null
|
if(!show) return null
|
||||||
|
console.log('Store', list)
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1}}>
|
<View style={{flex: 1}}>
|
||||||
<ListView
|
<ListView
|
||||||
refreshControl={<RefreshControl refreshing={refresh} onRefresh={getList} />}
|
refreshControl={<RefreshControl refreshing={refresh} onRefresh={getList} />}
|
||||||
enableEmptySections={true}
|
enableEmptySections={true}
|
||||||
dataSource={ds.cloneWithRows(list)}
|
dataSource={ds1.cloneWithRows(list)}
|
||||||
renderRow={data => {
|
renderRow={data => {
|
||||||
return (
|
return (
|
||||||
<Text>{data.name}</Text>
|
<Item name={data.name} onClick={()=>loadItems(data.id)} />
|
||||||
)
|
)
|
||||||
}} />
|
}} />
|
||||||
</View>
|
</View>
|
||||||
|
23
src/containers/ItemsPage.js
Normal file
23
src/containers/ItemsPage.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import {connect} from 'react-redux'
|
||||||
|
import ItemsPage from '../components/ItemsPage'
|
||||||
|
import {toPage, getStoreList, clearItems} from '../actions'
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => ({
|
||||||
|
dev: state.sys.dev,
|
||||||
|
show: state.ui.page == 1,
|
||||||
|
refresh: state.ui.loading,
|
||||||
|
list: state.sys.items || []
|
||||||
|
})
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||||
|
getList: () => {
|
||||||
|
dispatch(getItems())
|
||||||
|
},
|
||||||
|
backPage: () => {
|
||||||
|
dispatch(clearItems())
|
||||||
|
dispatch(toPage(0))
|
||||||
|
dispatch(getStoreList())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(ItemsPage)
|
@ -1,6 +1,6 @@
|
|||||||
import {connect} from 'react-redux'
|
import {connect} from 'react-redux'
|
||||||
import StoreList from '../components/StoreList'
|
import StoreList from '../components/StoreList'
|
||||||
import {getStoreList} from '../actions'
|
import {getStoreList, getItems, toPage, clearStore} from '../actions'
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
dev: state.sys.dev,
|
dev: state.sys.dev,
|
||||||
@ -12,6 +12,11 @@ const mapStateToProps = (state) => ({
|
|||||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||||
getList: () => {
|
getList: () => {
|
||||||
dispatch(getStoreList())
|
dispatch(getStoreList())
|
||||||
|
},
|
||||||
|
loadItems: (id) => {
|
||||||
|
dispatch(clearStore())
|
||||||
|
dispatch(toPage(1))
|
||||||
|
dispatch(getItems(id))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
19
src/index.js
19
src/index.js
@ -8,6 +8,7 @@ import {SetDev, getStoreList} from './actions'
|
|||||||
|
|
||||||
// import pages
|
// import pages
|
||||||
import StoreList from './containers/StoreList'
|
import StoreList from './containers/StoreList'
|
||||||
|
import ItemsPage from './containers/ItemsPage'
|
||||||
|
|
||||||
const middleware = [thunk]
|
const middleware = [thunk]
|
||||||
|
|
||||||
@ -17,6 +18,19 @@ store.subscribe(() => {
|
|||||||
console.log(JSON.stringify(store.getState()))
|
console.log(JSON.stringify(store.getState()))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const VV = (props) => {
|
||||||
|
console.log(props)
|
||||||
|
return (
|
||||||
|
<View style={{flex: 1}}>
|
||||||
|
{
|
||||||
|
props.children
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const CView = connect()(VV)
|
||||||
|
|
||||||
class Main extends React.Component {
|
class Main extends React.Component {
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
@ -28,7 +42,10 @@ class Main extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<StoreList />
|
<CView>
|
||||||
|
<StoreList />
|
||||||
|
<ItemsPage />
|
||||||
|
</CView>
|
||||||
</Provider>
|
</Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,12 @@ export default sysReducer = (state = stateDefault(), action) => {
|
|||||||
return { ...state, dev: action.dev }
|
return { ...state, dev: action.dev }
|
||||||
case 'store':
|
case 'store':
|
||||||
return { ...state, store: action.list }
|
return { ...state, store: action.list }
|
||||||
|
case 'clear_store':
|
||||||
|
return { ...state, store: [] }
|
||||||
|
case 'clear_items':
|
||||||
|
return { ...state, items: [] }
|
||||||
|
case 'items':
|
||||||
|
return { ...state, items: action.list }
|
||||||
default:
|
default:
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user