Files
lucide/site/src/components/IconOverview.tsx
Eric Fennis 5c96b8d848 Feature/site detail page (#99)
* site: pull data from "icons" dir

* site: display icons

* site: remove redundant code

* site: colour mode support

* site: header

* site: order imports

* site: search

* site: add toast when copying icon

* site: styling

* site: hero

* fix: disable theme toggle transitions

* feat: Use Yarn Workspaces

* refactor: Update site deploy scripts

* refactor: Remove dark mode for now

* feat: Add site title

* refactor: Fix warning and format

* feat: Add dark mode back 👀

* feat: Escape key to reset query

* Fix by aelfric

* Add Github link

* Fix #40

* Add site overlay

* sort categories

* Add detail page

* Add first categories

* add box

* move site to root directory

* fix merge issues

* Fix routing issues

* Fix icon overlay

* Add copy and download icon

* Fix style issues

* Add text

* update chakra UI

* remove import

* update dependecies

* add lucide react

* Fix bugs

* delete stats files

* update charkra version

Co-authored-by: John Letey <johnletey@gmail.com>
Co-authored-by: appmachine <appmachine@appmachines-iMac.local>
2020-10-26 08:59:56 +01:00

83 lines
2.2 KiB
TypeScript

import { Box, Input, InputGroup, InputLeftElement, Text, useColorMode, Icon } from "@chakra-ui/core";
import IconList from "./IconList";
import { useEffect, useRef, useState } from "react";
import useSearch from "../lib/search";
import { useRouter } from 'next/router';
import { useDebounce } from '../lib/useDebounce';
import theme from "../lib/theme";
import { Search as SearchIcon } from 'lucide-react';
const IconOverview = ({data}) => {
const router = useRouter();
const { query } = router.query;
const [queryText, setQueryText] = useState(query || '');
const debouncedQuery = useDebounce(queryText, 1000);
const results = useSearch(data, queryText);
const { colorMode } = useColorMode();
const inputElement = useRef(null);
function handleKeyDown(event) {
if (event.key === "/" && inputElement.current !== document.activeElement) {
event.preventDefault();
inputElement.current.focus();
}
}
useEffect(() => {
setQueryText(query || '');
}, [query]);
useEffect(() => {
const { query } = router;
router.push({
query: {
...query,
query: debouncedQuery
},
});
}, [debouncedQuery]);
useEffect(() => {
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, []);
return (
<>
<InputGroup position="sticky" top={4} zIndex={1} bg={
colorMode == "light"
? theme.colors.white
: theme.colors.gray[700]
}>
<InputLeftElement children={(<Icon><SearchIcon /></Icon>)} />
<Input
ref={inputElement}
placeholder={`Search ${Object.keys(data).length} icons (Press "/" to focus)`}
value={queryText}
onChange={(event) => setQueryText(event.target.value)}
/>
</InputGroup>
<Box marginTop={5}>
{results.length > 0 ? (
<IconList icons={results} />
) : (
<Text
fontSize="2xl"
fontWeight="bold"
textAlign="center"
style={{ wordBreak: "break-word" }}
>
No results found for "{query}"
</Text>
)}
</Box>
</>
);
}
export default IconOverview;