This commit is contained in:
Daniel Shleifman
2021-05-27 13:57:16 +03:00
parent feb9b11993
commit e3b276f02b

View File

@@ -15,14 +15,14 @@ export default function DialogCacheInfo({ hash }) {
const timerID = useRef(null) const timerID = useRef(null)
const componentIsMounted = useRef(true) const componentIsMounted = useRef(true)
const [dimensions, setDimensions] = useState({ width: -1, height: -1 }) const [dimensions, setDimensions] = useState({ width: -1, height: -1 })
const [isShortView, setIsShortView] = useState(true)
const [isLoading, setIsLoading] = useState(true)
const [stageSettings, setStageSettings] = useState({ const [stageSettings, setStageSettings] = useState({
boxHeight: null, boxHeight: null,
strokeWidth: null, strokeWidth: null,
marginBetweenBlocks: null, marginBetweenBlocks: null,
stageOffset: null, stageOffset: null,
}) })
const [isShortView, setIsShortView] = useState(true)
const [isLoading, setIsLoading] = useState(true)
const updateStageSettings = (boxHeight, strokeWidth) => { const updateStageSettings = (boxHeight, strokeWidth) => {
setStageSettings({ setStageSettings({
@@ -33,9 +33,6 @@ export default function DialogCacheInfo({ hash }) {
}) })
} }
const { boxHeight, strokeWidth, marginBetweenBlocks, stageOffset } = stageSettings
let activeId = null
useEffect(() => { useEffect(() => {
// initializing stageSettings // initializing stageSettings
updateStageSettings(24, 4) updateStageSettings(24, 4)
@@ -92,6 +89,8 @@ export default function DialogCacheInfo({ hash }) {
setIsLoading(false) setIsLoading(false)
}, [cache]) }, [cache])
const { boxHeight, strokeWidth, marginBetweenBlocks, stageOffset } = stageSettings
const preloadPiecesAmount = Math.round(cache.Capacity / cache.PiecesLength - 1) const preloadPiecesAmount = Math.round(cache.Capacity / cache.PiecesLength - 1)
const blockSizeWithMargin = boxHeight + strokeWidth + marginBetweenBlocks const blockSizeWithMargin = boxHeight + strokeWidth + marginBetweenBlocks
const piecesInOneRow = Math.floor((dimensions.width * 0.9) / blockSizeWithMargin) const piecesInOneRow = Math.floor((dimensions.width * 0.9) / blockSizeWithMargin)
@@ -100,6 +99,7 @@ export default function DialogCacheInfo({ hash }) {
? preloadPiecesAmount - 1 ? preloadPiecesAmount - 1
: preloadPiecesAmount + piecesInOneRow - (preloadPiecesAmount % piecesInOneRow) - 1 : preloadPiecesAmount + piecesInOneRow - (preloadPiecesAmount % piecesInOneRow) - 1
const amountOfRows = Math.ceil((isShortView ? amountOfBlocksToRenderInShortView : pMap.length) / piecesInOneRow) const amountOfRows = Math.ceil((isShortView ? amountOfBlocksToRenderInShortView : pMap.length) / piecesInOneRow)
let activeId = null
return ( return (
<Measure bounds onResize={contentRect => setDimensions(contentRect.bounds)}> <Measure bounds onResize={contentRect => setDimensions(contentRect.bounds)}>