-
-
Notifications
You must be signed in to change notification settings - Fork 16
fix: show more and show less not saving state on page refresh #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ac9041
refactor: simplify logging messages in job transitions
GiovaniGuizzo 4aa2b3f
feat: enhance logging for job transitions with job IDs
GiovaniGuizzo 876a8b9
feat: improve detail toggling by using unique IDs for constructor, ru…
GiovaniGuizzo e7a05fe
feat: implement scroll position restoration for HTMX swaps
GiovaniGuizzo 1c87eeb
fix: correct scroll position restoration method for HTMX swaps
GiovaniGuizzo 77930b6
feat: enhance URL management for HTMX requests and improve button beh…
GiovaniGuizzo 49d1391
fix: refine toggleDetails logic for better state handling in job details
GiovaniGuizzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,36 @@ | ||
| // Global variable to store details state | ||
| let globalDetailsStates = {}; | ||
|
|
||
| function applySeeMore() { | ||
| document.querySelectorAll(".sq-code").forEach((container) => { | ||
| const content = container.querySelector(".code-content"); | ||
| const btn = container.querySelector(".toggle-btn"); | ||
|
|
||
| const maxHeight = 240; | ||
| let expanded = false; | ||
|
|
||
| if (content.scrollHeight <= maxHeight) { | ||
| btn.classList.add("hidden"); | ||
| } | ||
|
|
||
| btn.addEventListener("click", () => { | ||
| expanded = !expanded; | ||
|
|
||
| function toggleDetails(expanded) { | ||
| if (expanded) { | ||
| content.classList.remove("max-h-[15rem]", "overflow-hidden"); | ||
| btn.textContent = "See less"; | ||
| globalDetailsStates[container.id] = true; // Save state as expanded | ||
| } else { | ||
| content.classList.add("max-h-[15rem]", "overflow-hidden"); | ||
| btn.textContent = "See more"; | ||
| globalDetailsStates[container.id] = false; // Save state as not expanded | ||
| } | ||
| } | ||
|
|
||
| toggleDetails(globalDetailsStates[container.id] ?? false); | ||
|
|
||
| btn.addEventListener("click", () => { | ||
| toggleDetails(!globalDetailsStates[container.id] ?? true); | ||
GiovaniGuizzo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| }); | ||
| } | ||
|
|
||
| document.addEventListener("DOMContentLoaded", applySeeMore); | ||
| document.addEventListener("htmx:afterSwap", applySeeMore); | ||
|
|
||
| document.addEventListener("htmx:beforeSwap", (evt) => { | ||
| const detailsStates = Array.from(document.querySelectorAll("#job-details details")).map((d) => d.open); | ||
|
|
||
| evt.detail.target.dataset.detailsStates = JSON.stringify(detailsStates); | ||
| }); | ||
|
|
||
| document.addEventListener("htmx:afterSwap", (evt) => { | ||
| const detailsStates = JSON.parse(evt.detail.target.dataset.detailsStates || "[]"); | ||
|
|
||
| const details = evt.target.querySelectorAll("details"); | ||
| detailsStates.forEach((isOpen, idx) => { | ||
| if (isOpen) details[idx].open = true; | ||
| }); | ||
| }); | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| let savedScrollY = 0; | ||
|
|
||
| // Save and restore scroll position around HTMX swaps | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| document.addEventListener("htmx:beforeSwap", () => { | ||
| savedScrollY = document.getElementById("main-section").scrollTop; | ||
| }); | ||
|
|
||
| document.addEventListener("htmx:afterSwap", () => { | ||
| document.getElementById("main-section").scrollTo({ top: savedScrollY }); | ||
| }); | ||
| }); |
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.