Skip to content

Commit d349267

Browse files
committed
still pretty print cmodel
1 parent d65ada7 commit d349267

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/NavBar.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { getQueryStore } from '@/stores/Stores'
2020
import { getBBoxFromCoord, getBBoxPoints } from '@/utils'
2121
import { decodeCoords, encodeCoords } from '@/util/flexPolyline'
2222
import { canCompress, deflateB64url, inflateB64url } from '@/util/urlCompress'
23+
import { customModel2prettyString } from '@/sidebar/CustomModelExamples'
2324

2425
// Minimum number of (initialized) waypoints before we switch from the legible
2526
// `point=lat,lng` format to the compact `fpolyline=` representation. For 1-3
@@ -260,7 +261,13 @@ export default class NavBar {
260261

261262
const customModelStr = await NavBar.parseCustomModel(url)
262263
if (customModelStr) {
263-
Dispatcher.dispatch(new SetCustomModel(customModelStr, true))
264+
// Pretty-print so the editor shows readable JSON (URL form is minified).
265+
// Mirrors QueryStore.getInitialState behaviour for the initial-load case.
266+
let prettyStr = customModelStr
267+
try {
268+
prettyStr = customModel2prettyString(JSON.parse(customModelStr))
269+
} catch {}
270+
Dispatcher.dispatch(new SetCustomModel(prettyStr, true))
264271
Dispatcher.dispatch(new SetCustomModelEnabled(true))
265272
}
266273

test/NavBar.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ describe('NavBar', function () {
292292
await navBar.updateStateFromUrl()
293293

294294
expect(queryStore.state.customModelEnabled).toEqual(true)
295-
expect(queryStore.state.customModelStr).toEqual(cm)
295+
// stored value is pretty-printed, so compare JSON semantically
296+
expect(JSON.parse(queryStore.state.customModelStr)).toEqual(JSON.parse(cm))
296297
})
297298

298299
it('parses legacy custom_model= URL', async () => {
@@ -308,7 +309,7 @@ describe('NavBar', function () {
308309
await navBar.updateStateFromUrl()
309310

310311
expect(queryStore.state.customModelEnabled).toEqual(true)
311-
expect(queryStore.state.customModelStr).toEqual(cm)
312+
expect(JSON.parse(queryStore.state.customModelStr)).toEqual(JSON.parse(cm))
312313
})
313314

314315
it('sets no points when no points are in URL', async () => {

0 commit comments

Comments
 (0)