Compare commits

..

2 commits

Author SHA1 Message Date
27774d908f Better error handling for item page preview HTTP error
If something goes wrong, like the site goes down or has an intermittent
error, try a full pageload. That way, we're both retrying, and in a way
that gives the user more control and visibility into what's going on,
and what they can potentially do about it. (e.g. if there's a useful
error message, they will see it!)
2024-09-08 13:36:30 -07:00
09572b5c05 Improve noscript species face picker styles
Fix z-index conflicts, and not always covering the whole option set
2024-09-08 13:29:34 -07:00
2 changed files with 23 additions and 11 deletions

View file

@ -4,9 +4,11 @@ document.addEventListener("change", (e) => {
try { try {
const mainPickerForm = document.querySelector( const mainPickerForm = document.querySelector(
"#item-preview species-color-picker form"); "#item-preview species-color-picker form",
const mainSpeciesField = );
mainPickerForm.querySelector("[name='preview[species_id]']"); const mainSpeciesField = mainPickerForm.querySelector(
"[name='preview[species_id]']",
);
mainSpeciesField.value = e.target.value; mainSpeciesField.value = e.target.value;
mainPickerForm.requestSubmit(); // `submit` doesn't get captured by Turbo! mainPickerForm.requestSubmit(); // `submit` doesn't get captured by Turbo!
} catch (error) { } catch (error) {
@ -14,6 +16,14 @@ document.addEventListener("change", (e) => {
} }
}); });
// If the preview frame fails to load, try a full pageload.
document.addEventListener("turbo:frame-missing", (e) => {
if (!e.target.matches("#item-preview")) return;
e.detail.visit(e.detail.response.url);
e.preventDefault();
});
class SpeciesColorPicker extends HTMLElement { class SpeciesColorPicker extends HTMLElement {
#internals; #internals;
@ -44,7 +54,7 @@ class SpeciesFacePicker extends HTMLElement {
#handleClick(e) { #handleClick(e) {
if (e.target.matches("input[type=radio]")) { if (e.target.matches("input[type=radio]")) {
this.dispatchEvent(new Event("change", {bubbles: true})); this.dispatchEvent(new Event("change", { bubbles: true }));
} }
} }
} }

View file

@ -207,15 +207,16 @@ body.items-show
species-face-picker species-face-picker
display: block display: block
position: relative position: relative
max-height: 200px // 4 rows of 50px images, and padding will offer a hint of below top: -10px
padding: 10px // leave enough room for the zoomed-in selected face
margin-top: -10px
overflow: auto
species-face-picker-options species-face-picker-options
display: flex display: flex
justify-content: center justify-content: center
flex-wrap: wrap flex-wrap: wrap
isolation: isolate // avoid z-index conflicts between pets and noscript
overflow: auto
max-height: 200px // 4 rows of 50px images, and padding will offer a hint of below
padding: 10px // leave enough room for the zoomed-in selected face
img img
width: 50px width: 50px
@ -271,7 +272,8 @@ body.items-show
noscript noscript
position: absolute position: absolute
inset: 0 inset: 0
background: rgba(white, .75) padding: 1em
background: rgba(white, .8)
z-index: 1 z-index: 1
cursor: auto cursor: auto
@ -366,8 +368,8 @@ body.items-show
species-face-picker species-face-picker
grid-area: faces grid-area: faces
max-height: 350px species-face-picker-options
margin: -10px max-height: 340px
.item-preview-meta-info .item-preview-meta-info
grid-area: meta grid-area: meta