-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polish UI
149 lines (130 loc) · 4.2 KB
/
Polish UI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
Styling with Material-UI:
Customize Theme: Define a theme to ensure consistent styling.
javascript
import { createTheme, ThemeProvider } from '@mui/material/styles';
const theme = createTheme({
palette: {
primary: {
main: '#1976d2',
},
secondary: {
main: '#dc004e',
},
},
typography: {
h1: {
fontSize: '2rem',
},
button: {
textTransform: 'none',
},
},
});
const App = () => (
<ThemeProvider theme={theme}>
{/* Your components */}
</ThemeProvider>
);
Make Components More Elegant: Update src/components/Search.js with Material-UI components for a polished look:
javascript
import React, { useState, useEffect } from 'react';
import API from '../api';
import { TextField, Button, List, ListItem, ListItemText, Box, Typography, Container } from '@mui/material';
const Search = () => {
const [query, setQuery] = useState('');
const [results, setResults] = useState([]);
const [suggestions, setSuggestions] = useState([]);
const handleSearch = async () => {
const data = await API.get(`/search?q=${query}`);
if (data) setResults(data.webPages.value);
};
const fetchSuggestions = async (q) => {
const data = await API.get(`/suggest?q=${q}`);
if (data) setSuggestions(data.suggestionGroups[0].searchSuggestions);
};
useEffect(() => {
if (query.length > 2) {
fetchSuggestions(query);
} else {
setSuggestions([]);
}
}, [query]);
return (
<Container>
<Typography variant="h1" gutterBottom>
Search Visualizer
</Typography>
<TextField
label="Search"
variant="outlined"
value={query}
onChange={(e) => setQuery(e.target.value)}
fullWidth
margin="normal"
/>
<Button
variant="contained"
color="primary"
onClick={handleSearch}
sx={{ marginTop: 2 }}
>
Search
</Button>
<Box mt={2}>
<Typography variant="h6">Suggestions:</Typography>
<List>
{suggestions.map((suggestion, index) => (
<ListItem key={index}>
<ListItemText primary={suggestion.displayText} />
</ListItem>
))}
</List>
</Box>
<Box mt={2}>
<Typography variant="h6">Results:</Typography>
<List>
{results.map((result) => (
<ListItem key={result.id}>
<ListItemText
primary={result.name}
secondary={result.url}
/>
</ListItem>
))}
</List>
</Box>
</Container>
);
};
export default Search;
Polish Navigation: Ensure a smooth user experience with src/App.js:
javascript
import React from 'react';
import { BrowserRouter as Router, Route, Routes, Link } from 'react-router-dom';
import Search from './components/Search';
import Profile from './components/Profile';
import Analytics from './components/Analytics';
import { AppBar, Toolbar, Button } from '@mui/material';
const App = () => (
<Router>
<AppBar position="static">
<Toolbar>
<Button color="inherit" component={Link} to="/">
Search
</Button>
<Button color="inherit" component={Link} to="/profile">
Profile
</Button>
<Button color="inherit" component={Link} to="/analytics">
Analytics
</Button>
</Toolbar>
</AppBar>
<Routes>
<Route path="/" element={<Search />} />
<Route path="/profile" element={<Profile />} />
<Route path="/analytics" element={<Analytics />} />
</Routes>
</Router>
);
export default App;