king
2020-10-11 5902ba5c3ff85efc78c95364196cd6ab5d2d1601
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { useState } from 'react'
import { useDrop } from 'react-dnd'
import { is, fromJS } from 'immutable'
import update from 'immutability-helper'
 
import Card from './card'
import Action from './action'
import './index.scss'
 
const Container = ({list, handleList, handleMenu, deleteMenu, profileAction, handleStyle }) => {
  const [cards, setCards] = useState(list)
  const moveCard = (id, atIndex) => {
    const { card, index } = findCard(id)
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    handleList(_cards)
  }
 
  if (!is(fromJS(cards), fromJS(list))) {
    setCards(list)
  }
  
  const findCard = id => {
    const card = cards.filter(c => `${c.uuid}` === id)[0]
    return {
      card,
      index: cards.indexOf(card),
    }
  }
 
  const editCard = id => {
    const { card } = findCard(id)
    handleMenu(card)
  }
 
  const changeStyle = id => {
    const { card } = findCard(id)
    handleStyle(card)
  }
 
  const profileCard = id => {
    const { card } = findCard(id)
    profileAction(card)
  }
 
  const delCard = id => {
    const { card } = findCard(id)
    deleteMenu(card)
  }
 
  let cardIds = cards.map(card => card.uuid)
 
  const [, drop] = useDrop({
    accept: 'action',
    drop() {}
  })
 
  return (
    <div ref={drop} className="ant-row card-detail-row">
      {cards.map(card => {
        if (card.eleType === 'button') {
          return (
            <Action
              id={card.uuid}
              key={card.uuid}
              cardIds={cardIds}
              card={card}
              moveCard={moveCard}
              editCard={editCard}
              changeStyle={changeStyle}
              profileCard={profileCard}
              delCard={delCard}
              findCard={findCard}
            />
          )
        } else {
          return (
            <Card
              id={card.uuid}
              key={card.uuid}
              cardIds={cardIds}
              card={card}
              moveCard={moveCard}
              editCard={editCard}
              changeStyle={changeStyle}
              delCard={delCard}
              findCard={findCard}
            />
          )
        }
      })}
    </div>
  )
}
export default Container