feat: import of ESI JSON fits from clipboard (#52)

This commit is contained in:
Patric Stout
2023-12-22 20:08:09 +01:00
committed by GitHub
parent ac6806f4db
commit 60f1125cba

View File

@@ -3,12 +3,12 @@ import React from "react";
import { LocalFitContext } from "../LocalFitProvider";
import { ModalDialog } from "../ModalDialog";
import { ShipSnapshotContext } from "../ShipSnapshotProvider";
import styles from "./FitButtonBar.module.css";
import { EsiFit, ShipSnapshotContext } from "../ShipSnapshotProvider";
import { useFormatAsEft } from "../FormatAsEft";
import { useFormatEftToEsi } from "../FormatEftToEsi";
import styles from "./FitButtonBar.module.css";
const SaveButton = () => {
const shipSnapshot = React.useContext(ShipSnapshotContext);
const localFit = React.useContext(LocalFitContext);
@@ -92,10 +92,15 @@ const ClipboardButton = () => {
const textArea = textAreaRef.current;
if (textArea === null) return;
const eft = textArea.value;
if (eft === "") return;
const fitString = textArea.value;
if (fitString === "") return;
const fit = eftToEsiFit(eft);
let fit: EsiFit | undefined;
if (fitString.startsWith("{")) {
fit = JSON.parse(fitString);
} else {
fit = eftToEsiFit(fitString);
}
if (fit === undefined) return;
shipSnapshot.changeFit(fit);