Skip to content

Commit 410073e

Browse files
committed
public: better message box
1 parent 7e316ee commit 410073e

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
- [x] Test package support
44
- [x] Auto format && import
55
- [x] Dark mode
6-
- [ ] Message: waiting for SSA response
7-
- [ ] Better Editor: Monaco Editor
6+
- [x] Message: waiting for SSA response
87
- [ ] Dragable SSA
98
- [ ] Compiler flags, e.g. disable
109
- [ ] More environment variable support, need investigation
1110
- [ ] Use short link instead of UUID
12-
- [ ] Containerized deployment
11+
- [ ] Containerized deployment
12+
- [ ] Better Editor: Monaco Editor

public/main.js

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ function ping() {
33
document.getElementById('version').innerText = data.go_version;
44
});
55
}
6+
ping(); // inject version info
7+
8+
69

710
let msgbox = document.getElementById('outputMsg')
811
let ssabox = document.getElementById('ssa')
12+
ssabox.addEventListener('load', () => {
13+
// inject ssa style
14+
let $head = $("iframe").contents().find("head");
15+
$head.append($("<link/>", { rel: "stylesheet", href: "/gossa/scrollbar.css", type: "text/css"}));
16+
setMessageBox('', true)
17+
});
18+
919
let lastFuncName, lastCode;
1020
function build() {
1121
let funcname = document.getElementById('funcname').value;
@@ -17,18 +27,17 @@ function build() {
1727
return
1828
}
1929
if (!code.includes('func '+funcname)) {
20-
ssabox.src = ''
21-
msgbox.innerText = 'GOFUNCNAME does not exist in your code.'
30+
setMessageBox('GOFUNCNAME does not exist in your code.', false)
2231
return
2332
}
2433

25-
msgbox.innerText = ''
2634
lastFuncName = funcname
2735
lastCode = code
36+
setMessageBox('Waiting for response...', false)
2837

2938
fetch('/api/v1/buildssa', {
3039
method: 'POST',
31-
headers: {'Content-Type': 'application/json',},
40+
headers: {'Content-Type': 'application/json'},
3241
body: JSON.stringify({
3342
'funcname': funcname,
3443
'code': code,
@@ -44,24 +53,20 @@ function build() {
4453
})
4554
.then(res => {
4655
ssabox.src = `/gossa/buildbox/${res.data.build_id}/ssa.html`
47-
msgbox.innerText = ''
4856
})
49-
.catch(res => {
50-
ssabox.src = ''
51-
msgbox.innerText = res.data.msg
52-
});
57+
.catch(res => setMessageBox(res.data.msg, true));
5358
}
5459

55-
// inject ssa style
56-
let ssablock = document.getElementById('ssa')
57-
ssablock.addEventListener('load', () => {
58-
// wait until ssa is loaded
59-
let $head = $("iframe").contents().find("head");
60-
$head.append($("<link/>", { rel: "stylesheet", href: "/gossa/scrollbar.css", type: "text/css"}));
61-
})
62-
63-
// inject version info
64-
ping();
60+
function setMessageBox(msg, hide) {
61+
msgbox.innerText = msg
62+
if (hide) {
63+
ssabox.style.display = '';
64+
msgbox.style.display = 'none';
65+
return
66+
}
67+
ssabox.style.display = 'none';
68+
msgbox.style.display = '';
69+
}
6570

6671
// listen build action
6772
let buildssa = document.getElementById('build')
@@ -85,6 +90,7 @@ $('#aboutbtn').click(function() {
8590
aboutinfo.show();
8691
})
8792

93+
// textarea and tab key stroke
8894
$('#code').linedtextarea();
8995
$('#code').keydown(function(event){
9096
if (event.keyCode == 9) {

0 commit comments

Comments
 (0)