Documentation

Tutorials: Showing all my Stations

The Component

Now that we have 2 ways to work with the data (via the query or the component), we can attach this to as many components as we want. 

Stations

The stations component uses the withCollectedStations provider as a data source and has 5 different UI states:



import React from 'react';
import PropTypes from 'prop-types';

import styles from './styles.module.scss';

import { withCollectedStations } from '../../graphql/catalog/collectedStations';
import ImageWithMeta from '../ImageWithMeta';

export const Stations = (props) => {
 const noItemsMessage = "Use search to find stations. Click on one of the results to start the station.";
 const {
   isLoading,
   error,
   stations,
   hideOnNoData,
 } = props;


 if (isLoading) {
   return (
     
Loading...
); } if (error) { return (
Error loading stations.
); } const stationList = stations && stations.map(({ meta }) => { const { id, art, name, } = meta; if (!id || !name) return null; return (
  • ); }); if (hideOnNoData && (!stationList || stationList.length === 0)) { return null; } return (
    Stations
    { (stationList && stationList.length !== 0) ?
      {stationList}
    :
    {noItemsMessage}
    }
    ); }; Stations.propTypes = { isLoading: PropTypes.bool, hideOnNoData: PropTypes.bool, error: PropTypes.string, stations: PropTypes.array, }; Stations.defaultProps = { isLoading: false, hideOnNoData: false, }; export default withCollectedStations(Stations);

    Bringing all of the above together, you will have a component using the collection query to display the stations of a listener. This is what the above example will look like:

    [screen]