Skip to content

Commit

Permalink
#30 add opensearch support
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hatch committed Dec 2, 2017
1 parent dd852fa commit 3246066
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link rel="search" href="https://steexp.com/search.xml"
title="Stellar Explorer" type="application/opensearchdescription+xml">
<title>Stellar Explorer</title>
</head>
<body>
Expand Down
12 changes: 12 additions & 0 deletions public/search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Stellar Explorer</ShortName>
<Description>Ledger explorer for the Stellar Network</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/png">favicon.ico</Image>
<Url type="text/html" method="get" template="/search/{searchTerms}" />
<Url
type="application/opensearchdescription+xml"
rel="self"
template="https://steexp.com/search.xml"
/>
</OpenSearchDescription>
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Footer from './components/layout/Footer'
import Home from './components/Home'
import NoMatchError from './components/shared/NoMatchError'
import Error from './components/shared/Error'
import SearchBox from './components/layout/SearchBox'
import SponsoredLink from './components/shared/SponsoredLink'

import Ledger from './components/Ledger'
Expand Down Expand Up @@ -127,6 +128,7 @@ class App extends Component {
<Route path="/account/:id" component={Account} />
<Route path="/anchors" component={Anchors} />
<Route path="/exchanges" component={Exchanges} />
<Route path="/search/:id" component={SearchBox} />
<Route path="/error/not-found/:id" component={NoMatchError} />
<Route path="/error/general/:id" component={Error} />
<Route component={Error} />
Expand Down
26 changes: 20 additions & 6 deletions src/components/layout/SearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import {injectIntl} from 'react-intl'
import {isPublicKey, isStellarAddress, isTxHash} from '../../lib/utils'

class SearchBox extends React.Component {
state = {
fromBox: true,
}

noMatch = searchStr => {
console.log(`unknown search string [${searchStr}]`)
window.location.href = `/error/not-found/${searchStr}`
}

search = event => {
event.preventDefault()

const searchBox = event.target.firstElementChild
const searchStr = searchBox.value.trim()
search = searchStr => {
console.log(`searchStr: ${searchStr}`)

if (isPublicKey(searchStr)) {
this.props.history.push(`/account/${searchStr}`)
} else if (isTxHash(searchStr)) {
Expand All @@ -30,7 +29,22 @@ class SearchBox extends React.Component {
}
}

searchHandler = event => {
event.preventDefault()
const searchBox = event.target.firstElementChild
const searchStr = searchBox.value.trim()
this.search(searchStr)
}

componentDidMount() {
const id = this.props.match.params.id
if (id && id.length > 0) {
this.search(id)
}
}

render() {
if (this.state.fromBox === false) return null // URI search
const {formatMessage} = this.props.intl
return (
<form onSubmit={this.search}>
Expand Down

0 comments on commit 3246066

Please sign in to comment.