This document provides an overview of the React component architecture in the Gregory MS website.
The Gregory MS website uses React for interactive components that display data from the Gregory MS API. The React components are organized in a modular, maintainable structure.
The website uses Umami Analytics for privacy-focused analytics. All interactive elements include data-umami-event attributes for comprehensive user behavior tracking.
Events follow a semantic naming pattern: click--{area}-{action}
Examples:
click--sources-filter-all- User clicks "All Sources" filterclick--pagination-next- User clicks next pageclick--download-csv- User downloads CSV dataclick--search-articles- User searches for articles
- Top navigation menu clicks:
click--topnav-{menu-item} - Footer navigation clicks:
click--footer-nav-{menu-item} - Mobile menu toggle:
click--mobile-menu-toggle
- Search tab switches:
click--search-tab-{articles|trials|authors} - Search submissions:
click--search-{articles|trials|authors} - Search result interactions
- External source links:
click--source-external-link - Trial external links:
click--trial-external-link - Author ORCID links:
click--author-orcid - Category card selections:
click--category-card
- Filter changes:
click--sources-filter-{type} - Pagination:
click--pagination-{previous|next|page} - Downloads:
click--download-csv
- Newsletter subscriptions:
click--subscribe-newsletter - Donation button:
click--donate-button
Many events include additional context using data-umami-event-* attributes:
data-umami-event-source- Source name for external linksdata-umami-event-page- Page number for paginationdata-umami-event-term- Search termsdata-umami-event-filename- Downloaded file name
assets/js/
├── apps/ # App entry points for different pages
│ ├── articles.jsx # Articles app entry point
│ ├── authorProfile.jsx # Author profile app entry point
│ ├── category.jsx # Category app entry point
│ ├── observatory.jsx # Observatory app entry point
│ ├── relevant.jsx # Relevant articles app entry point
│ ├── sources.jsx # Sources app entry point
│ └── trials.jsx # Trials app entry point
├── components/ # Reusable React components
│ ├── ArticleList.jsx # Displays a list of articles
│ ├── ArticleSnippet.jsx # Displays a preview of an article
│ ├── AuthorProfile.jsx # Displays author information
│ ├── CategoryCard.jsx # Displays a category card
│ ├── CategoryDetail.jsx # Displays detailed category information
│ ├── DownloadButton.jsx # Button to download data as CSV
│ ├── Observatory.jsx # Main observatory component
│ ├── Pagination.jsx # Pagination component
│ ├── SingleArticle.jsx # Displays a single article
│ ├── Source.jsx # Displays a single source
│ ├── SourceList.jsx # Displays a list of sources
│ ├── Trial.jsx # Displays a single trial
│ └── TrialsList.jsx # Displays a list of trials
├── contexts/ # React context providers
├── hooks/ # Custom React hooks
│ └── useApi.js # Hooks for API data fetching
├── services/ # Service modules
│ └── api.js # API service for data fetching
└── utils.js # Utility functions
The React components are built using esbuild. The build process is configured in jsx-build.js.
To start development with hot-reloading of React components:
npm run dev:watchThis will start the esbuild watcher and Hugo server together.
To build for production:
npm run buildThis will build the React components and then build the Hugo site.
- Create the component in the
assets/js/components/directory - Import and use the component in the appropriate app entry point
- Run the build process to generate the JavaScript files
- Create a new app entry point in
assets/js/apps/ - Update the
jsx-build.jsfile to include the new entry point - Update the
react-app.htmlpartial to include the new app - Create or update the Hugo layout to use the new app
- Use the custom hooks in
hooks/useApi.jsfor data fetching - Use the API service in
services/api.jsfor all API calls - Keep components small and focused on a single responsibility
- Use PropTypes for component props validation
- Follow the established patterns for error handling and loading states
- React 18.x
- React Router 6.x
- Axios for API requests
- Recharts for data visualization
If components are not loading correctly:
- Check the browser console for errors
- Verify that the root element exists in the HTML
- Check that the correct app is being loaded for the page
- Verify that the API endpoints are correct
- Check that the Hugo layout includes the correct React app
The Sources app (/sources/) displays information about the data sources Gregory MS uses to collect Multiple Sclerosis research and clinical trials.
- SourceList: Main component that displays a list of sources with filtering capabilities
- Source: Individual source card component
- Filter by Type: Users can filter sources by type (all, science papers, clinical trials)
- Responsive Design: Optimized for mobile and desktop viewing
- External Links: Sources with URLs link to their respective websites
- Detailed Information: Shows source names, descriptions, and purposes
The Sources app uses the useSources hook to fetch data from the /sources/ endpoint. The API returns:
{
"count": 19,
"next": "...",
"previous": null,
"results": [
{
"source_id": 1,
"source_for": "science paper",
"name": "APTA",
"description": null,
"link": "https://...",
"subject_id": 1,
"team_id": 1
}
]
}The Sources app is activated by the {{< sources >}} shortcode in Hugo templates.