<commit_before>import {dateFormatted} from '../../../utils/ItineraryUtils';
import {add, remove} from '../../../actions/ItineraryActions';

//TODO: Duplicate of Itinerary <Walk/>
//TODO: Issue with Favourite being removed on first attempt (works fine for Itinerary)

/**
 * Build a style object for the header
 * @return object A style object for React
 */
function headerBG(city, walk) {
  // Load the BG
  const thumb = (walk.thumbnails[0] && walk.thumbnails[0].url) || city.background;
  let bg;
  if (thumb) {
    bg = 'url(' + thumb + ')';
  } else {
    bg = '#eaeaea';
  }

  return {
    backgroundImage: bg,
    backgroundSize: 'cover',
    backgroundPosition: '50%'
  };
}

const WalkHeader = ({city, walk, favourites, itinerary}) => {
  let favButton, addButton;
  if (favourites) {
    if (favourites.walks.has(walk)) {
      favButton = <button className="removeFavourite" onClick={() => remove(favourites, walk)} />;
    } else {
      favButton = <button className="addFavourite" onClick={() => add(favourites, walk)} />;
    }
  }

  if (itinerary) {
    if (itinerary.walks.has(walk)) {
      addButton = <button className="removeItinerary" onClick={() => remove(itinerary, walk)} />;
    } else {
      addButton = <button className="addItinerary" onClick={() => add(itinerary, walk)} />;
    }
  }

  const {title, map, time, team, thumbnails} = walk;
  const {url, name} = city;
  const walkLeader = team.find(member => member.role === 'walk-leader');

  // Only show the add to itinerary if you can
  let addToItineraryButton;
  if (time.slots[0]) {
    addToItineraryButton = (
      <h4>
        {walkLeader ? `Led By ${walkLeader['name-first']} ${walkLeader['name-last']} - ` : null}{dateFormatted(time.slots[0][0])}
        {addButton}
      </h4>
    );
  }

  return(
    <section className="walkHeader">
      <section className="coverImage" style={headerBG(city, walk)}>
        <ul className="breadcrumb">
          <li><a href="/"><i className="fa fa-home" /></a></li>
          <li><a href={url}>{`${name} walks`}</a></li>
          <li className="active">{title}</li>
        </ul>
      </section>
      <h1>{title} {favButton}</h1>
      {addToItineraryButton}
      <h4>Meeting at {map.markers[0].title}</h4>
    </section>
  );
};

WalkHeader.propTypes = {
  walk: React.PropTypes.object.isRequired,
  remove: React.PropTypes.func.isRequired,
  add: React.PropTypes.func.isRequired,
};

WalkHeader.defaultProps = {
  remove: null,
  add: null,
};

export default WalkHeader;
<commit_msg>1. updating WalkHeader for multiple walk times<commit_after>import {dateFormatted} from '../../../utils/ItineraryUtils';
import {add, remove} from '../../../actions/ItineraryActions';

//TODO: Duplicate of Itinerary <Walk/>
//TODO: Issue with Favourite being removed on first attempt (works fine for Itinerary)

/**
 * Build a style object for the header
 * @return object A style object for React
 */
function headerBG(city, walk) {
  // Load the BG
  const thumb = (walk.thumbnails[0] && walk.thumbnails[0].url) || city.background;
  let bg;
  if (thumb) {
    bg = 'url(' + thumb + ')';
  } else {
    bg = '#eaeaea';
  }

  return {
    backgroundImage: bg,
    backgroundSize: 'cover',
    backgroundPosition: '50%'
  };
}

const WalkHeader = ({city, walk, favourites, itinerary}) => {
  let favButton, addButton;
  if (favourites) {
    if (favourites.walks.has(walk)) {
      favButton = <button className="removeFavourite" onClick={() => remove(favourites, walk)} />;
    } else {
      favButton = <button className="addFavourite" onClick={() => add(favourites, walk)} />;
    }
  }

  if (itinerary) {
    if (itinerary.walks.has(walk)) {
      addButton = <button className="removeItinerary" onClick={() => remove(itinerary, walk)} />;
    } else {
      addButton = <button className="addItinerary" onClick={() => add(itinerary, walk)} />;
    }
  }

  const {title, map, time, team, thumbnails} = walk;
  const {url, name} = city;
  const walkLeader = team.find(member => member.role === 'walk-leader');

  // Only show the add to itinerary if you can
  let addToItineraryButtons;
  if (time.slots[0]) {
    addToItineraryButtons = time.slots.map(t => <h4> {dateFormatted(t[0])} {addButton} </h4>);
  }

  return(
    <section className="walkHeader">
      <section className="coverImage" style={headerBG(city, walk)}>
        <ul className="breadcrumb">
          <li><a href="/"><i className="fa fa-home" /></a></li>
          <li><a href={url}>{`${name} walks`}</a></li>
          <li className="active">{title}</li>
        </ul>
      </section>
      <h1>{title} {favButton}</h1>
      <h4>Meeting at {map.markers[0].title}</h4>
      <h4>{walkLeader ? `Led By ${walkLeader['name-first']} ${walkLeader['name-last']} - ` : null}</h4>
      {addToItineraryButtons}
    </section>
  );
};

WalkHeader.propTypes = {
  walk: React.PropTypes.object.isRequired,
  remove: React.PropTypes.func.isRequired,
  add: React.PropTypes.func.isRequired,
};

WalkHeader.defaultProps = {
  remove: null,
  add: null,
};

export default WalkHeader;

{'fraction_non_alphanumeric': 0.17563571850975754, 'fraction_numerical': 0.0059136605558840925, 'mean_word_length': 3.2890955198647505, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3868707', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1725, 'n_words': 396}