import odooApi from '@/core/api/odooApi' import Spinner from '@/core/components/elements/Spinner/Spinner' import { useCallback, useEffect, useState } from 'react' import BrandCard from './BrandCard' const Brands = () => { const alpha = Array.from(Array(26)).map((e, i) => i + 65) const alphabets = alpha.map((x) => String.fromCharCode(x)) const [isLoading, setIsLoading] = useState(true) const [startWith, setStartWith] = useState(null) const [manufactures, setManufactures] = useState([]) const loadBrand = useCallback(async () => { setIsLoading(true) const name = startWith ? `${startWith}%` : '' const result = await odooApi( 'GET', `/api/v1/manufacture?limit=0&offset=${manufactures.length}&name=${name}` ) setIsLoading(false) setManufactures((manufactures) => [...manufactures, ...result.manufactures]) }, [startWith]) const toggleStartWith = (alphabet) => { setManufactures([]) if (alphabet == startWith) { setStartWith(null) return } setStartWith(alphabet) } useEffect(() => { loadBrand() }, [loadBrand]) if (isLoading) { return (