generated from corysanin/nodejs-web-template
basic page content
This commit is contained in:
@@ -1 +1,43 @@
|
||||
import type { GrocyChore } from '../distribution/Grocy';
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async function () {
|
||||
async function loadChores() {
|
||||
try {
|
||||
const response = await fetch('/api/chores');
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
if (!('chores' in result)) {
|
||||
throw new Error(JSON.stringify(result));
|
||||
}
|
||||
createChores(result.chores as GrocyChore[]);
|
||||
} catch (error: any) {
|
||||
console.error(error?.message);
|
||||
}
|
||||
}
|
||||
|
||||
function createChores(chores: GrocyChore[]) {
|
||||
const root = document.getElementById('approot');
|
||||
if (!root) {
|
||||
throw new Error('app root not found');
|
||||
}
|
||||
chores.forEach(ch => {
|
||||
const btn = document.createElement('div');
|
||||
const leftText = document.createElement('span');
|
||||
leftText.appendChild(document.createTextNode(ch.chore_name));
|
||||
btn.appendChild(leftText);
|
||||
btn.classList.add('chore');
|
||||
if (ch.next_execution_assigned_user?.display_name) {
|
||||
const rightText = document.createElement('span');
|
||||
rightText.appendChild(document.createTextNode(ch.next_execution_assigned_user.display_name));
|
||||
rightText.classList.add('right');
|
||||
btn.appendChild(rightText);
|
||||
}
|
||||
root.appendChild(btn);
|
||||
});
|
||||
}
|
||||
|
||||
loadChores();
|
||||
});
|
19
styles/01-layout.scss
Normal file
19
styles/01-layout.scss
Normal file
@@ -0,0 +1,19 @@
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.right {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 80%;
|
||||
width: calc(100% - 150px);
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.chore {
|
||||
line-height: 1.2em;
|
||||
padding: .75em;
|
||||
margin: 1em 0;
|
||||
}
|
8
styles/02-colors.scss
Normal file
8
styles/02-colors.scss
Normal file
@@ -0,0 +1,8 @@
|
||||
body {
|
||||
background-color: #212121;
|
||||
}
|
||||
|
||||
.chore {
|
||||
color: #FAFAFA;
|
||||
background-color: #4527A0;
|
||||
}
|
@@ -7,7 +7,9 @@
|
||||
|
||||
<body class="preload">
|
||||
<div class="content">
|
||||
<h1>Hello World</h1>
|
||||
<div id="approot">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script nonce="<%= cspNonce %>" src="/assets/js/content.js" defer></script>
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user