mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-30 02:38:47 -04:00
The new harvest cards and seed packets only appeared on plantings#show. Everywhere else either used the old thumbnails or hand-rolled its own markup, which is what made harvests and plantings look alike in the first place. - members#show and members/_harvests render harvests/card. The latter also wrapped each card in another .card, which nested a card in a card. - The homepage harvest list was hand-rolled markup beside a seeds section that already used seeds/card; both now use the shared partials. - Homepage seed packets go in an .index-cards grid. Outside one they have no width, and the packet's 3:4 ratio made each half the page wide. - harvests/_harvest and seeds/_seed chose between card and thumbnail on a `full:` local that nothing passes. Both render the card. The crop pages' harvest and seed panels are lists of links in a sidebar, not card grids, so they are left alone. Section "add" buttons now open the same dialogs as the actions menu, via a data-planting-dialog attribute the island listens for. Their href stays as the fallback without JavaScript. The rating card is now clickable: for someone who may edit the planting it renders StarRating, which saves the new rating and puts it back if the save fails. The card's own heading is the label, so the fieldset legend is hidden rather than saying "Rating" twice. "More photos" is a plain link again, and only shows when there are more photos than the page is displaying — the photos are now paginated to 12, where before the whole set was loaded and the link always showed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
34 lines
1.2 KiB
React
34 lines
1.2 KiB
React
// Entry point for the React "islands": small React components mounted into
|
|
// server-rendered pages. Rails renders an empty element with
|
|
// data-react-component="Name" and data-props='{...}' (see the react_component
|
|
// helper); this finds each one and mounts the matching component.
|
|
//
|
|
// To add a component: create it in ./components and register it below.
|
|
import React from 'react';
|
|
import {createRoot} from 'react-dom/client';
|
|
|
|
import GardenCards from './components/GardenCards';
|
|
import PlantingActions from './components/PlantingActions';
|
|
import PlantingRating from './components/PlantingRating';
|
|
|
|
const components = {GardenCards, PlantingActions, PlantingRating};
|
|
|
|
function mountIslands() {
|
|
document.querySelectorAll('[data-react-component]').forEach((element) => {
|
|
const name = element.dataset.reactComponent;
|
|
const Component = components[name];
|
|
if (!Component) {
|
|
console.error(`No React component registered as "${name}"`);
|
|
return;
|
|
}
|
|
const props = JSON.parse(element.dataset.props || '{}');
|
|
createRoot(element).render(<Component {...props} />);
|
|
});
|
|
}
|
|
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', mountIslands);
|
|
} else {
|
|
mountIslands();
|
|
}
|