Skip to content

Commit

Permalink
fix: Searchbar
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzyvinci committed Jan 17, 2022
1 parent 7b0a509 commit 937b54e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import Navbar from './components/Navbar'
import Warning from './components/Warning'
import Footer from './components/Footer'
import Error from './pages/Error'

import Homepage from './pages/Homepage'
import Blocks from './pages/Blocks'
Expand All @@ -31,6 +30,8 @@ import Account from './pages/Account'
import Token from './pages/Token'
import Stake from './pages/Stake'

import Missing from './pages/Missing'
import Error from './pages/Error'

const linkPage = [
{path: '/', component: <Homepage />},
Expand Down Expand Up @@ -60,6 +61,7 @@ const linkPage = [
{path: '/token/:id', children: <Token />},
{path: '/stake/:id', children: <Stake />},

{path: '/missing/:id', component: <Missing />},
{path: '/error', component: <Error />}
]

Expand Down
17 changes: 5 additions & 12 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,20 @@ import {
ChevronDownIcon,
ChevronRightIcon
} from '@chakra-ui/icons';
import { useHistory } from 'react-router-dom'
import brandLogo from '../assets/moonriver-logo.svg'
import { getUrl } from '../search'


export default function Navbar() {
const { isOpen, onToggle } = useDisclosure();
let searchTerm = ''
let history = useHistory()


function handleSearch(e) {
//console.log(e)
//console.log(`${e.target.value}${e.key}`)
if (e.key === 'Enter') {
console.log(searchTerm)
e.target.value = ''
getUrl(searchTerm).then(url => {
url ? history.push(url) : history.push('/error')
const target = e.target.value.toLowerCase()
getUrl(target).then(url => {
url ? window.open(url, "_self") : window.open(`/missing/${target}`, "_self")
})
searchTerm = ''
} else {
searchTerm += e.key
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/pages/Missing.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import { Heading } from '@chakra-ui/react'
import { useParams } from 'react-router-dom';

export default function Missing() {
const { id } = useParams();
return (
<Heading textAlign='center'>{`${id} can't be found`}</Heading>
)
}

0 comments on commit 937b54e

Please sign in to comment.