From fb4b7aea05526e154193d40a0cde6d674be263e7 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 22 Nov 2022 10:40:22 +0700 Subject: Brand alphabet slider --- src/components/Header.js | 6 +++++- src/pages/shop/brands.js | 26 +++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/components/Header.js b/src/components/Header.js index 80a7fb81..f5eb22f4 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -32,7 +32,11 @@ export default function Header({ title }) { const searchSubmit = (e) => { e.preventDefault(); - router.push(`/shop/search?q=${searchQuery}`, undefined, { scroll: false }); + if (searchQuery.length > 0) { + router.push(`/shop/search?q=${searchQuery}`, undefined, { scroll: false }); + } else { + searchQueryRef.current.focus(); + } } return ( diff --git a/src/pages/shop/brands.js b/src/pages/shop/brands.js index 5b49c922..8a7b7684 100644 --- a/src/pages/shop/brands.js +++ b/src/pages/shop/brands.js @@ -5,11 +5,9 @@ import "react-lazy-load-image-component/src/effects/blur.css"; import Link from "../../components/Link"; import { createSlug } from "../../helpers/slug"; import InfiniteScroll from "react-infinite-scroll-component"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useState } from "react"; import Spinner from "../../components/Spinner"; import Layout from "../../components/Layout"; -import { Swiper, SwiperSlide } from "swiper/react"; -import "swiper/css"; export async function getServerSideProps() { let initialManufactures = await apiOdoo('GET', '/api/v1/manufacture?limit=31'); @@ -24,12 +22,12 @@ export default function Brands({ initialManufactures }) { const alpha = Array.from(Array(26)).map((e, i) => i + 65); const alphabets = alpha.map((x) => String.fromCharCode(x)); - const getMoreManufactures = async () => { + const getMoreManufactures = useCallback(async () => { const name = manufactureStartwith != '' ? `${manufactureStartwith}%` : ''; const result = await apiOdoo('GET', `/api/v1/manufacture?limit=30&offset=${manufactures.length}&name=${name}`); setHasMoreManufacture(manufactures.length + 30 < result.manufacture_total) setManufactures((manufactures) => [...manufactures, ...result.manufactures]); - }; + }, [manufactureStartwith]); const filterManufactureStartWith = (character) => { setManufactures([]); @@ -42,28 +40,26 @@ export default function Brands({ initialManufactures }) { useEffect(() => { getMoreManufactures(); - }, [manufactureStartwith]); + }, [getMoreManufactures]); return ( <>
-

Semua Brand di Indoteknik

- +

Semua Brand di Indoteknik

+
{alphabets.map((alphabet, index) => ( - - - + ))} - +
-- cgit v1.2.3