Skip to content

Commit cdbaef4

Browse files
committed
Check for group existence on landing page.
1 parent a21134d commit cdbaef4

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

static/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ <h1 id="title" class="navbar-brand">Galène</h1>
2020
<input id="group" type="text" name="group" class="form-control form-control-inline"/>
2121
<input type="submit" value="Join" class="btn btn-default btn-large"/><br/>
2222
</form>
23+
24+
<p id="errormessage"></p>
2325

2426
<div id="public-groups" class="groups">
2527
<h2>Public groups</h2>

static/mainpage.css

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ body {
44
flex-direction: column;
55
}
66

7+
#errormessage {
8+
color: red;
9+
font-weight: bold;
10+
height: 12px;
11+
}
12+
713
.groups {
814
}
915

static/mainpage.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,50 @@
2020

2121
'use strict';
2222

23-
document.getElementById('groupform').onsubmit = function(e) {
23+
document.getElementById('groupform').onsubmit = async function(e) {
2424
e.preventDefault();
25+
clearError();
2526
let group = document.getElementById('group').value.trim();
26-
if(group !== '')
27-
location.href = '/group/' + group + '/';
27+
if(group === '')
28+
return;
29+
let url = '/group/' + group + '/';
30+
try {
31+
let resp = await fetch(url, {
32+
method: 'HEAD',
33+
});
34+
if(!resp.ok) {
35+
if(resp.status === 404)
36+
displayError('No such group');
37+
else
38+
displayError(`The server said: ${resp.status} ${resp.statusText}`);
39+
return;
40+
}
41+
} catch(e) {
42+
displayError(`Coudln't connect: ${e.toString()}`);
43+
}
44+
location.href = url;
2845
};
2946

47+
var clearErrorTimeout = null;
48+
49+
function displayError(message) {
50+
clearError();
51+
let p = document.getElementById('errormessage');
52+
p.textContent = message;
53+
clearErrorTimeout = setTimeout(() => {
54+
let p = document.getElementById('errormessage');
55+
p.textContent = '';
56+
clearErrorTimeout = null;
57+
}, 2500);
58+
}
59+
60+
function clearError() {
61+
if(clearErrorTimeout != null) {
62+
clearTimeout(clearErrorTimeout);
63+
clearErrorTimeout = null;
64+
}
65+
}
66+
3067
async function listPublicGroups() {
3168
let div = document.getElementById('public-groups');
3269
let table = document.getElementById('public-groups-table');

0 commit comments

Comments
 (0)