zhongrj
2025-11-24 276323dce9613867abb3f58a4cc2abbfb2fd0dea
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
import React from 'react';
import '../css/ShareButton.scss';
import SharePopup from './SharePopup';
import PropTypes from 'prop-types';
import { _ } from '../classes/gettext';
 
class ShareButton extends React.Component {
  static defaultProps = {
    task: null,
    popupPlacement: 'top'
  };
  static propTypes = {
    task: PropTypes.object.isRequired,
    linksTarget: PropTypes.oneOf(['map', '3d']).isRequired,
    popupPlacement: PropTypes.string,
    queryParams: PropTypes.object
  }
 
  constructor(props){
    super(props);
 
    this.state = { 
      showPopup: false,
      task: props.task
    };
 
    this.handleClick = this.handleClick.bind(this);
    this.handleTaskChanged = this.handleTaskChanged.bind(this);
  }
 
  handleClick(e){
    this.setState({ showPopup: !this.state.showPopup });
  }
 
  hidePopup(){
    this.setState({showPopup: false});
  }
 
  handleTaskChanged(task){
    this.setState({task});
  }
 
  render() {
    const popup = <SharePopup 
            task={this.state.task}
            taskChanged={this.handleTaskChanged}
            placement={this.props.popupPlacement}
            linksTarget={this.props.linksTarget}
            queryParams={this.props.queryParams}
          />;
 
    return (
      <div className="shareButton" onClick={e => { e.stopPropagation(); }}>
        {this.props.popupPlacement === 'top' && this.state.showPopup ? 
          popup : ""}
        <button 
          type="button"
          onClick={this.handleClick}
          className={"shareButton btn btn-sm " + (this.state.task.public ? "btn-primary" : "btn-secondary")}>
          <i className="fa fa-share-alt"></i> {_("Share")}
        </button>
        {this.props.popupPlacement === 'bottom' && this.state.showPopup ? 
          popup : ""}
      </div>
    );
  }
}
 
export default ShareButton;