Open
Conversation
|
Does this actually work on github pages? |
Author
yeah, you can check on https://chriscoy.github.io/button/ |
|
LGTM ! |
Member
|
Instead of replaying events I think it would be better to save the snapshot of the "State" of the app somehow. (Also please rebase onto latest changes, we've got quite a few PRs merged) |
Author
Cool idea! What you think about something like this? class AppState {
#state = {
popupVisible: false,
clickCount: 0,
buttonText: "Click me!",
customCursorEnabled: false
};
constructor(){
try {
const savedState = localStorage.getItem(STORAGE_KEY);
if (savedState) {
this.#state = JSON.parse(savedState);
}
this.showPopup = this.#state.popupVisible;
this.clickCount = this.#state.clickCount;
this.buttonText = this.#state.buttonText;
this.customCursorEnabled = this.#state.customCursorEnabled;
} catch (error) {
console.error("Failed to load state from localStorage:", error);
}
}
#updateStorage() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.#state));
} catch (error) {
console.error("Failed to save state to localStorage:", error);
}
}
set showPopup(visible) {
this.#state.popupVisible = visible;
popupText.style.visibility = visible ? "visible" : "hidden";
this.#updateStorage();
}
set clickCount(count) {
this.#state.clickCount = count;
clickMeText.innerText = `Congrats! You clicked it ${count} times!`;
this.#updateStorage();
}
set buttonText(text) {
this.#state.buttonText = text;
clickMeText.innerText = text;
this.#updateStorage();
}
set customCursorEnabled(enabled) {
this.#state.customCursorEnabled = enabled;
if (enabled) {
clickMeWrapper.classList.add("customCursor");
clickMe.classList.add("customCursor");
} else {
clickMeWrapper.classList.remove("customCursor");
clickMe.classList.remove("customCursor");
}
this.#updateStorage();
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In order to implement this, I had to change the code a little bit. First, once the count was loaded from localStorage, the button kept shaking non-stop, so I had to create the initializeButton function. And to avoid changing the code structure too much, I created a global variable to control whether the audio can play.