-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
51 lines (40 loc) · 1.32 KB
/
app.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
// importing other stuff, utility functions for:
// working with supabase:
import { checkAuth, signOutUser, getUser, getProjects } from './fetch-utils.js';
import { renderProject } from './render-utils.js';
// pure rendering (data --> DOM):
/* "boiler plate" auth code */
// checking if we have a user! (will redirect to auth if not):
// checkAuth();
// can optionally return the user:
// const user = checkAuth();
// sign out link:
const signOutLink = document.getElementById('sign-out-link');
signOutLink.addEventListener('click', async () => {
await signOutUser();
});
/* end "boiler plate auth code" */
// grab needed DOM elements on page:
const projectsListEl = document.getElementById('projects-container');
// display all projects on home page
async function displayProjects() {
projectsListEl.textContent = '';
const projects = await getProjects();
for (let project of projects) {
const projectEl = renderProject(project);
projectsListEl.append(projectEl);
}
}
displayProjects();
window.addEventListener('click', () => {
checkAuth();
});
window.addEventListener('load', () => {
const signOut = document.getElementById('sign-out-link');
const user = getUser();
if (user) {
signOut.textContent = 'Sign-Out';
} else {
signOut.textContent = 'Sign-In';
}
});