From 01715aed71b73fcda68d134220a22883f428418c Mon Sep 17 00:00:00 2001 From: qwertyforce <44163887+qwertyforce@users.noreply.github.com> Date: Sun, 13 Sep 2020 18:37:06 +0300 Subject: [PATCH] AppBar search --- components/AppBar.tsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/AppBar.tsx b/components/AppBar.tsx index 264a336..0976397 100644 --- a/components/AppBar.tsx +++ b/components/AppBar.tsx @@ -1,11 +1,12 @@ -import React from 'react'; +import React, { useState } from 'react'; import { fade,makeStyles } from '@material-ui/core/styles'; import AppBar from '@material-ui/core/AppBar'; import Toolbar from '@material-ui/core/Toolbar'; import Typography from '@material-ui/core/Typography'; import SearchIcon from '@material-ui/icons/Search'; import InputBase from '@material-ui/core/InputBase'; - +import Link from './Link' +import { useRouter } from 'next/router' const useStyles = makeStyles((theme) => ({ app_bar:{ @@ -62,20 +63,30 @@ const useStyles = makeStyles((theme) => ({ export default function DenseAppBar() { const classes = useStyles(); - + const router = useRouter() + const [tags, setTags] = useState(''); + const handleKeyPress = (e: React.KeyboardEvent) => { + if (e.keyCode === 13 || e.which === 13) { + router.push(`/search?q=${tags}`) + } + }; return (
- Scenery + + Scenery +
setTags(e.target.value)} + onKeyPress={(e)=>handleKeyPress(e)} classes={{ root: classes.inputRoot, input: classes.inputInput,