test new virtuoso design for catalogs

This commit is contained in:
plebeius.eth
2023-08-04 21:33:51 +02:00
parent 7311ad027e
commit 25e277c6c3
6 changed files with 1193 additions and 1051 deletions
+20
View File
@@ -0,0 +1,20 @@
import { useMemo, useRef } from "react"
const useFeedRows = (feedWithDescriptionAndRules, columnCount) => {
const rowsRef = useRef([]);
return useMemo(() => {
const rows = [];
for (let i = 0; i < feedWithDescriptionAndRules.length; i += columnCount) {
if (rowsRef.current?.[rows.length] && rowsRef.current[rows.length].length === columnCount) {
rows.push(rowsRef.current[rows.length])
}
else {
rows.push(feedWithDescriptionAndRules.slice(i, i + columnCount))
}
}
rowsRef.current = rows
return rows;
}, [feedWithDescriptionAndRules, columnCount]);
}
export default useFeedRows;
+16
View File
@@ -0,0 +1,16 @@
import { useState, useEffect } from 'react'
export default function useWindowWidth() {
const [windowWidth, setWindowWidth] = useState(window.innerWidth)
useEffect(() => {
function handleResize() {
setWindowWidth(window.innerWidth)
}
window.addEventListener('resize', handleResize)
return () => window.removeEventListener('resize', handleResize)
}, [])
return windowWidth
}