-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4eeb0ce
commit 770fbb2
Showing
12 changed files
with
254 additions
and
143 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
85 changes: 85 additions & 0 deletions
85
src/javascript/app/pages/trade/markets/market-selector.jsx
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,85 @@ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { CustomDropdown } from '@deriv-com/quill-ui'; | ||
import { MarketsDropdown, getMarketName } from './markets-dropdown.jsx'; | ||
import { getElementById } from '../../../../_common/common_functions'; | ||
import { localize } from '../../../../_common/localize'; | ||
import { useContractChange, useMarketChange } from '../../../hooks/events.js'; | ||
import Defaults, { PARAM_NAMES } from '../defaults.js'; | ||
|
||
const MarketSelector = () => { | ||
const [marketLabel, setMarketLabel] = useState(getMarketName()); | ||
const [isMarketDropdownOpen, setMarketDropdownOpen] = useState(false); | ||
const [isContractDropdownOpen, setIsContractDropdownOpen] = useState(false); | ||
const [tradeTypeLabel, setTradeTypeLabel] = useState(''); | ||
const hasContractChange = useContractChange(); | ||
const hasMarketChange = useMarketChange(); | ||
|
||
const contractDropdownRef = useRef(null); | ||
|
||
const handleOutsideClick = (event) => { | ||
if ( | ||
contractDropdownRef.current && | ||
!contractDropdownRef.current.contains(event.target) | ||
) { | ||
setIsContractDropdownOpen(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener('mousedown', handleOutsideClick); | ||
document.addEventListener('touchstart', handleOutsideClick); | ||
|
||
return () => { | ||
document.removeEventListener('mousedown', handleOutsideClick); | ||
document.removeEventListener('touchstart', handleOutsideClick); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
const contractName = decodeURIComponent( | ||
Defaults.get(PARAM_NAMES.CONTRACT_NAME) | ||
); | ||
setTradeTypeLabel(contractName); | ||
setIsContractDropdownOpen(false); | ||
}, [hasContractChange]); | ||
|
||
useEffect(() => { | ||
setMarketLabel(getMarketName()); | ||
setMarketDropdownOpen(false); | ||
}, [hasMarketChange]); | ||
|
||
return ( | ||
<div className='quill-market-selector-container'> | ||
<CustomDropdown | ||
containerClassName='quill-market-selector-dropdown' | ||
label={localize('Market')} | ||
value={marketLabel} | ||
> | ||
<MarketsDropdown /> | ||
</CustomDropdown> | ||
<div ref={contractDropdownRef} className='quill-market-selector-dropdown'> | ||
<CustomDropdown | ||
label={localize('Trade types')} | ||
value={tradeTypeLabel} | ||
onClickDropdown={() => setIsContractDropdownOpen((e) => !e)} | ||
/> | ||
<div | ||
id='contract_component' | ||
className={`contract-dropdown ${ | ||
isContractDropdownOpen && 'contract-dropdown-open' | ||
}`} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const init = () => { | ||
ReactDOM.render( | ||
<MarketSelector />, | ||
getElementById('markets-dropdown-container') | ||
); | ||
}; | ||
|
||
export default init; |
Oops, something went wrong.