From 8857aba53fc7fad797fc8520f9e0084b2a1a59c3 Mon Sep 17 00:00:00 2001 From: Cmdr McDonald Date: Mon, 21 Nov 2016 10:06:14 +0000 Subject: [PATCH] Use query parameters rather than long path --- package.json | 4 ++-- src/app/Coriolis.jsx | 3 +++ src/app/components/ComparisonTable.jsx | 3 ++- src/app/components/Modification.jsx | 6 ++++-- src/app/pages/OutfittingPage.jsx | 2 +- src/app/shipyard/Serializer.js | 3 ++- src/app/utils/UrlGenerators.js | 13 ++++++++----- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index ae7bf2a2..8be08e93 100644 --- a/package.json +++ b/package.json @@ -84,13 +84,13 @@ "dependencies": { "babel-polyfill": "*", "classnames": "^2.2.0", - "browserify-zlib": "ipfs/coriolis-data", + "browserify-zlib": "ipfs/browserify-zlib", "coriolis-data": "EDCD/coriolis-data", "d3": "3.5.16", "fbemitter": "^2.0.0", "lodash": "^4.15.0", "lz-string": "^1.4.4", - "react-number-editor": "^4.0.2", + "react-number-editor": "Athanasius/react-number-editor.git#miggy", "react": "^15.0.1", "react-dom": "^15.0.1", "superagent": "^1.4.0" diff --git a/src/app/Coriolis.jsx b/src/app/Coriolis.jsx index 3c39a94f..a3e70f02 100644 --- a/src/app/Coriolis.jsx +++ b/src/app/Coriolis.jsx @@ -68,7 +68,10 @@ export default class Coriolis extends React.Component { }; Router('', (r) => this._setPage(ShipyardPage, r)); + Router('/import?', (r) => this._importBuild(r)); Router('/import/:data', (r) => this._importBuild(r)); + Router('/outfit/?', (r) => this._setPage(OutfittingPage, r)); + Router('/outfit/:ship/?', (r) => this._setPage(OutfittingPage, r)); Router('/outfit/:ship/:code?', (r) => this._setPage(OutfittingPage, r)); Router('/compare/:name?', (r) => this._setPage(ComparisonPage, r)); Router('/comparison/:code', (r) => this._setPage(ComparisonPage, r)); diff --git a/src/app/components/ComparisonTable.jsx b/src/app/components/ComparisonTable.jsx index ca99d307..3f831a3a 100644 --- a/src/app/components/ComparisonTable.jsx +++ b/src/app/components/ComparisonTable.jsx @@ -2,6 +2,7 @@ import React from 'react'; import TranslatedComponent from './TranslatedComponent'; import Link from './Link'; import cn from 'classnames'; +import { outfitURL } from '../utils/UrlGenerators'; import { SizeMap } from '../shipyard/Constants'; @@ -71,7 +72,7 @@ export default class ComparisonTable extends TranslatedComponent { * @return {React.Component} Table row */ _buildRow(build, facets, formats, units) { - let url = `/outfit/${build.id}/${build.toString()}?bn=${build.buildName}`; + let url = outfitURL(build.id, build.toString(), build.buildName) let cells = [ {build.name}, {build.buildName} diff --git a/src/app/components/Modification.jsx b/src/app/components/Modification.jsx index c2b90939..6a1464d4 100644 --- a/src/app/components/Modification.jsx +++ b/src/app/components/Modification.jsx @@ -29,12 +29,14 @@ export default class Modification extends TranslatedComponent { /** * Update modification given a value. - * @param {Number} value The value to set + * @param {Number} value The value to set. This comes in as a string and must be stored in state as a string, + * because it needs to allow illegal 'numbers' ('-', '1.', etc) when the user is typing + * in a value by hand */ _updateValue(value) { const name = this.props.name; - let scaledValue = Math.floor(Number(value) * 100); + let scaledValue = Math.round(Number(value) * 100); // Limit to +1000% / -100% if (scaledValue > 100000) { scaledValue = 100000; diff --git a/src/app/pages/OutfittingPage.jsx b/src/app/pages/OutfittingPage.jsx index 6c97fa5c..e93a5eb9 100644 --- a/src/app/pages/OutfittingPage.jsx +++ b/src/app/pages/OutfittingPage.jsx @@ -294,7 +294,7 @@ export default class OutfittingPage extends Page {

{ship.name}

- + diff --git a/src/app/shipyard/Serializer.js b/src/app/shipyard/Serializer.js index 58f849d5..aa7515c2 100644 --- a/src/app/shipyard/Serializer.js +++ b/src/app/shipyard/Serializer.js @@ -4,6 +4,7 @@ import Ship from './Ship'; import * as ModuleUtils from './ModuleUtils'; import * as Utils from '../utils/UtilityFunctions'; import LZString from 'lz-string'; +import { outfitURL } from '../utils/UrlGenerators'; const STANDARD = ['powerPlant', 'thrusters', 'frameShiftDrive', 'lifeSupport', 'powerDistributor', 'sensors', 'fuelTank']; @@ -84,7 +85,7 @@ export function toDetailedBuild(buildName, ship) { ship: ship.name, references: [{ name: 'Coriolis.io', - url: `https://coriolis.edcd.io/outfit/${ship.id}/${code}?bn=${encodeURIComponent(buildName)}`, + url: 'https://coriolis.edcd.io' + outfitURL(ship.id, code, buildName), code, shipId: ship.id }], diff --git a/src/app/utils/UrlGenerators.js b/src/app/utils/UrlGenerators.js index 75182f44..827cc04e 100644 --- a/src/app/utils/UrlGenerators.js +++ b/src/app/utils/UrlGenerators.js @@ -6,15 +6,18 @@ * @return {String} URL */ export function outfitURL(shipId, code, buildName) { - let parts = ['/outfit/', shipId]; + let path = '/outfit/' + shipId; + + let sepChar = '?'; if (code) { - parts.push('/', code); + path = path + sepChar + 'code=' + encodeURIComponent(code); + sepChar = '&'; } if (buildName) { - parts.push('?bn=', encodeURIComponent(buildName)); + path = path + sepChar + 'bn=' + encodeURIComponent(buildName); } - return parts.join(''); -} + return path; +}