Files
growstuff/app/javascript/react_islands.jsx
T
Brenda Wallace 54258de6c4 Refactor home dashboard and related components
- Removed unused styles and helper methods from _garden_layout.scss, _homepage.scss, and overrides.scss.
- Updated _home_dashboard.scss to enhance button styles and added new harvest picker styles.
- Introduced HarvestPicker component for improved harvest recording functionality.
- Refactored home dashboard views to utilize new home_section helper for consistent layout.
- Simplified and optimized existing methods in application_helper.rb, activity.rb, and harvest.rb.
- Removed deprecated homepage_records methods from Activity and Harvest models.
- Updated tests to reflect changes in helper methods and removed obsolete tests.
2026-10-12 19:24:55 +13:00

39 lines
1.5 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 GardenLayout from './components/GardenLayout';
import HarvestPicker from './components/HarvestPicker';
import LocationPicker from './components/LocationPicker';
import PhotoDialog from './components/PhotoDialog';
import PlantPicker from './components/PlantPicker';
import PlantingActions from './components/PlantingActions';
import PlantingRating from './components/PlantingRating';
const components = {GardenCards, GardenLayout, HarvestPicker, LocationPicker, PhotoDialog, PlantPicker, 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();
}