Skip to content

Commit e14f726

Browse files
authored
Light styling and cleanup of vanilla js version (#31)
1 parent 7dcb087 commit e14f726

File tree

20 files changed

+231
-275
lines changed

20 files changed

+231
-275
lines changed

src/assets/icons/github.svg

Lines changed: 3 additions & 1 deletion
Loading

src/assets/icons/puzzle.svg

Lines changed: 3 additions & 2 deletions
Loading

src/assets/icons/stub.svg

Lines changed: 3 additions & 1 deletion
Loading

src/header.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import './style.css';
22
import icons from './icons';
3+
import { getBaseUrl } from './utils/utils';
34

45
export function getHeader(routes) {
5-
const header = document.createElement('header');
6-
const img = document.createElement('img');
7-
img.src = icons['puzzle.svg'];
8-
img.alt = 'puzzle';
9-
header.appendChild(img);
10-
header.appendChild(getNav(routes));
11-
return header;
6+
const header = document.createElement('header');
7+
8+
const link = document.createElement('a');
9+
link.href = getBaseUrl();
10+
11+
const img = document.createElement('img');
12+
img.src = icons['puzzle.svg'];
13+
img.alt = 'puzzle';
14+
img.classList.add('logo');
15+
16+
link.appendChild(img);
17+
header.appendChild(link);
18+
header.appendChild(getNav(routes));
19+
return header;
1220
}
1321

1422
function getNav(routes) {

src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const routes = {
4949
content: signup
5050
},
5151
signout: {
52-
linkLabel: 'Sign out',
5352
content: signout
5453
}
5554
};

src/pages/alerts.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getDefaultContainer } from '../utils/utils';
2+
13
const buttons = [
24
{
35
id: 'alert-trigger',
@@ -35,10 +37,8 @@ function showPrompt() {
3537
}
3638

3739
export default function alerts() {
38-
const container = document.createElement('div');
39-
const title = document.createElement('h1');
40-
title.textContent = 'Alerts';
41-
container.appendChild(title);
40+
const container = getDefaultContainer('Alerts');
41+
4242
for (const button of buttons) {
4343
const buttonElement = document.createElement('button');
4444
buttonElement.id = button.id;

src/pages/cookie.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#cookie-value {
22
font-size: 2rem;
3+
padding-top: 1vh;
34
}

src/pages/cookie.js

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getCookie, getValueFromCookie } from '../utils/utils';
1+
import { getCookie, getDefaultContainer, getValueFromCookie } from '../utils/utils';
22
import './cookie.css';
33

4-
let cookieValue;
54
const cookieName = 'gibberish';
5+
let cookieValue = getCookieValue();
66

77
function randomString() {
88
let text = '';
@@ -15,67 +15,39 @@ function randomString() {
1515
function setCookie(value, expirationDays) {
1616
let d = new Date();
1717
d.setTime(d.getTime() + expirationDays * 24 * 60 * 60 * 1000);
18-
let expires = 'expires=' + d.toUTCString();
19-
let v = cookieName + '=' + value + '; ' + expires;
18+
let v = `${cookieName}=${value};expires=${d.toUTCString()}`;
2019
console.log('Setting cookie ' + v);
2120
document.cookie = v;
2221

23-
cookieValue = getCookieValue();
22+
document.getElementById('cookie-value').textContent = getCookieValue();
2423
}
2524

2625
function getCookieValue() {
2726
const cookieValue = getValueFromCookie(getCookie(cookieName));
2827
return cookieValue ? cookieValue : '';
2928
}
3029

31-
function update(shouldDelete) {
32-
if (shouldDelete) {
33-
setCookie('', -1);
34-
} else {
35-
setCookie(randomString(), 5);
36-
}
37-
}
38-
39-
export default function alerts() {
40-
const container = document.createElement('div');
41-
42-
const title = document.createElement('h1');
43-
title.textContent = 'The gibberish talking cookie';
44-
container.appendChild(title);
45-
46-
const row = document.createElement('div');
47-
row.classList.add('row');
48-
container.appendChild(row);
49-
50-
const col = document.createElement('div');
51-
col.classList.add('col', 'text-center');
52-
row.appendChild(col);
53-
54-
const buttonGroupDiv = document.createElement('div');
55-
col.appendChild(buttonGroupDiv);
56-
57-
const buttonGroup = document.createElement('div');
58-
buttonGroup.classList.add('btn-group');
59-
buttonGroupDiv.appendChild(buttonGroup);
30+
export default function main() {
31+
const container = getDefaultContainer('The gibberish talking cookie');
6032

6133
const setButton = document.createElement('button');
62-
setButton.classList.add('btn', 'btn-success');
34+
setButton.classList.add('success');
6335
setButton.id = 'set-cookie';
64-
setButton.textContent = cookieValue ? 'Update' : 'Set' + ' the cookie';
65-
setButton.addEventListener('click', () => update(false));
66-
buttonGroup.appendChild(setButton);
36+
setButton.textContent = 'Set the cookie';
37+
setButton.addEventListener('click', () => setCookie(randomString(), 1));
38+
container.appendChild(setButton);
6739

6840
const deleteButton = document.createElement('button');
69-
deleteButton.classList.add('btn', 'btn-danger');
41+
deleteButton.classList.add('danger');
7042
deleteButton.id = 'delete-cookie';
7143
deleteButton.textContent = 'Remove the cookie';
72-
deleteButton.addEventListener('click', () => update(true));
73-
buttonGroup.appendChild(deleteButton);
44+
deleteButton.addEventListener('click', () => setCookie('', -1));
45+
container.appendChild(deleteButton);
7446

7547
const cookieValueDiv = document.createElement('div');
76-
col.appendChild(cookieValueDiv);
48+
container.appendChild(cookieValueDiv);
7749

78-
const cookieValueSpan = document.createElement('span');
50+
const cookieValueSpan = document.createElement('div');
7951
cookieValueSpan.id = 'cookie-value';
8052
cookieValueSpan.textContent = cookieValue ? cookieValue : '';
8153
cookieValueDiv.appendChild(cookieValueSpan);

src/pages/forms.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/pages/home.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ export default function home() {
88
const title = document.createElement('h1');
99
title.textContent = `Welcome to web-stubs, ${userWithActiveSession ? userWithActiveSession : 'guest'}!`;
1010

11-
if (userWithActiveSession) {
12-
const signOut = document.createElement('a');
13-
signOut.textContent = 'Sign out';
14-
signOut.href = '?page=signout';
15-
title.appendChild(signOut);
16-
}
11+
const action = document.createElement('a');
12+
action.classList.add('signInLink');
13+
action.textContent = userWithActiveSession ? 'Sign out' : 'Sign in';
14+
action.href = userWithActiveSession ? '?page=signout' : '?page=login';
15+
title.appendChild(action);
1716

1817
container.appendChild(title);
1918

0 commit comments

Comments
 (0)