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'
|
|
|
|
import { getDeckList} from '../../actions/anki-get-actions';
|
|
|
|
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()
|
|
|
|
setDeckList(props.decks)
|
|
|
|
}, [])
|
|
|
|
return (
|
2020-03-07 19:38:01 +00:00
|
|
|
<Picker onValueChange={id => props.selectDeck(id)} selectedValue={props.selectedDeck} >
|
|
|
|
{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-07 19:38:01 +00:00
|
|
|
selectDeck
|
2020-03-07 14:30:26 +00:00
|
|
|
})(DeckPicker)
|