1 | import React, { Component } from 'react'
|
2 |
|
3 | export const shotTypeSortOrder = [
|
4 | 'front',
|
5 | 'on_model',
|
6 | 'back',
|
7 | 'detail',
|
8 | 'other'
|
9 | ]
|
10 |
|
11 | export default function withSortedShots(WrappedComponent) {
|
12 | return class extends Component {
|
13 | sortShots = () => {
|
14 | const { shots: inShots } = this.props
|
15 | return inShots.sort((shot1, shot2) => {
|
16 | return shotTypeSortOrder.indexOf(shot1.shot_type) < shotTypeSortOrder.indexOf(shot2.shot_type) ? -1 : 1
|
17 | })
|
18 | }
|
19 |
|
20 | render () {
|
21 | const { product } = this.props
|
22 | const sortedShots = this.sortShots()
|
23 | const shots = sortedShots.map((shot) => {
|
24 | return ({
|
25 | alt: `${product.name} ${shot.shot_type}`,
|
26 | src: shot.cloudinary_key
|
27 | })
|
28 | })
|
29 | return <WrappedComponent {...this.props} images={shots} />
|
30 | }
|
31 | }
|
32 | }
|
33 |
|
\ | No newline at end of file |