Added sorting to notes
This commit is contained in:
parent
f5aec514f8
commit
8873e59205
@ -208,7 +208,7 @@ function Map({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort so vehicles render below other tokens
|
// Sort so vehicles render below other tokens
|
||||||
function sortMapTokenStates(a, b, draggingTokenOptions) {
|
function sortMapTokenStates(a, b, tokenDraggingOptions) {
|
||||||
const tokenA = tokensById[a.tokenId];
|
const tokenA = tokensById[a.tokenId];
|
||||||
const tokenB = tokensById[b.tokenId];
|
const tokenB = tokensById[b.tokenId];
|
||||||
if (tokenA && tokenB) {
|
if (tokenA && tokenB) {
|
||||||
@ -218,16 +218,16 @@ function Map({
|
|||||||
const bWeight = getMapTokenCategoryWeight(tokenB.category);
|
const bWeight = getMapTokenCategoryWeight(tokenB.category);
|
||||||
return bWeight - aWeight;
|
return bWeight - aWeight;
|
||||||
} else if (
|
} else if (
|
||||||
draggingTokenOptions &&
|
tokenDraggingOptions &&
|
||||||
draggingTokenOptions.dragging &&
|
tokenDraggingOptions.dragging &&
|
||||||
draggingTokenOptions.tokenState.id === a.id
|
tokenDraggingOptions.tokenState.id === a.id
|
||||||
) {
|
) {
|
||||||
// If dragging token a move above
|
// If dragging token a move above
|
||||||
return 1;
|
return 1;
|
||||||
} else if (
|
} else if (
|
||||||
draggingTokenOptions &&
|
tokenDraggingOptions &&
|
||||||
draggingTokenOptions.dragging &&
|
tokenDraggingOptions.dragging &&
|
||||||
draggingTokenOptions.tokenState.id === b.id
|
tokenDraggingOptions.tokenState.id === b.id
|
||||||
) {
|
) {
|
||||||
// If dragging token b move above
|
// If dragging token b move above
|
||||||
return -1;
|
return -1;
|
||||||
@ -362,6 +362,27 @@ function Map({
|
|||||||
setIsNoteMenuOpen(true);
|
setIsNoteMenuOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortNotes(a, b, noteDraggingOptions) {
|
||||||
|
if (
|
||||||
|
noteDraggingOptions &&
|
||||||
|
noteDraggingOptions.dragging &&
|
||||||
|
noteDraggingOptions.noteId === a.id
|
||||||
|
) {
|
||||||
|
// If dragging token `a` move above
|
||||||
|
return 1;
|
||||||
|
} else if (
|
||||||
|
noteDraggingOptions &&
|
||||||
|
noteDraggingOptions.dragging &&
|
||||||
|
noteDraggingOptions.noteId === b.id
|
||||||
|
) {
|
||||||
|
// If dragging token `b` move above
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
// Else sort so last modified is on top
|
||||||
|
return a.lastModified - b.lastModified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const mapNotes = (
|
const mapNotes = (
|
||||||
<MapNotes
|
<MapNotes
|
||||||
map={map}
|
map={map}
|
||||||
@ -370,8 +391,13 @@ function Map({
|
|||||||
selectedToolSettings={settings[selectedToolId]}
|
selectedToolSettings={settings[selectedToolId]}
|
||||||
onNoteAdd={onMapNoteChange}
|
onNoteAdd={onMapNoteChange}
|
||||||
onNoteChange={onMapNoteChange}
|
onNoteChange={onMapNoteChange}
|
||||||
// TODO: Sort by last modified
|
notes={
|
||||||
notes={mapState ? Object.values(mapState.notes) : []}
|
mapState
|
||||||
|
? Object.values(mapState.notes).sort((a, b) =>
|
||||||
|
sortNotes(a, b, noteDraggingOptions)
|
||||||
|
)
|
||||||
|
: []
|
||||||
|
}
|
||||||
onNoteMenuOpen={handleNoteMenuOpen}
|
onNoteMenuOpen={handleNoteMenuOpen}
|
||||||
draggable={selectedToolId === "note" || selectedToolId === "pan"}
|
draggable={selectedToolId === "note" || selectedToolId === "pan"}
|
||||||
onNoteDragStart={(e, noteId) =>
|
onNoteDragStart={(e, noteId) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user