Skip to content

Commit

Permalink
Check for group existence on landing page.
Browse files Browse the repository at this point in the history
  • Loading branch information
jech committed Aug 31, 2022
1 parent a21134d commit cdbaef4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ <h1 id="title" class="navbar-brand">Galène</h1>
<input id="group" type="text" name="group" class="form-control form-control-inline"/>
<input type="submit" value="Join" class="btn btn-default btn-large"/><br/>
</form>

<p id="errormessage"></p>

<div id="public-groups" class="groups">
<h2>Public groups</h2>
Expand Down
6 changes: 6 additions & 0 deletions static/mainpage.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ body {
flex-direction: column;
}

#errormessage {
color: red;
font-weight: bold;
height: 12px;
}

.groups {
}

Expand Down
43 changes: 40 additions & 3 deletions static/mainpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,50 @@

'use strict';

document.getElementById('groupform').onsubmit = function(e) {
document.getElementById('groupform').onsubmit = async function(e) {
e.preventDefault();
clearError();
let group = document.getElementById('group').value.trim();
if(group !== '')
location.href = '/group/' + group + '/';
if(group === '')
return;
let url = '/group/' + group + '/';
try {
let resp = await fetch(url, {
method: 'HEAD',
});
if(!resp.ok) {
if(resp.status === 404)
displayError('No such group');
else
displayError(`The server said: ${resp.status} ${resp.statusText}`);
return;
}
} catch(e) {
displayError(`Coudln't connect: ${e.toString()}`);
}
location.href = url;
};

var clearErrorTimeout = null;

function displayError(message) {
clearError();
let p = document.getElementById('errormessage');
p.textContent = message;
clearErrorTimeout = setTimeout(() => {
let p = document.getElementById('errormessage');
p.textContent = '';
clearErrorTimeout = null;
}, 2500);
}

function clearError() {
if(clearErrorTimeout != null) {
clearTimeout(clearErrorTimeout);
clearErrorTimeout = null;
}
}

async function listPublicGroups() {
let div = document.getElementById('public-groups');
let table = document.getElementById('public-groups-table');
Expand Down

0 comments on commit cdbaef4

Please sign in to comment.