mirror of
https://github.com/dap-ps/discover.git
synced 2025-02-12 09:17:32 +00:00
Fix search open and close logic
This commit is contained in:
parent
b50ea64449
commit
a5ce9cc472
@ -67,7 +67,7 @@ class DiscoverService extends BlockchainService {
|
|||||||
.call({ from: this.sharedContext.account })
|
.call({ from: this.sharedContext.account })
|
||||||
|
|
||||||
const dappMetadata = dappsCache[dapp.metadata]
|
const dappMetadata = dappsCache[dapp.metadata]
|
||||||
if (typeof dappMetadata !== 'undefined') {
|
if (dappMetadata) {
|
||||||
delete dappsCache[dapp.metadata]
|
delete dappsCache[dapp.metadata]
|
||||||
dapp.metadata = dappMetadata.details
|
dapp.metadata = dappMetadata.details
|
||||||
dapp.metadata.status = dappMetadata.status
|
dapp.metadata.status = dappMetadata.status
|
||||||
@ -79,7 +79,7 @@ class DiscoverService extends BlockchainService {
|
|||||||
Object.keys(dappsCache).forEach(metadataHash => {
|
Object.keys(dappsCache).forEach(metadataHash => {
|
||||||
const dappMetadata = dappsCache[metadataHash]
|
const dappMetadata = dappsCache[metadataHash]
|
||||||
|
|
||||||
if (dappMetadata.status == 'NEW') {
|
if (dappMetadata.status == 'APPROVED') {
|
||||||
dapps.push({
|
dapps.push({
|
||||||
developer: '',
|
developer: '',
|
||||||
id: dappMetadata.compressedMetadata,
|
id: dappMetadata.compressedMetadata,
|
||||||
|
@ -8,7 +8,7 @@ const DEFAULT_HEADERS = {
|
|||||||
const executeRequest = async function(method, url, reqStruct) {
|
const executeRequest = async function(method, url, reqStruct) {
|
||||||
return axios({
|
return axios({
|
||||||
method,
|
method,
|
||||||
url: `http://localhost:4000${url}`,
|
url,
|
||||||
data: {
|
data: {
|
||||||
...reqStruct.body,
|
...reqStruct.body,
|
||||||
},
|
},
|
||||||
|
@ -12,12 +12,43 @@ class Search extends React.Component {
|
|||||||
dapps: [],
|
dapps: [],
|
||||||
isSearching: false,
|
isSearching: false,
|
||||||
}
|
}
|
||||||
|
this.nodes = React.createRef()
|
||||||
this.handleChange = this.handleChange.bind(this)
|
this.handleChange = this.handleChange.bind(this)
|
||||||
|
this.applyClass = this.applyClass.bind(this)
|
||||||
|
this.closeSearchBox = this.closeSearchBox.bind(this)
|
||||||
|
this.onClickBody = this.onClickBody.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
document.addEventListener('click', this.onClickBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('click', this.onClickBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
onClickBody(e) {
|
||||||
|
if (this.nodes && this.nodes.current.contains(e.target) === true) return
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isSearching: false,
|
||||||
|
dapps: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
closeSearchBox() {}
|
||||||
|
|
||||||
|
applyClass(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
this.setState({
|
||||||
|
isSearching: true,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(e) {
|
handleChange(e) {
|
||||||
const { value } = e.target
|
const { value } = e.target
|
||||||
const { dappState } = this.props
|
const { dappState } = this.props
|
||||||
|
this.setState({ isSearching: true })
|
||||||
if (value.length > 1) {
|
if (value.length > 1) {
|
||||||
const searchExp = new RegExp(value, 'i')
|
const searchExp = new RegExp(value, 'i')
|
||||||
const dapps = dappState.dapps.filter(dapp => {
|
const dapps = dappState.dapps.filter(dapp => {
|
||||||
@ -26,10 +57,9 @@ class Search extends React.Component {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
this.setState({ dapps, isSearching: true })
|
this.setState({ dapps })
|
||||||
} else if (value === '') {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
isSearching: false,
|
|
||||||
dapps: [],
|
dapps: [],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -38,8 +68,15 @@ class Search extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const { searchStyle, searchResultStyle } = this.props
|
const { searchStyle, searchResultStyle } = this.props
|
||||||
const { dapps, isSearching } = this.state
|
const { dapps, isSearching } = this.state
|
||||||
|
const cssClassVisible = isSearching ? styles.isOpen : ''
|
||||||
return (
|
return (
|
||||||
<div className={styles.search_container}>
|
<>
|
||||||
|
<div className={`${styles.dim}`} />
|
||||||
|
<div
|
||||||
|
ref={this.nodes}
|
||||||
|
className={[styles.search_container, cssClassVisible].join(' ')}
|
||||||
|
onClick={e => this.applyClass(e)}
|
||||||
|
>
|
||||||
<img src={searchIcon} alt="Search Icon" width="16" height="16" />
|
<img src={searchIcon} alt="Search Icon" width="16" height="16" />
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@ -48,11 +85,14 @@ class Search extends React.Component {
|
|||||||
placeholder="Search Dapps"
|
placeholder="Search Dapps"
|
||||||
/>
|
/>
|
||||||
{isSearching && (
|
{isSearching && (
|
||||||
<div className={[styles.searchResults, searchResultStyle].join(' ')}>
|
<div
|
||||||
|
className={[styles.searchResults, searchResultStyle].join(' ')}
|
||||||
|
>
|
||||||
<SearchResultItem showActionButtons={false} dapps={dapps} />
|
<SearchResultItem showActionButtons={false} dapps={dapps} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
@media (min-width: $desktop) {
|
@media (min-width: $desktop) {
|
||||||
.search_container {
|
.search_container {
|
||||||
height: calculateRem(20);
|
height: calculateRem(20);
|
||||||
cursor: pointer;
|
|
||||||
border-radius: calculateRem(40);
|
border-radius: calculateRem(40);
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
padding: calculateRem(10);
|
padding: calculateRem(10);
|
||||||
@ -16,25 +15,6 @@
|
|||||||
z-index: 1;
|
z-index: 1;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
|
|
||||||
&:hover {
|
|
||||||
width: calculateRem(240);
|
|
||||||
.search {
|
|
||||||
width: calculateRem(240);
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.searchResults {
|
|
||||||
z-index: 99;
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
top: calculateRem(39);
|
|
||||||
background: #ffffff;
|
|
||||||
left: 0;
|
|
||||||
border-bottom-left-radius: calculateRem(5);
|
|
||||||
border-bottom-right-radius: calculateRem(5);
|
|
||||||
box-shadow: 0 0 0 rgba(0, 34, 51, 0.08),
|
|
||||||
0px 2px 4px rgba(0, 34, 51, 0.16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
img {
|
img {
|
||||||
align-self: center;
|
align-self: center;
|
||||||
}
|
}
|
||||||
@ -48,7 +28,7 @@
|
|||||||
outline: none;
|
outline: none;
|
||||||
transition: 0.4s;
|
transition: 0.4s;
|
||||||
line-height: calculateRem(15);
|
line-height: calculateRem(15);
|
||||||
width: 0px;
|
width: calculateRem(20);
|
||||||
&::placeholder {
|
&::placeholder {
|
||||||
color: #939ba1;
|
color: #939ba1;
|
||||||
}
|
}
|
||||||
@ -60,6 +40,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.isOpen {
|
||||||
|
width: calculateRem(240);
|
||||||
|
.search {
|
||||||
|
width: calculateRem(240);
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.searchResults {
|
||||||
|
z-index: 99;
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
top: 1.6rem;
|
||||||
|
background: #ffffff;
|
||||||
|
left: 0;
|
||||||
|
border-bottom-left-radius: calculateRem(5);
|
||||||
|
border-bottom-right-radius: calculateRem(5);
|
||||||
|
box-shadow: 0 0 0 rgba(0, 34, 51, 0.08), 0px 2px 4px rgba(0, 34, 51, 0.16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: $desktop) {
|
@media (max-width: $desktop) {
|
||||||
.search_container {
|
.search_container {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -93,4 +92,7 @@
|
|||||||
background-size: cover;
|
background-size: cover;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.isOpen {
|
||||||
|
width: 90vw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,12 @@ const SearchResultItem = props => {
|
|||||||
>
|
>
|
||||||
{description}
|
{description}
|
||||||
</p>
|
</p>
|
||||||
<a className={styles.link} href={url}>
|
<a
|
||||||
|
className={styles.link}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
href={url}
|
||||||
|
>
|
||||||
{url}
|
{url}
|
||||||
→
|
→
|
||||||
</a>
|
</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user