Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
template-single-page-app/public/modules/home.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (35 sloc)
1.19 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getCookie, login, showMessage } from '../core.js' | |
export async function setup() { | |
try { | |
console.log('MAIN SCRIPT') | |
await login() | |
displayLists() | |
document.querySelector('h1').innerText = 'My Lists' | |
document.querySelector('main > button').addEventListener('click', event => { | |
console.log('adding a new note') | |
// await displayLists() | |
}) | |
} catch(err) { | |
showMessage(err.message) | |
window.location.href = '/#login' | |
} | |
} | |
async function displayLists() { | |
console.log('DISPLAY LISTS') | |
// const request= new Request('/lists') | |
// request.url = '/lists' | |
const options = { headers: { Authorization: getCookie('authorization') } } | |
const response = await fetch('/lists',options) | |
// const head = new Headers({authorization: getCookie('authorization')}) | |
// const options = { method: 'post', headers: head } | |
// request.headers = head | |
const json = await response.json() | |
// console.log(await response.json()) | |
const page = document.querySelector('main') | |
for(const list of json.data) { | |
console.log(list) | |
const section = document.createElement('article') | |
section.innerHTML = `<h2>${list.listname}</h2><p>${list.description}</p><button>Show list</button>` | |
page.appendChild(section) | |
} | |
} |