Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PROG2053-Project
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
Martin Wighus Holtmon
PROG2053-Project
Commits
c9c02efd
Commit
c9c02efd
authored
3 years ago
by
Martin Wighus Holtmon
Browse files
Options
Downloads
Patches
Plain Diff
Modified states to the one displayed in class
parent
fa2a2318
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
projectFirstPart/components/states/States.jsx
+33
-49
33 additions, 49 deletions
projectFirstPart/components/states/States.jsx
with
33 additions
and
49 deletions
projectFirstPart/components/states/States.jsx
+
33
−
49
View file @
c9c02efd
...
@@ -9,50 +9,34 @@ import './States.css';
...
@@ -9,50 +9,34 @@ import './States.css';
class
States
extends
React
.
Component
{
class
States
extends
React
.
Component
{
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
);
super
(
props
);
console
.
log
(
'
window.cs142models.statesModel()
'
,
window
.
cs142models
.
statesModel
());
this
.
state
=
{
states
:
window
.
cs142models
.
statesModel
().
sort
(),
displayedStates
:
window
.
cs142models
.
statesModel
().
sort
(),
searchValue
:
''
};
//console.log('window.cs142models.statesModel()', this.state.states);
}
}
findStates
(
event
)
{
onInputChange
=
(
event
)
=>
{
function
matchStates
(
value
,
statesModel
)
{
this
.
setState
({
let
results
=
[];
searchValue
:
event
.
target
.
value
,
statesModel
.
forEach
(
e
=>
{
displayedStates
:
this
.
state
.
states
.
filter
((
usStates
)
=>
usStates
.
toLowerCase
().
includes
(
event
.
target
.
value
.
toLowerCase
()))
if
(
e
.
toLowerCase
().
includes
(
value
))
results
.
push
(
e
)
});
});
return
results
;
}
let
out
=
document
.
getElementById
(
"
content
"
);
//Get table to edit
out
.
innerHTML
=
""
;
//Clear table
// Exit
if
(
event
.
target
.
value
==
""
)
{
return
""
;
}
// Get matching states
let
results
=
matchStates
(
event
.
target
.
value
,
window
.
cs142models
.
statesModel
());
// Update dive
if
(
results
.
length
==
0
)
{
out
.
innerHTML
=
"
<tr><td>There are no matching states to this string!</td></tr>
"
;
}
else
{
out
.
innerHTML
=
"
<tr><th>States</th></tr>
"
results
.
forEach
(
e
=>
{
out
.
innerHTML
+=
"
<tr><td>
"
+
e
.
toString
()
+
"
</td></tr>
"
})
}
}
}
render
()
{
render
()
{
return
(
return
(
<
div
>
<
div
>
<
label
htmlFor
=
"inName"
>
Name:
</
label
>
<
input
value
=
{
this
.
state
.
searchValue
}
onChange
=
{
this
.
onInputChange
}
/>
<
input
type
=
"text"
placeholder
=
"country"
id
=
"inName"
onChange
=
{
this
.
findStates
}
/>
<
div
>
{
this
.
state
.
searchValue
}
</
div
>
<
table
>
{
this
.
state
.
displayedStates
.
length
===
0
?
<
tbody
id
=
"content"
>
<
div
>
No matches
</
div
>
:
</
tbody
>
<
ul
>
</
table
>
{
this
.
state
.
displayedStates
.
map
((
usState
)
=>
<
li
key
=
{
usState
}
>
{
usState
}
</
li
>
)
}
</
ul
>
}
</
div
>
</
div
>
);
);
}
}
...
...
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