Skip to content

Commit 72ae162

Browse files
authored
Lookslike windows closing (#81)
* allow for duplicate opens and close them one by one
1 parent 7a8cc76 commit 72ae162

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

typescript/packages/lookslike-high-level/src/components/window-manager.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,20 @@ export class CommonWindowManager extends LitElement {
5656
@property({ type: Array })
5757
sagas: Gem[] = [];
5858

59-
private renderedSagas: { [key: string]: HTMLElement } = {};
60-
6159
override render() {
60+
const idCounts: { [key: string]: number } = {};
6261
return html`
6362
${this.sagas.map((saga) => {
64-
if (!this.renderedSagas[saga[ID]])
65-
this.renderedSagas[saga[ID]] = render.render(
66-
include({ content: binding("UI") }),
67-
{
68-
UI: saga.UI,
69-
}
70-
) as HTMLElement;
63+
idCounts[saga[ID]] ??= 0;
64+
const id = saga[ID] + "#" + idCounts[saga[ID]]++;
7165
7266
return html`
73-
<div class="window" id="${saga[ID]}">
67+
<div class="window" id="${id}">
7468
<button class="close-button" @click="${this.onClose}">×</button>
7569
<common-screen-element>
76-
${this.renderedSagas[saga[ID]]}
70+
${render.render(include({ content: binding("UI") }), {
71+
UI: saga.UI,
72+
})}
7773
</common-screen-element>
7874
</div>
7975
`;
@@ -98,7 +94,13 @@ export class CommonWindowManager extends LitElement {
9894
onClose(e: Event) {
9995
const id = (e.currentTarget as HTMLElement).parentElement?.id;
10096
if (id) {
101-
this.sagas = this.sagas.filter((saga) => saga[ID] + "" !== id);
97+
const idCounts: { [key: string]: number } = {};
98+
99+
this.sagas = this.sagas.filter((saga) => {
100+
idCounts[saga[ID]] ??= 0;
101+
const sagaID = saga[ID] + "#" + idCounts[saga[ID]]++;
102+
return sagaID !== id;
103+
});
102104
}
103105
}
104106

0 commit comments

Comments
 (0)