Skip to content

Commit

Permalink
Fix preview actions
Browse files Browse the repository at this point in the history
  • Loading branch information
bas080 committed Jun 27, 2024
1 parent f0a3a4a commit 3025d46
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
66 changes: 34 additions & 32 deletions lit-component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const emitAction =
event.target.dispatchEvent(customEvent);
};

const onAction = (actions) =>
export const onAction = (actions) =>
function (event) {
this.querySelectorAll("details").forEach((details) => {
details.open = false;
Expand Down Expand Up @@ -215,39 +215,41 @@ const toplist = {

items: (vm) => vm.items.map(toplist.item(vm)),

list: (vm) => (list, listIndex) => {
vm = {
...vm,
...list,
isTopList: listIndex === 0,
listIndex,
};
list:
(vm) =>
(list, listIndex = 0) => {
vm = {
...vm,
...list,
isTopList: vm.isTopList ?? listIndex === 0,
listIndex,
};

return html`<article class="list">
${when(
vm.isTopList,
() =>
html` <h1 id="toplist">${tr("appTitle")}</h1>
<form @submit="${emitAction("addItem", vm)}">
<label>${tr("newItem")}</label>
<input required id="addItemInput" />
<input type="submit" value="${tr("addItem")}" />
</form>`,
)}
<ul>
${toplist.items(vm)}
</ul>
<details>
<summary>${tr("listActions")}</summary>
return html`<article class="list">
${when(
vm.isTopList,
() =>
html` <h1 id="toplist">${tr("appTitle")}</h1>
<form @submit="${emitAction("addItem", vm)}">
<label>${tr("newItem")}</label>
<input required id="addItemInput" />
<input type="submit" value="${tr("addItem")}" />
</form>`,
)}
${when(vm.isTopList, () => toplist.action(vm, "newList", svg.plus))}
${when(!vm.isTopList, () => toplist.action(vm, "raise", svg.up))}
${toplist.action(vm, "shareList", svg.share)}
${toplist.action(vm, "qrShareList", svg.qr)}
</details>
</article> `;
},
<ul>
${toplist.items(vm)}
</ul>
<details>
<summary>${tr("listActions")}</summary>
${when(vm.isTopList, () => toplist.action(vm, "newList", svg.plus))}
${when(!vm.isTopList, () => toplist.action(vm, "raise", svg.up))}
${toplist.action(vm, "shareList", svg.share)}
${toplist.action(vm, "qrShareList", svg.qr)}
</details>
</article> `;
},

lists: (vm) => vm.lists.map(toplist.list(vm)),
};
Expand Down
6 changes: 4 additions & 2 deletions toplist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
tryReject,
moveItemToTop,
} from "./util.mjs";
import { toplist } from "./lit-component.mjs";
import { toplist, onAction } from "./lit-component.mjs";

const openQRCode = (items) => {
const url = shareUrl(items);
Expand Down Expand Up @@ -257,7 +257,9 @@ tryReject(async function () {

if (items) {
render(
list(false)({ created: new Date().toISOString(), items }, 0),
html`<div @action="${onAction(actions)}">
${toplist.list({ isTopList: false })({ items })}
</div>`,
window.preview,
);

Expand Down

0 comments on commit 3025d46

Please sign in to comment.