-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite apis, and remove unnecessary action
- Loading branch information
Showing
17 changed files
with
82 additions
and
140 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
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
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
This file was deleted.
Oops, something went wrong.
53 changes: 12 additions & 41 deletions
53
src/components/CompanyAndJobTitle/TimeAndSalary/ViewLog.js
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 |
---|---|---|
@@ -1,54 +1,25 @@ | ||
import { Component } from 'react'; | ||
import { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
import { useViewSalaryWorkTimes } from 'hooks/viewLog'; | ||
|
||
import { viewSalaryWorkTimes } from '../../../actions/viewLog'; | ||
|
||
class ViewLog extends Component { | ||
componentDidMount() { | ||
const { contentIds } = this.props; | ||
const ViewLog = ({ pageName, page, contentIds }) => { | ||
// Send view to backend | ||
const viewSalaryWorkTimes = useViewSalaryWorkTimes(); | ||
useEffect(() => { | ||
const referrer = window.location.href; | ||
viewSalaryWorkTimes({ contentIds, referrer }); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [pageName, page, viewSalaryWorkTimes]); | ||
|
||
this.props.viewSalaryWorkTimes({ contentIds, referrer }); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
const prevPageName = prevProps.pageName; | ||
const prevPage = prevProps.page; | ||
const pageName = this.props.pageName; | ||
const page = this.props.page; | ||
|
||
if (prevPageName !== pageName || prevPage !== page) { | ||
const { contentIds } = this.props; | ||
const referrer = window.location.href; | ||
|
||
this.props.viewSalaryWorkTimes({ contentIds, referrer }); | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
ViewLog.propTypes = { | ||
// key | ||
pageName: PropTypes.string.isRequired, | ||
page: PropTypes.number.isRequired, | ||
|
||
contentIds: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
|
||
// method | ||
viewSalaryWorkTimes: PropTypes.func.isRequired, | ||
}; | ||
|
||
const mapStateToProps = state => ({}); | ||
|
||
const mapDispatchToProps = dispatch => | ||
bindActionCreators({ viewSalaryWorkTimes }, dispatch); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(ViewLog); | ||
export default ViewLog; |
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,42 +1,22 @@ | ||
import React, { Component } from 'react'; | ||
import React, { useContext, useRef, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import withFB from './withFB'; | ||
import FacebookContext from 'contexts/FacebookContext'; | ||
|
||
class FacebookWrapper extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.container = null; | ||
this.handleContainer = this.handleContainer.bind(this); | ||
} | ||
const FacebookWrapper = ({ children }) => { | ||
const FB = useContext(FacebookContext); | ||
const container = useRef(null); | ||
|
||
componentDidMount() { | ||
if (this.props.FB && this.container) { | ||
this.props.FB.XFBML.parse(this.container); | ||
useEffect(() => { | ||
if (FB && container) { | ||
FB.XFBML.parse(container.current); | ||
} | ||
} | ||
}); | ||
|
||
// 讓 FB 重新 parse children | ||
componentDidUpdate() { | ||
// if FB instance | ||
if (this.props.FB && this.container) { | ||
this.props.FB.XFBML.parse(this.container); | ||
} | ||
} | ||
|
||
handleContainer(container) { | ||
this.container = container; | ||
} | ||
|
||
render() { | ||
const { children } = this.props; | ||
|
||
return <div ref={this.handleContainer}>{children}</div>; | ||
} | ||
} | ||
return <div ref={container}>{children}</div>; | ||
}; | ||
|
||
FacebookWrapper.propTypes = { | ||
children: PropTypes.node, | ||
FB: PropTypes.object, | ||
}; | ||
|
||
export default withFB(FacebookWrapper); | ||
export default FacebookWrapper; |
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
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
Oops, something went wrong.