forked from Laboratoria/BOG001-social-network
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
68 lines (62 loc) · 1.77 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Este es el punto de entrada de tu aplicacion
import { signOut } from './lib/firebaseAuth.js';
import home from './views/home.js';
import login from './views/login.js';
import createAccount from './views/createAccount.js';
import recover from './views/recover.js';
import otherThank from './views/thankAccount.js';
import timeline from './views/timeline.js';
import profile from './views/profile.js';
import v404 from './views/404.js';
const body = document.getElementById('root');
const header = document.getElementById('header');
auth.onAuthStateChanged((user) => {
if (user) {
window.location.hash = '#timeline';
console.log('esta dentro');
} else {
console.log('debe entrar');
window.location.hash = '#home';
}
});
const router = (rute) => {
body.innerHTML = ' ';
switch (rute) {
case '#home':
return body.appendChild(home());
break;
case '#login':
return body.appendChild(login());
break;
case '#createAccount':
return body.appendChild(createAccount());
break;
case '#recover':
return body.appendChild(recover());
break;
case '#thankAccount':
return body.appendChild(otherThank());
break;
case '#timeline':
return body.appendChild(timeline());
break;
case '#profile':
return body.appendChild(profile());
break;
default:
window.location.hash = '#404';
return body.appendChild(v404());
}
};
window.addEventListener('hashchange', () => {
router(window.location.hash);
if (window.location.hash == '#timeline' || window.location.hash == '#profile') {
header.style.display = 'block';
} else {
header.style.display = 'none';
}
});
const logout = document.querySelector('#logout');
logout.addEventListener('click', () => {
signOut();
});