-
Notifications
You must be signed in to change notification settings - Fork 0
/
stateful-rating.html
58 lines (53 loc) · 1.93 KB
/
stateful-rating.html
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
<!DOCTYPE html>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/vendor/mui/mui.min.css" />
<script src="/vendor/jquery/jquery.js"></script>
<script src="/vendor/mui/mui.min.js"></script>
<div class="mui-container-fluid">
<div id="rank" class="mui--text-dark-secondary mui--text-display4">0</div>
<div class="mui-panel">
<div class="mui--text-dark mui--text-subhead">
when this page is opened, the figure above shows what the rank is atm.
<br />
when you click the buttons below, <br />
backend Haskell code is called to increase/decrease current rank, <br />
the new rank is then communicated back, to update the figure above.
</div>
<div
style="background-color:#444;"
class="mui--text-light mui--text-subhead"
>
refresh & click buttons in multiple windows displaying this page to get
the feel.
</div>
<div class="mui--text-accent">
only in publication mode (<i>hadui</i>), will multiple windows communicate
to each other; <br />
if run in development mode (<i>hadui-dev</i>), the state of rank in
backend is not shared, <br />
as each window is served by a dedicated backend process.
</div>
</div>
<button id="uprate" class="mui-btn mui-btn--fab mui-btn--primary">👍🏻</button>
<button id="downrate" class="mui-btn mui-btn--fab mui-btn--danger">👎🏻</button>
</div>
<script type="module">
import { withHadui } from "/hadui.js";
withHadui(ws => {
ws.send(`showCurrentRating`);
});
$("#uprate").click(() =>
withHadui(ws => {
// call backend Haskell function to increase from what recorded in
// the application state
ws.send(`increaseStatefulRating`);
})
);
$("#downrate").click(() =>
withHadui(ws => {
// call backend Haskell function to decrease from what recorded in
// the application state
ws.send(`decreaseStatefulRating`);
})
);
</script>