From af0ccc1f40a9376e3bb643a99a38f4455ee627ca Mon Sep 17 00:00:00 2001 From: aasimdag Date: Tue, 30 Apr 2024 21:45:16 +0300 Subject: [PATCH] added search bar functions --- artifact_MobileApp/SearchBar.js | 33 +++++++++++++++++++++++---- artifact_backend/artifact/settings.py | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/artifact_MobileApp/SearchBar.js b/artifact_MobileApp/SearchBar.js index e125714..d622f8f 100644 --- a/artifact_MobileApp/SearchBar.js +++ b/artifact_MobileApp/SearchBar.js @@ -1,15 +1,40 @@ // SearchBar.js import React, { useState } from 'react'; +import apiInstance from './Api'; +import Toast from 'react-native-toast-message'; import { View, TextInput, TouchableOpacity, StyleSheet } from 'react-native'; import { Ionicons } from '@expo/vector-icons'; const SearchBar = () => { const [searchText, setSearchText] = useState(''); - const handleSearch = (val) => { - console.log({val}); - //link to wikiData API here ... - setSearchText(''); + const handleSearch = async (val) => { + try { + const response = await apiInstance().post("search", { + query: val + }) + + if (response.status === 200) { + + const data = await response.data + + console.log(data) + + setSearchText("") + } + } catch (e) { + console.log(e) + Toast.show({ + type: 'error', + position: 'bottom', + text1: 'Search Error', + text2: 'There was an error while searching. Please try again.', + visibilityTime: 2000, + autoHide: true, + topOffset: 30, + bottomOffset: 40 + }); + } }; diff --git a/artifact_backend/artifact/settings.py b/artifact_backend/artifact/settings.py index b6455e9..a4a4cae 100644 --- a/artifact_backend/artifact/settings.py +++ b/artifact_backend/artifact/settings.py @@ -38,7 +38,7 @@ 'http://localhost:3000', 'https://bounswe.github.io', 'https://frontend-yslcfqdwna-oa.a.run.app', - 'http://192.168.1.31:8081' + 'http://localhost:8081' ] CORS_ALLOW_CREDENTIALS = True