import Header from "../../components/Header"; import apiOdoo from "../../helpers/apiOdoo"; import InfiniteScroll from "react-infinite-scroll-component"; import { useEffect, useState } from "react"; import Spinner from "../../components/Spinner"; import Layout from "../../components/Layout"; import ManufactureCard from "../../components/ManufactureCard"; export async function getServerSideProps() { let initialManufactures = await apiOdoo('GET', '/api/v1/manufacture?limit=31'); return {props: {initialManufactures}}; } export default function Brands({ initialManufactures }) { const [manufactures, setManufactures] = useState(initialManufactures.manufactures); const [hasMoreManufacture, setHasMoreManufacture] = useState(true); const [manufactureStartwith, setManufactureStartWith] = useState(''); const alpha = Array.from(Array(26)).map((e, i) => i + 65); const alphabets = alpha.map((x) => String.fromCharCode(x)); const getMoreManufactures = 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]); }; const filterManufactureStartWith = (character) => { setManufactures([]); if (manufactureStartwith == character) { setManufactureStartWith(''); } else { setManufactureStartWith(character); } }; useEffect(() => { getMoreManufactures(); }, [manufactureStartwith]); return ( <>

Semua Brand di Indoteknik

{alphabets.map((alphabet, index) => ( ))}
} > {manufactures?.map((manufacture, index) => ( manufacture.name ? ( ) : '' ))}
) }