Skip to content

Commit 5eaf82e

Browse files
simonprevremi
andauthored
Add minimal LiveView setup with a /live example page (#258)
* Add minimal LiveView setup with a /live example page * Format * Refactor app.js --------- Co-authored-by: Rémi Prévost <rprevost@mirego.com>
1 parent 02a5d04 commit 5eaf82e

33 files changed

+542
-400
lines changed

assets/css/app.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
align-items: center;
66
padding: 40px;
77
text-align: center;
8+
font-family:
9+
system-ui,
10+
-apple-system,
11+
'Segoe UI',
12+
Roboto,
13+
'Helvetica Neue',
14+
Arial,
15+
'Noto Sans',
16+
'Liberation Sans',
17+
sans-serif,
18+
'Apple Color Emoji',
19+
'Segoe UI Emoji',
20+
'Segoe UI Symbol',
21+
'Noto Color Emoji';
822
line-height: 1.4;
923
}
1024

@@ -20,3 +34,10 @@
2034
.home p:last-child {
2135
margin-bottom: 0;
2236
}
37+
38+
.flash-messages {
39+
position: fixed;
40+
top: 0;
41+
right: 0;
42+
padding: 10px;
43+
}

assets/js/app.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
import 'simple-css-reset/reset.css';
22
import '../css/app.css';
3+
4+
import {Socket} from 'phoenix';
5+
import {LiveSocket} from 'phoenix_live_view';
6+
7+
const FLASH_TTL = 8000;
8+
const Hooks = {};
9+
10+
Hooks.Flash = {
11+
mounted() {
12+
this.timer = setTimeout(() => this._hide(), FLASH_TTL);
13+
14+
this.el.addEventListener('mouseover', () => {
15+
clearTimeout(this.timer);
16+
this.timer = setTimeout(() => this._hide(), FLASH_TTL);
17+
});
18+
},
19+
20+
destroyed() {
21+
clearTimeout(this.timer);
22+
},
23+
24+
_hide() {
25+
liveSocket.execJS(this.el, this.el.getAttribute('phx-click'));
26+
}
27+
};
28+
29+
const csrfToken = document
30+
.querySelector("meta[name='csrf-token']")
31+
.getAttribute('content');
32+
33+
const liveSocket = new LiveSocket('/live', Socket, {
34+
hooks: Hooks,
35+
params: {_csrf_token: csrfToken} // eslint-disable-line camelcase
36+
});
37+
38+
liveSocket.connect();

0 commit comments

Comments
 (0)