Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ZRoom_App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
SCCA
ZRoom_App
Commits
df75b05e
Commit
df75b05e
authored
3 years ago
by
Mehmet Salih Hasanoglu
Browse files
Options
Downloads
Patches
Plain Diff
frontend state updated
parent
ad0f43e1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
frontend/src/App.js
+23
-27
23 additions, 27 deletions
frontend/src/App.js
frontend/src/components/reaction.jsx
+4
-11
4 additions, 11 deletions
frontend/src/components/reaction.jsx
frontend/src/components/reactions.jsx
+1
-5
1 addition, 5 deletions
frontend/src/components/reactions.jsx
with
28 additions
and
43 deletions
frontend/src/App.js
+
23
−
27
View file @
df75b05e
...
@@ -3,8 +3,6 @@ import Reactions from "./components/reactions";
...
@@ -3,8 +3,6 @@ import Reactions from "./components/reactions";
import
"
./App.css
"
;
import
"
./App.css
"
;
import
logo
from
"
./ZRoom_Logo.png
"
;
import
logo
from
"
./ZRoom_Logo.png
"
;
//import { render } from "@testing-library/react";
class
App
extends
Component
{
class
App
extends
Component
{
state
=
{
state
=
{
reactions
:
[
reactions
:
[
...
@@ -27,13 +25,27 @@ class App extends Component {
...
@@ -27,13 +25,27 @@ class App extends Component {
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
milliseconds
))
return
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
milliseconds
))
}
}
componentDidUpdate
(
prev
ious
Props
,
prev
ious
State
)
{
componentDidUpdate
(
prevProps
,
prevState
)
{
this
.
sleep
(
5000
).
then
(
r
=>
{
this
.
sleep
(
5000
).
then
(
r
=>
{
if
(
previousState
.
reactions
!==
this
.
state
.
reactions
)
{
for
(
var
i
=
0
;
i
<
this
.
state
.
reactions
.
length
;
i
++
)
{
this
.
state
.
reactions
=
previousState
.
reactions
if
(
this
.
state
.
reactions
[
i
].
value
==
"
Befehl wird gesendet ...
"
)
{
this
.
setState
(
this
.
state
.
reactions
);
this
.
setState
({
reactions
:
[
{
id
:
1
,
value
:
"
Frage ?
"
},
{
id
:
2
,
value
:
"
Daumen Hoch
"
},
{
id
:
3
,
value
:
"
Problem !
"
},
],
})
}
}
}
})
})
// this.sleep(5000).then(r => {
// if (previousState.reactions !== this.state.reactions) {
// this.state.reactions = previousState.reactions
// this.setState(this.state.reactions);
// }
// })
}
}
handleClick
=
(
reaction
)
=>
{
handleClick
=
(
reaction
)
=>
{
...
@@ -42,40 +54,24 @@ class App extends Component {
...
@@ -42,40 +54,24 @@ class App extends Component {
reactions
[
index
]
=
{
...
reaction
};
reactions
[
index
]
=
{
...
reaction
};
reactions
[
index
].
value
=
"
Befehl wird gesendet ...
"
;
reactions
[
index
].
value
=
"
Befehl wird gesendet ...
"
;
//
for (var i = 0; i < reactions.length; i++) {
for
(
var
i
=
0
;
i
<
reactions
.
length
;
i
++
)
{
//
reactions[i].value = index === i ? "Befehl wird gesendet ..." : "Warten ...";
reactions
[
i
].
value
=
index
===
i
?
"
Befehl wird gesendet ...
"
:
"
Warten ...
"
;
//
}
}
const
requestURL
=
"
http://localhost:5000/lamp/
"
+
reactions
[
index
].
id
+
"
/activate
"
const
requestURL
=
"
http://0.0.0.0:5000/lamp/
"
+
reactions
[
index
].
id
+
"
/activate
"
//alert(requestURL)
fetch
(
requestURL
)
fetch
(
requestURL
)
this
.
setState
({
reactions
});
this
.
setState
({
reactions
});
};
};
handleReset
=
()
=>
{
const
reactions
=
this
.
state
.
reactions
.
map
((
c
)
=>
{
c
.
value
=
0
;
return
c
;
});
this
.
setState
({
reactions
});
};
handleDelete
=
(
reactionId
)
=>
{
const
reactions
=
this
.
state
.
reactions
.
filter
((
c
)
=>
c
.
id
!==
reactionId
);
this
.
setState
({
reactions
});
};
render
()
{
render
()
{
console
.
log
(
"
App - Rendered
"
);
console
.
log
(
"
App - Rendered
"
);
return
(
return
(
<
React
.
Fragment
>
<
React
.
Fragment
>
<
main
className
=
"
container
"
>
<
main
className
=
"
container
"
>
<
img
src
=
{
logo
}
alt
=
"
ZRoom Logo
"
class
=
"
rounded mx-auto d-block m-5
"
/>
<
img
src
=
{
logo
}
alt
=
"
ZRoom Logo
"
class
Name
=
"
rounded mx-auto d-block m-5
"
/>
<
Reactions
<
Reactions
reactions
=
{
this
.
state
.
reactions
}
reactions
=
{
this
.
state
.
reactions
}
onReset
=
{
this
.
handleReset
}
onClick
=
{
this
.
handleClick
}
onClick
=
{
this
.
handleClick
}
onDelete
=
{
this
.
handleDelete
}
/
>
/
>
<
/main
>
<
/main
>
<
/React.Fragment
>
<
/React.Fragment
>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/components/reaction.jsx
+
4
−
11
View file @
df75b05e
...
@@ -19,9 +19,9 @@ class Reaction extends Component {
...
@@ -19,9 +19,9 @@ class Reaction extends Component {
componentDidUpdate
(
prevProps
,
prevState
)
{
componentDidUpdate
(
prevProps
,
prevState
)
{
console
.
log
(
"
prevProps
"
,
prevProps
);
console
.
log
(
"
prevProps
"
,
prevProps
);
console
.
log
(
"
prevState
"
,
prevState
);
console
.
log
(
"
prevState
"
,
prevState
);
if
(
prevProps
.
reaction
.
value
!==
this
.
props
.
reaction
.
value
)
{
//
if (prevProps.reaction.value !== this.props.reaction.value) {
// Ajax call and get new data from the server
//
// Ajax call and get new data from the server
}
//
}
}
}
componentWillUnmount
()
{
componentWillUnmount
()
{
...
@@ -31,19 +31,12 @@ class Reaction extends Component {
...
@@ -31,19 +31,12 @@ class Reaction extends Component {
console
.
log
(
"
Reaction - Rendered
"
);
console
.
log
(
"
Reaction - Rendered
"
);
return
(
return
(
<
div
>
<
div
>
{
/* <span className={this.getBadgeClasses()}>{this.getValue()}</span> */
}
<
button
disabled
=
{
this
.
getValue
()
==
"
Warten ...
"
||
this
.
getValue
()
==
"
Befehl wird gesendet ...
"
}
<
button
onClick
=
{
()
=>
this
.
props
.
onClick
(
this
.
props
.
reaction
)
}
onClick
=
{
()
=>
this
.
props
.
onClick
(
this
.
props
.
reaction
)
}
className
=
{
this
.
getBadgeClasses
()
}
className
=
{
this
.
getBadgeClasses
()
}
>
>
{
this
.
getValue
()
}
{
this
.
getValue
()
}
</
button
>
</
button
>
{
/* <button
onClick={() => this.props.onDelete(this.props.reaction.id)}
className="btn btn-danger btn-sm m-2"
>
Delete
</button> */
}
</
div
>
</
div
>
);
);
}
}
...
...
This diff is collapsed.
Click to expand it.
frontend/src/components/reactions.jsx
+
1
−
5
View file @
df75b05e
...
@@ -4,16 +4,12 @@ import Reaction from "./reaction";
...
@@ -4,16 +4,12 @@ import Reaction from "./reaction";
class
Reactions
extends
Component
{
class
Reactions
extends
Component
{
render
()
{
render
()
{
console
.
log
(
"
Reactions - Rendered
"
);
console
.
log
(
"
Reactions - Rendered
"
);
const
{
onReset
,
reactions
,
onDelete
,
onClick
}
=
this
.
props
;
const
{
reactions
,
onClick
}
=
this
.
props
;
return
(
return
(
<
div
>
<
div
>
<
button
onClick
=
{
onReset
}
className
=
"btn btn-primary btn-sm m-2"
>
Reset
</
button
>
{
reactions
.
map
((
reaction
)
=>
(
{
reactions
.
map
((
reaction
)
=>
(
<
Reaction
<
Reaction
key
=
{
reaction
.
id
}
key
=
{
reaction
.
id
}
onDelete
=
{
onDelete
}
onClick
=
{
onClick
}
onClick
=
{
onClick
}
reaction
=
{
reaction
}
reaction
=
{
reaction
}
/>
/>
...
...
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