Skip to content

Commit af0ccc1

Browse files
committed
added search bar functions
1 parent 37f3efd commit af0ccc1

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

artifact_MobileApp/SearchBar.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
// SearchBar.js
22
import React, { useState } from 'react';
3+
import apiInstance from './Api';
4+
import Toast from 'react-native-toast-message';
35
import { View, TextInput, TouchableOpacity, StyleSheet } from 'react-native';
46
import { Ionicons } from '@expo/vector-icons';
57

68
const SearchBar = () => {
79
const [searchText, setSearchText] = useState('');
810

9-
const handleSearch = (val) => {
10-
console.log({val});
11-
//link to wikiData API here ...
12-
setSearchText('');
11+
const handleSearch = async (val) => {
12+
try {
13+
const response = await apiInstance().post("search", {
14+
query: val
15+
})
16+
17+
if (response.status === 200) {
18+
19+
const data = await response.data
20+
21+
console.log(data)
22+
23+
setSearchText("")
24+
}
25+
} catch (e) {
26+
console.log(e)
27+
Toast.show({
28+
type: 'error',
29+
position: 'bottom',
30+
text1: 'Search Error',
31+
text2: 'There was an error while searching. Please try again.',
32+
visibilityTime: 2000,
33+
autoHide: true,
34+
topOffset: 30,
35+
bottomOffset: 40
36+
});
37+
}
1338

1439
};
1540

artifact_backend/artifact/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
'http://localhost:3000',
3939
'https://bounswe.github.io',
4040
'https://frontend-yslcfqdwna-oa.a.run.app',
41-
'http://192.168.1.31:8081'
41+
'http://localhost:8081'
4242
]
4343

4444
CORS_ALLOW_CREDENTIALS = True

0 commit comments

Comments
 (0)