diff --git a/src/screens/detail/SearchScreen.js b/src/screens/detail/SearchScreen.js index 0919771..75badb3 100644 --- a/src/screens/detail/SearchScreen.js +++ b/src/screens/detail/SearchScreen.js @@ -34,7 +34,7 @@ import {Dimensions} from 'react-native'; import {FlatList, TextInput} from 'react-native-gesture-handler'; import StoreCompo from '../../components/StoreCompo'; import axios, {AxiosError} from 'axios'; -import {API_URL} from '@env'; +import {API_URL, AUTO_COMPLETE} from '@env'; import AppContext from '../../components/AppContext'; const windowWidth = Dimensions.get('window').width; @@ -49,11 +49,7 @@ export default function SearchScreen(props) { const [searchText, setSearchText] = useState(''); const [recentSearch, setRecentSearch] = useState([]); - const [autoCompleteData, setAutoCompleteData] = useState([ - '햄버거', - '햄스터', - '햄토리', - ]); + const [autoCompleteData, setAutoCompleteData] = useState([]); useEffect(() => { initRecentSearch(); @@ -62,26 +58,19 @@ export default function SearchScreen(props) { const autocomplete = async inputString => { console.log('검색어:', inputString); try { - // console.log('context.accessToken:', context.accessToken); - - //TODO: 필터 조건 추가하기 - const params = { - text: inputString, + query: inputString, }; const queryString = new URLSearchParams(params).toString(); - const response = await axios.get( - `${API_URL}/v1/restaurants/autocomplete?${queryString}`, - { - headers: {Authorization: `Bearer ${context.accessToken}`}, - }, - ); + const response = await axios.get(`${AUTO_COMPLETE}?${queryString}`, { + headers: {Authorization: `Bearer ${context.accessToken}`}, + }); - console.log('response:', response.data.data); + console.log('response:', response.data.results); - // setStoreDartDatas(response.data.data.restaurants.content); + setAutoCompleteData(response.data.results); } catch (e) { console.log('error', e); } @@ -89,8 +78,6 @@ export default function SearchScreen(props) { const initRecentSearch = async () => { try { - // console.log('context.accessToken:', context.accessToken); - const response = await axios.get(`${API_URL}/v1/recents`, { headers: {Authorization: `Bearer ${context.accessToken}`}, }); @@ -117,8 +104,6 @@ export default function SearchScreen(props) { }); console.log('response:', response.data); - - // setRecentSearch(response.data.data.recentQueries); } catch (e) { if (axios.isAxiosError(e)) { console.log('Axios error:', e.response ? e.response.data : e.message); @@ -164,7 +149,7 @@ export default function SearchScreen(props) { style={styles.textInput} onChangeText={text => { setSearchText(text); - // autocomplete(text); + autocomplete(text); }} blurOnSubmit={false} maxLength={200} @@ -261,12 +246,11 @@ export default function SearchScreen(props) { { - console.log('item:', item); - setSearch(item); + setSearch(item.org_display); navigation.goBack(); }}> - {item} + {item.org_display} ); }} diff --git a/src/screens/list/ListMainScreen.js b/src/screens/list/ListMainScreen.js index 5db0ff7..7cdae01 100644 --- a/src/screens/list/ListMainScreen.js +++ b/src/screens/list/ListMainScreen.js @@ -91,6 +91,7 @@ export default function ListMainScreen() { const getStoreDatas = async p => { try { // console.log('context.accessToken:', context.accessToken); + setPageNumber(p + 1); let discountForSkku = false; @@ -212,6 +213,10 @@ export default function ListMainScreen() { break; } + if (search !== '') { + params.query = search; + } + const queryString = new URLSearchParams(params).toString(); const response = await axios.get( @@ -221,7 +226,7 @@ export default function ListMainScreen() { }, ); - console.log('response:', response.data.data.restaurants.content[0]); + // console.log('response:', response.data.data.restaurants.content[0]); if (p == 0) { setStoreDartDatas(response.data.data.restaurants.content); @@ -238,6 +243,9 @@ export default function ListMainScreen() { const onEndReached = () => { console.log('onEndReached', pageNumber); + if (pageNumber === 0) { + return; + } getStoreDatas(pageNumber); }; @@ -259,6 +267,7 @@ export default function ListMainScreen() { storeScoreNaver, replyNumNaver, myLocation, + search, ]); const listHeader = () => {