mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
fix(shipwrecks): a reversed period is stored in the order the picker shows it, so changing one end keeps the other
A period set as 1950 to 1900 (a link or the voice tool) showed as 1900–1950 but stayed reversed, so changing "From" to 1920 gave 1920 to 1900, shown as 1900–1920: the end the reader did not touch moved.
This commit is contained in:
1 parent
38ba8a3b59
commit
0ac06dad2d
2 files changed
+25
-1
No files matched your search
@@ -29,7 +29,7 @@ function yearParam(value) {
|
||||
/**
|
||||
* Merge a (partial) period request into the current one. `from: null` means
|
||||
* the first year in the data and `to: null` the latest; an invalid year keeps
|
||||
* the current one.
|
||||
* the current one, and a start after the end is stored as the reverse.
|
||||
* @param {{from?: number|string|null, to?: number|string|null}} params
|
||||
* @param {{from: number|null, to: number|null}} current
|
||||
* @returns {{from: number|null, to: number|null}}
|
||||
@@ -44,6 +44,10 @@ export function normalizePeriod(
|
||||
const year = yearParam(params[end]);
|
||||
if (year !== undefined) next[end] = year;
|
||||
}
|
||||
// Stored in the order it is shown, so a later edit to one end (the picker
|
||||
// sends only that end) changes the end the reader picked, not the other.
|
||||
if (Number.isInteger(next.from) && Number.isInteger(next.to))
|
||||
if (next.from > next.to) [next.from, next.to] = [next.to, next.from];
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user