function APPROVAL() {
let enqueue
const generator = Generators.observe((enqueue_) => {
enqueue = enqueue_;
});
setTimeout(WORKER, 0);
let $tbody;
const $self = htl.html`
<h2>Actions awaiting approval</h2>
<table style="display: block; height: 12rem; overflow-y: scroll">
<thead>
<tr>
<th>Approve
<th>Deny
<th>ID
<th style="width: 80rem">Name
</tr>
</thead>
${$tbody = htl.html`<tbody>`}
</table>
`;
return Object.defineProperties($self, {
value: {
get: () => SUBMIT,
},
});
function SUBMIT(s) {
if (typeof s !== 'object') {
s = { name: s };
}
const { name } = s;
return new Promise((resolve, reject) => {
enqueue({ name, resolve, reject });
});
}
async function WORKER() {
const inProgress = [];
let nextId = 0;
for await (const { name, resolve, reject } of generator) {
const id = nextId++;
const $approve = htl.html.fragment`
<button onclick=${() => APPROVE(id)}>Approve
`/* htl.html.fragment */;
const $deny = htl.html.fragment`
<button onclick=${() => DENY(id)}>Deny
`/* htl.html.fragment */;
PUSH({ id, name, resolve, reject, $approve, $deny });
RENDER();
}
function PUSH(d) {
inProgress.push(d);
}
function POP(id) {
const index = inProgress.findIndex((d) => d.id === id);
if (index < 0) throw 'bad index';
const [d] = inProgress.splice(index, 1);
return d;
}
function APPROVE(id) {
const { resolve } = POP(id);
resolve();
RENDER();
}
function DENY(id) {
const { reject } = POP(id);
reject();
RENDER();
}
function RENDER() {
$tbody.replaceChildren(htl.html.fragment`
${inProgress.map(({ id, name, $approve, $deny }) => htl.html.fragment`
<tr>
<td>${$approve}
<td>${$deny}
<td>${id}
<td>${name}
`/* htl.html.fragment */)}
`/* htl.html.fragment */);
}
};
}