parent
1285a4aea7
commit
b26c57abe0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,10 @@
|
||||
import { Kanji } from '../../model/kanji';
|
||||
import { SET_PLAYGROUND_LIST } from '../constants';
|
||||
|
||||
export const setPlaygroundList = (kanjis: Kanji[]) => {
|
||||
console.log("SET");
|
||||
return {
|
||||
type: SET_PLAYGROUND_LIST,
|
||||
payload: kanjis,
|
||||
};
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
export const SET_SELECTED_KANJI = 'SET_SELECTED_KANJI';
|
||||
export const SET_KANJIS = 'SET_KANJIS';
|
||||
export const SET_KANJIS = 'SET_KANJIS';
|
||||
export const SET_PLAYGROUND_LIST = 'SET_PLAYGROUND_LIST';
|
@ -0,0 +1,40 @@
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { Kanji } from '../../model/kanji';
|
||||
import { initKanjiListByGrade, KanjiListByGrade } from '../../model/kanjiListByGrades';
|
||||
import { KanjiMapper } from '../../model/kanjiMapper';
|
||||
import { setPlaygroundList } from '../actions/setPlaygroundList';
|
||||
|
||||
// @ts-ignore
|
||||
export const searchKanjis = async (search: string) => {
|
||||
|
||||
const options = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-RapidAPI-Key': '19516a9900mshce10de76f99976bp10f192jsn8c8d82222baa',
|
||||
'X-RapidAPI-Host': 'kanjialive-api.p.rapidapi.com'
|
||||
}
|
||||
};
|
||||
|
||||
return async (dispatch) => {
|
||||
const fetchAll = async () => {
|
||||
const data = await fetch(`https://kanjialive-api.p.rapidapi.com/api/public/search/${search}`, options)
|
||||
.then(response => response.json());
|
||||
|
||||
const fetchPromises = data.map(it =>
|
||||
fetch(`https://kanjialive-api.p.rapidapi.com/api/public/kanji/${it.kanji.character}`, options)
|
||||
.then(detail => detail.json())
|
||||
);
|
||||
|
||||
const kanjis = await Promise.all(fetchPromises)
|
||||
.then(details => details.map(detail_data => KanjiMapper.ApiJsonToKanji(detail_data)));
|
||||
|
||||
return kanjis;
|
||||
};
|
||||
|
||||
return fetchAll()
|
||||
.then(kanjis => dispatch(setPlaygroundList(kanjis)))
|
||||
.catch(err => console.log("ERR : " + err));
|
||||
|
||||
|
||||
};
|
||||
}
|
Loading…
Reference in new issue