forked from seanpdoyle/select-your-own-seat
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Extract SeatingMap component [NEW]
This commit has no equivalent in the Stimulus branch. Here, a concept of a `SeatingMap` component emerges from `index.js`. This is a quality of working in React. The library library makes it easy to extract related and semantic behavior into into reusable, testable components. Rails has tools like partial, presenters, view object, etc. But when faced with a ERB template with a rich history of changes, dependencies on instance variables, global view helpers, local variables contribute to some of the difficulty of extracting isolated, and testable behavior.
- Loading branch information
Showing
2 changed files
with
67 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react' | ||
|
||
const buildSectionElements = (sections) => { | ||
return sections.map((section, index) => { | ||
const seatElements = section.seats.map((seat) => ( | ||
<a | ||
href={seat.venueFloorSeatPath} | ||
aria-label={seat.ariaLabel} | ||
key={seat.venueFloorSeatPath} | ||
> | ||
<use | ||
width="12px" | ||
height="12px" | ||
xlinkHref={seat.href} | ||
x={seat.x} | ||
y={seat.y} | ||
/> | ||
</a> | ||
)) | ||
|
||
return <g key={index}>{seatElements}</g> | ||
}) | ||
} | ||
|
||
export default class extends React.Component { | ||
render() { | ||
const { sections } = this.props | ||
const sectionElements = buildSectionElements(sections) | ||
|
||
return( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlnsXlink="http://www.w3.org/1999/xlink" | ||
className="syos-seat-map" | ||
width="1600px" | ||
height="1600px" | ||
viewBox="0 0 1600 1600" | ||
> | ||
<rect fill="none" x="0" y="0" width="1600" height="1600"></rect> | ||
<svg style={{display: "none"}}> | ||
<symbol | ||
id="seat-icon-unselected" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
> | ||
<circle fill="#37b24d" r="12" cx="12" cy="12"></circle> | ||
<circle fill="#ffffff" r="6" cx="12" cy="12"></circle> | ||
</symbol> | ||
|
||
<symbol | ||
id="seat-icon-selected" | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
> | ||
<circle fill="#37b24d" r="12" cx="12" cy="12"></circle> | ||
</symbol> | ||
</svg> | ||
{ sectionElements } | ||
</svg> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters