Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
171 lines (160 loc) · 4.99 KB
/
Copy pathApp.js
File metadata and controls
171 lines (160 loc) · 4.99 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import {Component} from 'react'
import './App.css'
// These are the list used in the application. You can move them to any component needed.
const initialHistoryList = [
{
id: 0,
timeAccessed: '07:45 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/instagram-img.png',
title: 'Instagram',
domainUrl: 'instagram.com',
},
{
id: 1,
timeAccessed: '05:45 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/twitter-img.png',
title: 'Twitter. It’s what’s happening / Twitter',
domainUrl: 'twitter.com',
},
{
id: 2,
timeAccessed: '04:35 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/facebook-img.png',
title: 'Facebook – log in or sign up',
domainUrl: 'facebook.com',
},
{
id: 3,
timeAccessed: '04:25 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/linkedin-img.png',
title: 'LinkedIn: Log In or Sign Up',
domainUrl: 'linkedin.com',
},
{
id: 4,
timeAccessed: '04:00 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/hashnode-img.png',
title: 'Hashnode: Everything you need to start blogging as a developer!',
domainUrl: 'hashnode.com',
},
{
id: 5,
timeAccessed: '03:25 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/github-img.png',
title: 'GitHub: Where the world builds software · GitHub',
domainUrl: 'github.com',
},
{
id: 6,
timeAccessed: '02:45 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/react-img.png',
title: 'React – A JavaScript library for building user interfaces',
domainUrl: 'reactjs.org',
},
{
id: 7,
timeAccessed: '01:25 PM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/stackoverflow-img.png',
title: 'Stack Overflow - Where Developers Learn, Share, & Build Careers',
domainUrl: 'stackoverflow.com',
},
{
id: 8,
timeAccessed: '09:25 AM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/gmail-img.png',
title: 'Gmail',
domainUrl: 'mail.google.com',
},
{
id: 9,
timeAccessed: '09:00 AM',
logoUrl: 'https://assets.ccbp.in/frontend/react-js/google-img.png',
title: 'Google',
domainUrl: 'google.com',
},
]
// Replace your code here
class App extends Component {
state = {
searchInput: '',
historyList: initialHistoryList,
}
handleChange = event => {
this.setState({searchInput: event.target.value})
}
deleteHistoryItem = id => {
const {historyList} = this.state
const updatedHistoryList = historyList.filter(
eachItem => eachItem.id !== id,
)
this.setState({historyList: updatedHistoryList})
}
render() {
const {searchInput, historyList} = this.state
const filteredHistoryList = historyList.filter(eachItem =>
eachItem.title.toLowerCase().includes(searchInput.toLowerCase()),
)
return (
<div className="bg-container">
<div className="header-container">
<img
src="https://assets.ccbp.in/frontend/react-js/history-website-logo-img.png"
alt="app logo"
className="app-logo"
/>
<div className="search-bar">
<img
src="https://assets.ccbp.in/frontend/react-js/search-img.png"
alt="search"
className="search-icon"
/>
<input
type="search"
value={searchInput}
onChange={this.handleChange}
className="input-container"
placeholder="Search History"
/>
</div>
</div>
<div className="details-container">
{filteredHistoryList.length > 0 ? (
<ul className="historyList-container">
{filteredHistoryList.map(eachItem => (
<li className="history-item" key={eachItem.id}>
<div className="item-info">
<p className="time">{eachItem.timeAccessed}</p>
<div className="title-container">
<img
className="domain-logo"
src={eachItem.logoUrl}
alt="domain logo"
/>
<p className="title">{eachItem.title}</p>
<p className="domain">{eachItem.domainUrl}</p>
</div>
</div>
<button
type="button"
className="delete-button"
onClick={() => this.deleteHistoryItem(eachItem.id)}
data-testid="delete"
>
<img
src="https://assets.ccbp.in/frontend/react-js/delete-img.png"
alt="delete"
className="delete-icon"
/>
</button>
</li>
))}
</ul>
) : (
<p className="empty-history">There is no history to show</p>
)}
</div>
</div>
)
}
}
export default App