Skip to content

Commit

Permalink
Allow SLEF import of multiple builds via URL
Browse files Browse the repository at this point in the history
  • Loading branch information
felixlinker committed Oct 24, 2020
1 parent bded793 commit 804466f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
33 changes: 23 additions & 10 deletions src/app/Coriolis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,30 @@ export default class Coriolis extends React.Component {
const json = JSON.parse(data);
console.info('Ship import data: ');
console.info(json);
let ship;
if (json && json[0] && json[0].data) {
ship = JournalUtils.shipFromLoadoutJSON(json[0].data);
} else if (json && json.modules) {
ship = CompanionApiUtils.shipFromJson(json);
} else if (json && json.Modules) {
ship = JournalUtils.shipFromLoadoutJSON(json);
let ship, importString;
if (json) {
if (json.length && json[0].data) { // SLEF
if (json.length > 1) { // Multiple builds, open modal
importString = data;
} else { // Single build, import directly
ship = JournalUtils.shipFromLoadoutJSON(json[0].data);
}
} else { // not SLEF
if (json.modules) {
ship = CompanionApiUtils.shipFromJson(json);
} else if (json.Modules) {
ship = JournalUtils.shipFromLoadoutJSON(json);
}
}
}
if (ship) {
r.params.ship = ship.id;
r.params.code = ship.toString();
this._setPage(OutfittingPage, r);
} else if (importString) {
this._setPage(ShipyardPage, r);
this._showModal(<ModalImport importString={data}/>);
}
r.params.ship = ship.id;
r.params.code = ship.toString();
this._setPage(OutfittingPage, r);
} catch (err) {
this._onError('Failed to import ship', r.path, 0, 0, err);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/ModalImport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default class ModalImport extends TranslatedComponent {


static propTypes = {
importString: PropTypes.string, // Optional: Default data for import modal
builds: PropTypes.object, // Optional: Import object
};

Expand All @@ -107,7 +108,7 @@ export default class ModalImport extends TranslatedComponent {
shipDiscount: null,
moduleDiscount: null,
errorMsg: null,
importString: null,
importString: props.importString || null,
importValid: false,
insurance: null
};
Expand Down

0 comments on commit 804466f

Please sign in to comment.