diff --git a/src/components/map/Map.js b/src/components/map/Map.js index a6ce762..4fdd0cf 100644 --- a/src/components/map/Map.js +++ b/src/components/map/Map.js @@ -188,11 +188,29 @@ function Map({ } // Sort so vehicles render below other tokens - function sortMapTokenStates(a, b) { + function sortMapTokenStates(a, b, draggingTokenOptions) { const tokenA = tokensById[a.tokenId]; const tokenB = tokensById[b.tokenId]; if (tokenA && tokenB) { - return tokenB.isVehicle - tokenA.isVehicle; + // If one token is a vehicle and one isn't sort vehicles below + if (tokenB.isVehicle !== tokenA.isVehicle) { + return tokenB.isVehicle - tokenA.isVehicle; + } else if ( + draggingTokenOptions && + draggingTokenOptions.tokenState.id === a.id + ) { + // If dragging token a move above + return 1; + } else if ( + draggingTokenOptions && + draggingTokenOptions.tokenState.id === b.id + ) { + // If dragging token b move above + return -1; + } else { + // Else sort so last modified is on top + return a.lastModified - b.lastModified; + } } else if (tokenA) { return 1; } else if (tokenB) { @@ -205,7 +223,7 @@ function Map({ const mapTokens = mapState && ( {Object.values(mapState.tokens) - .sort(sortMapTokenStates) + .sort((a, b) => sortMapTokenStates(a, b, draggingTokenOptions)) .map((tokenState) => (