1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-05 02:45:18 +02:00

Added warning about unsupported prefix. Added support for Spotify search. Edited README file

This commit is contained in:
unknown 2021-06-25 10:42:44 +02:00
parent aec00982ba
commit 0c3a27febd
9 changed files with 73 additions and 38 deletions

View file

@ -0,0 +1,17 @@
.SearchBar {
width: 100%;
padding: 10px 0;
color: var(--color-primary);
/* font-size: 20px; */
margin-bottom: 20px;
background-color: transparent;
border: none;
border-bottom: 2px solid var(--color-accent);
opacity: 0.5;
transition: all 0.2s;
}
.SearchBar:focus {
opacity: 1;
outline: none;
}

View file

@ -0,0 +1,50 @@
import { useRef, useEffect, KeyboardEvent } from 'react';
// Redux
import { connect } from 'react-redux';
import { createNotification } from '../../store/actions';
// Typescript
import { NewNotification } from '../../interfaces';
// CSS
import classes from './SearchBar.module.css';
// Utils
import { searchParser } from '../../utility';
interface ComponentProps {
createNotification: (notification: NewNotification) => void;
}
const SearchBar = (props: ComponentProps): JSX.Element => {
const inputRef = useRef<HTMLInputElement>(document.createElement('input'));
useEffect(() => {
inputRef.current.focus();
}, [])
const searchHandler = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.code === 'Enter') {
const prefixFound = searchParser(inputRef.current.value);
if (!prefixFound) {
props.createNotification({
title: 'Error',
message: 'Prefix not found'
})
}
}
}
return (
<input
ref={inputRef}
type='text'
className={classes.SearchBar}
onKeyDown={(e) => searchHandler(e)}
/>
)
}
export default connect(null, { createNotification })(SearchBar);