From c5838a2873473440ba9b1bea740b714ae1fb2485 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 19 Nov 2022 11:13:02 +0700 Subject: brand with infinite scroll and fix product card style --- src/pages/shop/brands.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/pages/shop/brands.js (limited to 'src/pages') diff --git a/src/pages/shop/brands.js b/src/pages/shop/brands.js new file mode 100644 index 00000000..f39839af --- /dev/null +++ b/src/pages/shop/brands.js @@ -0,0 +1,54 @@ +import { LazyLoadImage } from "react-lazy-load-image-component"; +import Header from "../../components/Header"; +import apiOdoo from "../../helpers/apiOdoo"; +import "react-lazy-load-image-component/src/effects/blur.css"; +import Link from "next/link"; +import { createSlug } from "../../helpers/slug"; +import InfiniteScroll from "react-infinite-scroll-component"; +import { useState } from "react"; +import Spinner from "../../components/Spinner"; + +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 getMoreManufactures = async () => { + const result = await apiOdoo('GET', `/api/v1/manufacture?limit=31&offset=${manufactures.length}`); + if (manufactures.length + 30 >= result.manufacture_total) setHasMoreManufacture(false); + setManufactures((manufactures) => [...manufactures, ...result.manufactures]); + }; + return ( + <> +
+
+

Semua Brand di Indoteknik

+ + + + } + > + {manufactures?.map((manufacture, index) => ( + manufacture.name ? ( + + {manufacture.logo ? ( + + ) : manufacture.name} + + ) : '' + ))} + +
+ + ) +} \ No newline at end of file -- cgit v1.2.3