Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Book-Management-System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ashwanth K
Book-Management-System
Commits
16671842
Commit
16671842
authored
4 years ago
by
Ashwanth K
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
65297000
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/src/Components/Forms/searchbook.jsx
+107
-0
107 additions, 0 deletions
client/src/Components/Forms/searchbook.jsx
with
107 additions
and
0 deletions
client/src/Components/Forms/searchbook.jsx
0 → 100644
+
107
−
0
View file @
16671842
import
React
,
{
Component
}
from
'
react
'
import
'
./forms.css
'
import
axios
from
'
axios
'
;
export
default
class
Search
extends
Component
{
constructor
(
props
){
super
(
props
)
this
.
state
=
{
searchby
:
'
book_name
'
,
inp
:
''
,
objects
:[],
test
:
0
}
this
.
handleChange
=
this
.
handleChange
.
bind
(
this
);
this
.
handleinp
=
this
.
handleinp
.
bind
(
this
);
this
.
rendertable
=
this
.
rendertable
.
bind
(
this
);
this
.
search
=
this
.
search
.
bind
(
this
);
this
.
view
=
this
.
view
.
bind
(
this
);
}
handleChange
(
event
)
{
this
.
setState
({
searchby
:
event
.
target
.
name
});
}
handleinp
(
event
){
this
.
setState
({
inp
:
event
.
target
.
value
});
}
view
(){
this
.
setState
({
searchby
:
'
book_name
'
})
}
rendertable
(){
if
(
this
.
state
.
test
===
0
){
return
<
h3
style
=
{
{
marginLeft
:
'
2%
'
}
}
>
Results will appear here
</
h3
>
}
else
if
(
this
.
state
.
objects
===
null
){
return
<
h3
>
No Results!
</
h3
>
}
else
{
return
<
div
style
=
{
{
marginLeft
:
'
2%
'
}
}
>
<
button
onClick
=
{
this
.
view
}
>
View Results
</
button
>
<
table
>
<
thead
>
<
tr
>
<
th
>
Book_id
</
th
>
<
th
>
Book_name
</
th
>
<
th
>
Author
</
th
>
<
th
>
price
</
th
>
</
tr
>
</
thead
>
<
tbody
>
{
this
.
state
.
objects
.
map
(
id
=>
(
<
Row
id
=
{
id
}
/>
))
}
</
tbody
>
</
table
>
</
div
>
}
}
search
(){
let
object
=
[];
axios
.
get
(
'
http://localhost:5000/book
'
)
.
then
(
response
=>
{
response
.
data
.
map
((
obj
,
idx
)
=>
{
if
(
obj
[
this
.
state
.
searchby
].
includes
(
this
.
state
.
inp
)){
object
.
push
(
obj
)
}
})})
this
.
setState
({
objects
:
object
,
test
:
1
});
console
.
log
(
object
);
}
render
(){
return
(
<
div
style
=
{
{
position
:
"
absolute
"
,
right
:
"
5%
"
,
top
:
"
6%
"
,
backgroundColor
:
"
white
"
,
width
:
"
600px
"
}
}
>
<
h3
style
=
{
{
marginLeft
:
'
2%
'
}
}
><
b
>
Search Books
</
b
></
h3
>
<
h4
style
=
{
{
marginLeft
:
'
2%
'
}
}
>
(directly click search to view all details)
</
h4
>
<
div
class
=
"dropdown"
style
=
{
{
marginLeft
:
"
2%
"
}
}
>
<
button
class
=
"dropbtn"
>
by name
</
button
>
<
div
class
=
"dropdown-content"
>
<
a
href
=
"#"
name
=
"book_name"
onClick
=
{
this
.
handleChange
}
>
by_name
</
a
>
<
a
href
=
"#"
name
=
"author"
onClick
=
{
this
.
handleChange
}
>
by_author
</
a
>
<
a
href
=
"#"
name
=
"_id"
onClick
=
{
this
.
handleChange
}
>
By_id
</
a
>
</
div
>
</
div
>
<
input
type
=
"text"
placeholder
=
"Search"
onChange
=
{
this
.
handleinp
}
style
=
{
{
marginLeft
:
"
2%
"
}
}
/>
<
button
onClick
=
{
this
.
search
}
className
=
"b1"
>
Search
</
button
>
{
this
.
rendertable
()
}
</
div
>
)
}
}
const
Row
=
({
id
})
=>
(
<
tr
style
=
{
{
backgroundColor
:
"
black
"
,
color
:
"
white
"
}
}
>
<
td
>
{
id
.
_id
}
</
td
>
<
td
>
{
id
.
book_name
}
</
td
>
<
td
>
{
id
.
author
}
</
td
>
<
td
>
{
id
.
price
}
</
td
>
</
tr
>
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment