Ankilan/src/components/view/deck-picker.jsx

33 lines
1,010 B
React
Raw Normal View History

2020-03-07 14:30:26 +00:00
import React, {useEffect, useState} from 'react'
import {connect} from 'react-redux'
import {Picker, Text} from 'native-base'
2020-03-08 07:18:34 +00:00
import { getDeckList, getModelList} from '../../actions/anki-get-actions';
2020-03-07 14:30:26 +00:00
import {selectDeck} from '../../actions/anki-set-actions';
const DeckPicker = props => {
2020-03-07 19:38:01 +00:00
const [deckList, setDeckList] = useState([{name: "no decks", id: 0}]);
2020-03-07 14:30:26 +00:00
useEffect(() => {
props.getDeckList()
2020-03-08 07:18:34 +00:00
props.getModelList()
2020-03-07 14:30:26 +00:00
}, [])
2020-03-08 07:18:34 +00:00
useEffect(() => {
setDeckList(props.decks)
}, [props.decks])
2020-03-07 14:30:26 +00:00
return (
2020-03-08 07:18:34 +00:00
<Picker onValueChange={id => props.selectDeck({id, deck: deckList[id]})} selectedValue={props.selectedDeck.id}>
2020-03-07 19:38:01 +00:00
{deckList.map((deck, index) => (
<Picker.Item label={deck.name} key={deck.id} value={index}/>
2020-03-07 14:30:26 +00:00
))}
</Picker>
)
}
export default connect(state => ({
decks: state.anki.deckList,
selectedDeck: state.anki.selectedDeck
}),{
getDeckList,
2020-03-08 07:18:34 +00:00
selectDeck,
getModelList
2020-03-07 14:30:26 +00:00
})(DeckPicker)