added short view in chache

This commit is contained in:
Daniel Shleifman
2021-05-27 11:42:37 +03:00
parent 6f0e8a642d
commit 19599fc0ae
4 changed files with 103 additions and 50 deletions

View File

@@ -3,7 +3,6 @@ import Button from '@material-ui/core/Button'
import Dialog from '@material-ui/core/Dialog' import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions' import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent' import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle' import DialogTitle from '@material-ui/core/DialogTitle'
import InfoIcon from '@material-ui/icons/Info' import InfoIcon from '@material-ui/icons/Info'
import ListItem from '@material-ui/core/ListItem' import ListItem from '@material-ui/core/ListItem'
@@ -27,7 +26,6 @@ export default function AboutDialog() {
<DialogContent> <DialogContent>
<DialogContent> <DialogContent>
<DialogContentText id='alert-dialog-description'>
<center> <center>
<h2>Thanks to everyone who tested and helped.</h2> <h2>Thanks to everyone who tested and helped.</h2>
</center> </center>
@@ -43,7 +41,6 @@ export default function AboutDialog() {
<br /> <br />
<b>SpAwN_LMG</b> <b>SpAwN_LMG</b>
<br /> <br />
</DialogContentText>
</DialogContent> </DialogContent>
</DialogContent> </DialogContent>

View File

@@ -1,9 +1,5 @@
import { Rect } from 'react-konva' import { Rect } from 'react-konva'
export const boxHeight = 12
export const strokeWidth = 2
export const marginBetweenBlocks = 2
export default function SingleBlock({ export default function SingleBlock({
x, x,
y, y,
@@ -12,6 +8,8 @@ export default function SingleBlock({
inProgress = false, inProgress = false,
isReaderRange = false, isReaderRange = false,
isComplete = false, isComplete = false,
boxHeight,
strokeWidth,
}) { }) {
const strokeColor = isActive const strokeColor = isActive
? '#000' ? '#000'

View File

@@ -7,7 +7,7 @@ import { cacheHost } from 'utils/Hosts'
import { Stage, Layer } from 'react-konva' import { Stage, Layer } from 'react-konva'
import Measure from 'react-measure' import Measure from 'react-measure'
import SingleBlock, { boxHeight, strokeWidth, marginBetweenBlocks } from './SingleBlock' import SingleBlock from './SingleBlock'
export default function DialogCacheInfo({ hash }) { export default function DialogCacheInfo({ hash }) {
const [cache, setCache] = useState({}) const [cache, setCache] = useState({})
@@ -15,14 +15,36 @@ 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 [stageSettings, setStageSettings] = useState({
boxHeight: null,
strokeWidth: null,
marginBetweenBlocks: null,
stageOffset: null,
})
const [isShortView, setIsShortView] = useState(true)
const [isLoading, setIsLoading] = useState(true)
useEffect( const updateStageSettings = (boxHeight, strokeWidth) => {
setStageSettings({
boxHeight,
strokeWidth,
marginBetweenBlocks: strokeWidth,
stageOffset: strokeWidth * 2,
})
}
const { boxHeight, strokeWidth, marginBetweenBlocks, stageOffset } = stageSettings
let activeId = null
useEffect(() => {
// initializing stageSettings
updateStageSettings(24, 4)
return () => {
// this function is required to notify "getCache" when NOT to make state update // this function is required to notify "getCache" when NOT to make state update
() => () => {
componentIsMounted.current = false componentIsMounted.current = false
}, }
[], }, [])
)
useEffect(() => { useEffect(() => {
if (hash) { if (hash) {
@@ -52,16 +74,14 @@ export default function DialogCacheInfo({ hash }) {
const currentPiece = Pieces[i] const currentPiece = Pieces[i]
if (currentPiece) { if (currentPiece) {
if (currentPiece.Completed && currentPiece.Size === currentPiece.Length) newPiece.isComplete = true if (currentPiece.Completed && currentPiece.Size === currentPiece.Length) newPiece.isComplete = true
else newPiece.inProgress = true else {
newPiece.inProgress = true
newPiece.percentage = (currentPiece.Size / currentPiece.Length).toFixed(2) newPiece.percentage = (currentPiece.Size / currentPiece.Length).toFixed(2)
} }
}
Readers.forEach(r => { Readers.forEach(r => {
if (i === r.Reader) { if (i === r.Reader) newPiece.isActive = true
newPiece.isActive = true
return
}
if (i >= r.Start && i <= r.End) newPiece.isReaderRange = true if (i >= r.Start && i <= r.End) newPiece.isReaderRange = true
}) })
@@ -69,11 +89,17 @@ export default function DialogCacheInfo({ hash }) {
} }
setPMap(map) setPMap(map)
setIsLoading(false)
}, [cache]) }, [cache])
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)
const amountOfRows = Math.ceil(pMap.length / piecesInOneRow) + 1 const amountOfBlocksToRenderInShortView =
preloadPiecesAmount === piecesInOneRow
? preloadPiecesAmount - 1
: preloadPiecesAmount + piecesInOneRow - (preloadPiecesAmount % piecesInOneRow) - 1
const amountOfRows = Math.ceil((isShortView ? amountOfBlocksToRenderInShortView : pMap.length) / piecesInOneRow)
return ( return (
<Measure bounds onResize={contentRect => setDimensions(contentRect.bounds)}> <Measure bounds onResize={contentRect => setDimensions(contentRect.bounds)}>
@@ -107,20 +133,56 @@ export default function DialogCacheInfo({ hash }) {
</DialogTitle> </DialogTitle>
<DialogContent> <DialogContent>
{!pMap.length ? ( <button
type='button'
onClick={() => {
if (isShortView) {
updateStageSettings(12, 2)
setIsShortView(false)
} else {
updateStageSettings(24, 4)
setIsShortView(true)
}
setIsLoading(true)
}}
>
updateStageSettings
</button>
{isLoading ? (
'loading' 'loading'
) : ( ) : (
<Stage <Stage
style={{ display: 'flex', justifyContent: 'center' }} style={{ display: 'flex', justifyContent: 'center' }}
offsetX={-3} offset={{ x: -stageOffset, y: -stageOffset }}
width={dimensions.width * 0.9} width={stageOffset + blockSizeWithMargin * piecesInOneRow}
height={amountOfRows * blockSizeWithMargin} height={stageOffset + blockSizeWithMargin * amountOfRows}
> >
<Layer> <Layer>
{pMap.map(({ id, percentage, isComplete, inProgress, isActive, isReaderRange }) => { {pMap.map(({ id, percentage, isComplete, inProgress, isActive, isReaderRange }) => {
const currentRow = Math.floor(id / piecesInOneRow) + 1 const currentRow = Math.floor((isShortView ? id - activeId : id) / piecesInOneRow)
return ( // -------- related only for short view -------
if (isActive) activeId = id
const shouldBeRendered =
isActive || (id - activeId <= amountOfBlocksToRenderInShortView && id - activeId >= 0)
// --------------------------------------------
return isShortView ? (
shouldBeRendered && (
<SingleBlock
key={id}
x={((id - activeId) % piecesInOneRow) * blockSizeWithMargin}
y={currentRow * blockSizeWithMargin}
percentage={percentage}
inProgress={inProgress}
isComplete={isComplete}
isReaderRange={isReaderRange}
isActive={isActive}
boxHeight={boxHeight}
strokeWidth={strokeWidth}
/>
)
) : (
<SingleBlock <SingleBlock
key={id} key={id}
x={(id % piecesInOneRow) * blockSizeWithMargin} x={(id % piecesInOneRow) * blockSizeWithMargin}
@@ -130,6 +192,8 @@ export default function DialogCacheInfo({ hash }) {
isComplete={isComplete} isComplete={isComplete}
isReaderRange={isReaderRange} isReaderRange={isReaderRange}
isActive={isActive} isActive={isActive}
boxHeight={boxHeight}
strokeWidth={strokeWidth}
/> />
) )
})} })}

View File

@@ -135,13 +135,7 @@ export default function SettingsDialog() {
<br /> <br />
<br /> <br />
<InputLabel htmlFor='RetrackersMode'>Retracker mode</InputLabel> <InputLabel htmlFor='RetrackersMode'>Retracker mode</InputLabel>
<Select <Select onChange={inputForm} type='number' native id='RetrackersMode' value={settings.RetrackersMode}>
onChange={inputForm}
type='number'
native='true'
id='RetrackersMode'
value={settings.RetrackersMode}
>
<option value={0}>Don&apos;t add retrackers</option> <option value={0}>Don&apos;t add retrackers</option>
<option value={1}>Add retrackers</option> <option value={1}>Add retrackers</option>
<option value={2}>Remove retrackers</option> <option value={2}>Remove retrackers</option>