mirror of
https://github.com/Xevion/icons.git
synced 2025-12-06 01:15:19 -06:00
Improve scaling on multiple viewports
- fix improper variable being used - extract useMemo into variable
This commit is contained in:
@@ -7,7 +7,7 @@ type Props = {
|
||||
|
||||
const IconCatalog: FunctionComponent<Props> = ({icons}) => {
|
||||
return <div
|
||||
className="flex flex-wrap rounded gap-y-4 p-1.5 rounded overflow-x-clip mb-5">{icons.map(({id, setId}) => {
|
||||
className="grid grid-cols-3 sm:grid-cols-5 md:grid-cols-8 lg:grid-cols-9 xl:grid-cols-11 rounded gap-4 p-1.5 rounded overflow-x-clip mb-5">{icons.map(({id, setId}) => {
|
||||
return <DisplayIconSingle key={id + setId} id={id} setId={setId}/>
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@ import Head from "next/head";
|
||||
import iconList from "@utils/iconList";
|
||||
import {useEffect, useMemo, useState} from "react";
|
||||
import {useDebounce} from "usehooks-ts";
|
||||
import { useHotkeys } from 'react-hotkeys-hook'
|
||||
import {useHotkeys} from 'react-hotkeys-hook'
|
||||
import {AiOutlineLoading3Quarters} from "react-icons/ai";
|
||||
import IconCatalog from "@components/render/IconCatalog";
|
||||
import NoSSR from 'react-no-ssr';
|
||||
@@ -37,7 +37,7 @@ const Home: NextPage = () => {
|
||||
}, [debouncedQuery]);
|
||||
|
||||
useEffect(() => {
|
||||
setLazyIcons(icons.slice(0, 100))
|
||||
setLazyIcons(allFilteredIcons.slice(0, 100))
|
||||
}, [allFilteredIcons]);
|
||||
|
||||
useHotkeys(['ctrl+k', 'ctrl+/'], () => {
|
||||
@@ -46,6 +46,16 @@ const Home: NextPage = () => {
|
||||
const [searchRef, focusSearch] = useFocus<HTMLInputElement>()
|
||||
const [lazyIcons, setLazyIcons] = useState<IconIdentifierPair[]>([]);
|
||||
|
||||
const infiniteScroll = useMemo(() => <InfiniteScroll hasMore={lazyIcons.length < allFilteredIcons.length}
|
||||
loader={<span>Loading...</span>}
|
||||
dataLength={lazyIcons.length}
|
||||
next={() => {
|
||||
const newLength = Math.min(lazyIcons.length + 300, allFilteredIcons.length)
|
||||
setLazyIcons(allFilteredIcons.slice(0, newLength))
|
||||
}}>
|
||||
<IconCatalog icons={lazyIcons}/>
|
||||
</InfiniteScroll>, [lazyIcons]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -53,7 +63,7 @@ const Home: NextPage = () => {
|
||||
<meta name="description" content="Generated by create-t3-app"/>
|
||||
<link rel="icon" href="/favicon.ico"/>
|
||||
</Head>
|
||||
<main className="flex flex-col items-center m-auto p-6 max-w-[100ch]">
|
||||
<main className="flex flex-col items-center m-auto p-6 max-w-[130ch]">
|
||||
<div className="flex max-w-[60ch] px-1 py-2 m-4">
|
||||
<input
|
||||
ref={searchRef}
|
||||
@@ -78,15 +88,7 @@ const Home: NextPage = () => {
|
||||
</NoSSR>
|
||||
</div>
|
||||
<div>
|
||||
{useMemo(() => <InfiniteScroll hasMore={lazyIcons.length < allFilteredIcons.length}
|
||||
loader={<span>Loading...</span>}
|
||||
dataLength={lazyIcons.length}
|
||||
next={() => {
|
||||
const newLength = Math.min(lazyIcons.length + 300, allFilteredIcons.length)
|
||||
setLazyIcons(allFilteredIcons.slice(0, newLength))
|
||||
}}>
|
||||
<IconCatalog icons={lazyIcons}/>
|
||||
</InfiniteScroll>, [lazyIcons])}
|
||||
{infiniteScroll}
|
||||
</div>
|
||||
</main>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user