Skip to content

Commit

Permalink
fix select or error
Browse files Browse the repository at this point in the history
  • Loading branch information
fidoriel committed Oct 9, 2023
1 parent fc4986f commit 2f25c08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion evap/evaluation/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<script type="module">
import { NotebookLogic } from "{% static 'js/notebook.js' %}"

new NotebookLogic("notebook").attach();
new NotebookLogic("#notebook").attach();
</script>

{% block additional_javascript %}{% endblock %}
Expand Down
20 changes: 10 additions & 10 deletions evap/static/ts/src/notebook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { unwrap, assert, selectOrError } from "./utils.js";

const NOTEBOOK_LOCALSTORAGE_KEY = "evap_notebook_open";
const COLLAPSE_TOGGLE_BUTTON_ID = "notebookButton";
const WEBSITE_CONTENT_ID = "evapContent";
const NOTEBOOK_FORM_ID = "notebook-form";
const COLLAPSE_TOGGLE_BUTTON_SELECTOR = "#notebookButton";
const WEBSITE_CONTENT_SELECTOR = "#evapContent";
const NOTEBOOK_FORM_SELECTOR = "#notebook-form";

class NotebookFormLogic {
private readonly notebook: HTMLFormElement;
Expand Down Expand Up @@ -50,27 +50,27 @@ export class NotebookLogic {
private formLogic: NotebookFormLogic;
private readonly localStorageKey: string;

constructor(notebookId: string) {
this.notebookCard = unwrap(document.getElementById(notebookId));
this.formLogic = new NotebookFormLogic(NOTEBOOK_FORM_ID);
this.evapContent = unwrap(document.getElementById(WEBSITE_CONTENT_ID));
this.localStorageKey = NOTEBOOK_LOCALSTORAGE_KEY + "_" + this.notebookCard.dataset.notebookId;
constructor(notebookSelector: string) {
this.notebookCard = selectOrError(notebookSelector);
this.formLogic = new NotebookFormLogic(NOTEBOOK_FORM_SELECTOR);
this.evapContent = selectOrError(WEBSITE_CONTENT_SELECTOR);
this.localStorageKey = NOTEBOOK_LOCALSTORAGE_KEY + "_" + this.notebookCard.dataset.notebookSelector;
}

private onShowNotebook = (): void => {
this.notebookCard.classList.add("notebook-container");

localStorage.setItem(this.localStorageKey, "true");
this.evapContent.classList.add("notebook-margin");
unwrap(document.getElementById(COLLAPSE_TOGGLE_BUTTON_ID)).classList.replace("show", "hide");
selectOrError(COLLAPSE_TOGGLE_BUTTON_SELECTOR).classList.replace("show", "hide");
};

private onHideNotebook = (): void => {
this.notebookCard.classList.remove("notebook-container");

localStorage.setItem(this.localStorageKey, "false");
this.evapContent.classList.remove("notebook-margin");
unwrap(document.getElementById(COLLAPSE_TOGGLE_BUTTON_ID)).classList.replace("hide", "show");
selectOrError(COLLAPSE_TOGGLE_BUTTON_SELECTOR).classList.replace("hide", "show");
};

public attach = (): void => {
Expand Down

0 comments on commit 2f25c08

Please sign in to comment.