Skip to content

Commit

Permalink
Add a way to clear an individual scramble through an "Additional acti…
Browse files Browse the repository at this point in the history
…ons…" modal.
  • Loading branch information
lgarron committed Mar 28, 2024
1 parent b553f01 commit 6fa8c1b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cubing/scramble-table",
"version": "0.2.1",
"version": "0.2.2",
"type": "module",
"publishConfig": {
"access": "public"
Expand Down
25 changes: 25 additions & 0 deletions src/lib/elements/CompetitorScrambleDisplay.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,28 @@ competitor-scramble-display:not(.show-multi) .multi {
competitor-scramble-display.show-multi-grid>twisty-player {
display: none;
}


scramble-table .additional-actions {
border: 1px solid var(--scramble-table-border-color);
padding: 2em;
line-height: 1.5em;
color: var(--scramble-table-main-color);
backdrop-filter: blur(0.25em);
background: color-mix(in oklab, var(--scramble-table-background) 90%, transparent);
}

scramble-table .additional-actions h1 {
margin-top: 0;
}

scramble-table .additional-actions .close {
float: right;
position: relative
}

scramble-table dialog::backdrop {
background-color: #444;
opacity: 0.75;
z-index: 1;
}
17 changes: 14 additions & 3 deletions src/lib/elements/CompetitorScrambleDisplay.template.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template>
<div class="info">
<div class="split scrambler"><span class="scrambler-name">Scrambler</span><button class="set-scrambler"
data-original-text="Set scrambler">Set
scrambler</button></div>
<div class="split scrambler"><span class="scrambler-name">Scrambler</span><span><button class="set-scrambler"
data-original-text="Set scrambler">Set
scrambler</button>&nbsp;<button class="additional-actions-button"
title="Additional actions…"></button></span></div>
<div class="competitor"></div>
<div class="split">
<div class="event"></div>
Expand All @@ -23,4 +24,14 @@
<button class="next">Next ➡️</button>
<button class="all">Show All</button>
</div>
<dialog class="additional-actions">
<button class="close">Close</button>
<br>
<br>
<h1>Additional&nbsp;actions</h1>
<h2>Scrambler: <span class="scrambler-name">Scrambler</span></h2>
<hr>
<br>
<span><button class="clear-scramble">Clear scramble</button></span>
</dialog>
</template>
46 changes: 45 additions & 1 deletion src/lib/elements/CompetitorScrambleDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import templateHTML from "./CompetitorScrambleDisplay.template.html";
import type { SharedState } from "./SharedState";
import { addCSS, parseHTML } from "./html";

import { Alg } from "cubing/alg";
import "./MultiBlindGridDisplay";

const template = parseHTML<HTMLTemplateElement>(templateHTML);
Expand Down Expand Up @@ -40,12 +41,53 @@ export class CompetitorScrambleDisplay extends HTMLElement {
"click",
() => this.#toggleShowAllSubScrambles(),
);
this.querySelector(".clear-scramble")!.addEventListener("click", () =>
this.#clearScramble(),
);
this.querySelector("multi-blind-grid-display")!.addEventListener(
"scramble-clicked",
(e: CustomEvent<{ idx: number }>) => {
this.#currentSubScrambleSetIndex(e.detail.idx);
},
);
this.#initializeAdditionalActions();
}

// TODO: unify dialog code with main settings
#initializeAdditionalActions() {
this.querySelector(".additional-actions-button").addEventListener(
"click",
() => {
this.#showAdditionalActions();
},
);

this.querySelector(".additional-actions button.close").addEventListener(
"click",
() => {
this.#hideAdditionalActions();
},
);
}

#showAdditionalActions() {
this.querySelector<HTMLDialogElement>(".additional-actions").showModal();
}

#hideAdditionalActions() {
this.querySelector<HTMLDialogElement>(".additional-actions").close();
}

#clearScramble() {
this.classList.remove("scramble-signed");
this.#toggleShowAllSubScrambles(false);
this.#setField("competitor", "");
this.#setField("event", "");
this.#setField("round", "");
this.#setField("scramble-set", "");
this.#setField("attempt", "");
this.querySelector("twisty-player").alg = new Alg();
this.#hideAdditionalActions();
}

#info: AttemptScrambleInfo | undefined;
Expand Down Expand Up @@ -141,7 +183,9 @@ export class CompetitorScrambleDisplay extends HTMLElement {
}

#setField(field: string, text: string): void {
this.getElementsByClassName(field)[0].textContent = text;
for (const elem of this.getElementsByClassName(field)) {
elem.textContent = text;
}
}

async #onSetScrambler() {
Expand Down
9 changes: 6 additions & 3 deletions src/lib/elements/ScrambleTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ export class ScrambleTable
}

#initializeSettings() {
this.querySelector("header button").addEventListener("click", () => {
this.#showSettings();
});
this.querySelector("header .settings-button").addEventListener(
"click",
() => {
this.#showSettings();
},
);

this.querySelector(
".scramble-table-settings button.close",
Expand Down

0 comments on commit 6fa8c1b

Please sign in to comment.