From 9260537e3f94af296b7c7947964a6e7565cf200c Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 3 Mar 2024 09:59:30 +0100 Subject: [PATCH] chore: apply prettier coding-style to the whole project (#63) --- .editorconfig | 2 + .prettierignore | 2 + package.json | 3 +- .../CalculationDetail.module.css | 42 +-- .../CalculationDetail.stories.tsx | 24 +- src/CalculationDetail/CalculationDetail.tsx | 113 +++--- .../DogmaEngineProvider.stories.tsx | 26 +- .../DogmaEngineProvider.tsx | 25 +- .../EsiCharacterSelection.module.css | 30 +- .../EsiCharacterSelection.stories.tsx | 17 +- .../EsiCharacterSelection.tsx | 28 +- src/EsiProvider/EsiAccessToken.tsx | 8 +- src/EsiProvider/EsiFittings.tsx | 2 +- src/EsiProvider/EsiProvider.stories.tsx | 22 +- src/EsiProvider/EsiProvider.tsx | 110 +++--- src/EsiProvider/EsiSkills.tsx | 3 +- src/EveDataProvider/DataTypes.tsx | 103 +++--- .../EveDataProvider.stories.tsx | 33 +- src/EveDataProvider/EveDataProvider.tsx | 10 +- src/EveShipFitHash/EveShipFitHash.stories.tsx | 19 +- src/EveShipFitHash/EveShipFitHash.tsx | 10 +- src/EveShipFitLink/EveShipFitLink.stories.tsx | 24 +- src/EveShipFitLink/EveShipFitLink.tsx | 12 +- src/FitButtonBar/ClipboardButton.tsx | 59 +-- src/FitButtonBar/FitButtonBar.module.css | 114 +++--- src/FitButtonBar/FitButtonBar.stories.tsx | 26 +- src/FitButtonBar/FitButtonBar.tsx | 14 +- src/FitButtonBar/RenameButton.tsx | 34 +- src/FitButtonBar/SaveButton.tsx | 86 +++-- src/FitButtonBar/ShareButton.tsx | 27 +- src/FormatAsEft/FormatAsEft.stories.tsx | 20 +- src/FormatAsEft/FormatAsEft.tsx | 36 +- src/FormatEftToEsi/FormatEftToEsi.stories.tsx | 16 +- src/FormatEftToEsi/FormatEftToEsi.tsx | 42 +-- .../HardwareListing.module.css | 64 ++-- .../HardwareListing.stories.tsx | 14 +- src/HardwareListing/HardwareListing.tsx | 141 +++++--- src/Helpers/LocalStorage.tsx | 31 +- src/HullListing/HullListing.module.css | 64 ++-- src/HullListing/HullListing.stories.tsx | 29 +- src/HullListing/HullListing.tsx | 190 ++++++---- src/Icon/Icon.stories.tsx | 8 +- src/Icon/Icon.tsx | 6 +- .../LocalFitProvider.stories.tsx | 19 +- src/LocalFitProvider/LocalFitProvider.tsx | 21 +- src/ModalDialog/ModalDialog.module.css | 46 +-- src/ModalDialog/ModalDialog.stories.tsx | 35 +- src/ModalDialog/ModalDialog.tsx | 20 +- src/ShipAttribute/ShipAttribute.stories.tsx | 22 +- src/ShipAttribute/ShipAttribute.tsx | 8 +- src/ShipFit/FitLink.tsx | 42 ++- src/ShipFit/Hull.tsx | 14 +- src/ShipFit/RadialMenu.tsx | 42 ++- src/ShipFit/RingInner.tsx | 40 +- src/ShipFit/RingOuter.tsx | 24 +- src/ShipFit/RingTop.tsx | 18 +- src/ShipFit/ShipFit.module.css | 187 +++++----- src/ShipFit/ShipFit.stories.tsx | 20 +- src/ShipFit/ShipFit.tsx | 162 ++++++--- src/ShipFit/Slot.tsx | 235 ++++++------ .../ShipFitExtended.module.css | 50 +-- .../ShipFitExtended.stories.tsx | 22 +- src/ShipFitExtended/ShipFitExtended.tsx | 114 +++--- .../ShipSnapshotProvider.stories.tsx | 32 +- .../ShipSnapshotProvider.tsx | 172 ++++----- src/ShipSnapshotProvider/index.ts | 8 +- src/ShipStatistics/Category.tsx | 28 +- src/ShipStatistics/RechargeRate.tsx | 108 ++++-- src/ShipStatistics/Resistance.tsx | 15 +- src/ShipStatistics/ShipStatistics.module.css | 145 ++++---- src/ShipStatistics/ShipStatistics.stories.tsx | 22 +- src/ShipStatistics/ShipStatistics.tsx | 341 ++++++++++-------- src/TreeListing/TreeListing.module.css | 42 +-- src/TreeListing/TreeListing.stories.tsx | 29 +- src/TreeListing/TreeListing.tsx | 120 +++--- src/index.ts | 40 +- src/types.d.ts | 2 +- 77 files changed, 2166 insertions(+), 1768 deletions(-) create mode 100644 .editorconfig create mode 100644 .prettierignore diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e53f54d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*] +max_line_length=120 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..0dc0dd2 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +src/EveDataProvider/esf_pb2.js +src/EveDataProvider/protobuf.js diff --git a/package.json b/package.json index 08a4ae0..7c545eb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "build": "rollup -c", "build-storybook": "storybook build", "dev": "storybook dev -p 6006 --no-open", - "lint": "eslint src --ext .js,.tsx --cache" + "lint": "eslint src --ext .js,.tsx --cache && prettier -c src", + "prettier": "prettier -w src" }, "repository": { "type": "git", diff --git a/src/CalculationDetail/CalculationDetail.module.css b/src/CalculationDetail/CalculationDetail.module.css index 17504cb..0c68bc6 100644 --- a/src/CalculationDetail/CalculationDetail.module.css +++ b/src/CalculationDetail/CalculationDetail.module.css @@ -1,55 +1,55 @@ .entry { - cursor: pointer; - display: flex; + cursor: pointer; + display: flex; } .entry > span { - flex: 1; + flex: 1; } .entry > span:first-child { - display: inline-block; - flex: unset; - width: 20px; + display: inline-block; + flex: unset; + width: 20px; } .entry > span:last-child { - display: inline-block; - flex: unset; - width: 60px; + display: inline-block; + flex: unset; + width: 60px; } .entry:hover { - background-color: #cccccc; + background-color: #cccccc; } .header { - cursor: inherit; - font-weight: bold; + cursor: inherit; + font-weight: bold; } .header:hover { - background-color: inherit; + background-color: inherit; } .collapsed { - display: none; + display: none; } .effects { - background-color: #cccccc; - padding: 10px 20px; + background-color: #cccccc; + padding: 10px 20px; } .effect { - display: flex; + display: flex; } .effect > span:nth-child(3) { - flex: 1; + flex: 1; } .effect > span:nth-child(1) { - width: 40px; + width: 40px; } .effect > span:nth-child(2) { - width: 200px; + width: 200px; } .line:nth-child(odd) { - background-color: #f2f2f2; + background-color: #f2f2f2; } diff --git a/src/CalculationDetail/CalculationDetail.stories.tsx b/src/CalculationDetail/CalculationDetail.stories.tsx index cb8ca4d..775d415 100644 --- a/src/CalculationDetail/CalculationDetail.stories.tsx +++ b/src/CalculationDetail/CalculationDetail.stories.tsx @@ -1,24 +1,24 @@ -import type { Decorator, Meta, StoryObj } from '@storybook/react'; +import type { Decorator, Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { fullFit } from '../../.storybook/fits'; +import { fullFit } from "../../.storybook/fits"; -import { DogmaEngineProvider } from '../DogmaEngineProvider'; -import { EsiProvider } from '../EsiProvider'; -import { EveDataProvider } from '../EveDataProvider'; -import { ShipSnapshotProvider } from '../ShipSnapshotProvider'; -import { CalculationDetail } from './'; +import { DogmaEngineProvider } from "../DogmaEngineProvider"; +import { EsiProvider } from "../EsiProvider"; +import { EveDataProvider } from "../EveDataProvider"; +import { ShipSnapshotProvider } from "../ShipSnapshotProvider"; +import { CalculationDetail } from "./"; const meta: Meta = { component: CalculationDetail, - tags: ['autodocs'], - title: 'Component/CalculationDetail', + tags: ["autodocs"], + title: "Component/CalculationDetail", }; export default meta; type Story = StoryObj; -const useShipSnapshotProvider: Decorator<{source: "Ship" | { Item: number }}> = (Story, context) => { +const useShipSnapshotProvider: Decorator<{ source: "Ship" | { Item: number } }> = (Story, context) => { const [skills, setSkills] = React.useState>({}); return ( @@ -32,7 +32,7 @@ const useShipSnapshotProvider: Decorator<{source: "Ship" | { Item: number }}> = ); -} +}; export const Default: Story = { args: { @@ -42,6 +42,6 @@ export const Default: Story = { parameters: { snapshot: { fit: fullFit, - } + }, }, }; diff --git a/src/CalculationDetail/CalculationDetail.tsx b/src/CalculationDetail/CalculationDetail.tsx index add5091..971299f 100644 --- a/src/CalculationDetail/CalculationDetail.tsx +++ b/src/CalculationDetail/CalculationDetail.tsx @@ -2,21 +2,25 @@ import clsx from "clsx"; import React from "react"; import { EveDataContext } from "../EveDataProvider"; -import { ShipSnapshotContext, ShipSnapshotItemAttribute, ShipSnapshotItemAttributeEffect } from "../ShipSnapshotProvider"; +import { + ShipSnapshotContext, + ShipSnapshotItemAttribute, + ShipSnapshotItemAttributeEffect, +} from "../ShipSnapshotProvider"; import styles from "./CalculationDetail.module.css"; import { Icon } from "../Icon"; const EffectOperatorOrder: Record = { - "PreAssign": "=", - "PreMul": "*", - "PreDiv": "/", - "ModAdd": "+", - "ModSub": "-", - "PostMul": "*", - "PostDiv": "/", - "PostPercent": "%", - "PostAssignment": "=", + PreAssign: "=", + PreMul: "*", + PreDiv: "/", + ModAdd: "+", + ModSub: "-", + PostMul: "*", + PostDiv: "/", + PostPercent: "%", + PostAssignment: "=", }; const Effect = (props: { effect: ShipSnapshotItemAttributeEffect }) => { @@ -40,14 +44,21 @@ const Effect = (props: { effect: ShipSnapshotItemAttributeEffect }) => { } } - return
- {EffectOperatorOrder[props.effect.operator]} - {attribute?.value || eveAttribute?.defaultValue}{props.effect.penalty ? " (penalized)" : ""} - {sourceName} - {eveAttribute?.name} -
; -} + return ( +
+ {EffectOperatorOrder[props.effect.operator]} + + {attribute?.value || eveAttribute?.defaultValue} + {props.effect.penalty ? " (penalized)" : ""} + + + {sourceName} - {eveAttribute?.name} + +
+ ); +}; -const CalculationDetailMeta = (props: { attributeId: number, attribute: ShipSnapshotItemAttribute }) => { +const CalculationDetailMeta = (props: { attributeId: number; attribute: ShipSnapshotItemAttribute }) => { const [expanded, setExpanded] = React.useState(false); const eveData = React.useContext(EveDataContext); @@ -63,39 +74,41 @@ const CalculationDetailMeta = (props: { attributeId: number, attribute: ShipSnap return aIndex - bIndex; }); - return
-
setExpanded(!expanded)}> - - - - {eveAttribute?.name} - {props.attribute.value} - {props.attribute.effects.length} -
-
-
- = - {props.attribute.base_value} - base value {props.attributeId < 0 && <>(list of effects might be incomplete)} + return ( +
+
setExpanded(!expanded)}> + + + + {eveAttribute?.name} + {props.attribute.value} + {props.attribute.effects.length} +
+
+
+ = + {props.attribute.base_value} + base value {props.attributeId < 0 && <>(list of effects might be incomplete)} +
+ {sortedEffects.map((effect) => { + index += 1; + return ; + })}
- {sortedEffects.map((effect) => { - index += 1; - return - })}
-
-} + ); +}; /** * Show in detail for each attribute how the value came to be. This includes * the base value, all effects (and their source) and the final value. */ -export const CalculationDetail = (props: {source: "Ship" | { Item: number }}) => { +export const CalculationDetail = (props: { source: "Ship" | { Item: number } }) => { const shipSnapshot = React.useContext(ShipSnapshotContext); let attributes; if (props.source === "Ship") { - attributes = [...shipSnapshot.hull?.attributes.entries() || []]; + attributes = [...(shipSnapshot.hull?.attributes.entries() || [])]; } else if (props.source.Item !== undefined) { const item = shipSnapshot.items?.[props.source.Item]; if (item !== undefined) { @@ -103,15 +116,17 @@ export const CalculationDetail = (props: {source: "Ship" | { Item: number }}) => } } - return
-
- - Attribute - Value - Effects + return ( +
+
+ + Attribute + Value + Effects +
+ {attributes?.map(([attributeId, attribute]) => { + return ; + })}
- {attributes?.map(([attributeId, attribute]) => { - return - })} -
+ ); }; diff --git a/src/DogmaEngineProvider/DogmaEngineProvider.stories.tsx b/src/DogmaEngineProvider/DogmaEngineProvider.stories.tsx index 641f256..fa459a6 100644 --- a/src/DogmaEngineProvider/DogmaEngineProvider.stories.tsx +++ b/src/DogmaEngineProvider/DogmaEngineProvider.stories.tsx @@ -1,15 +1,15 @@ -import type { Meta, StoryObj } from '@storybook/react'; +import type { Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { fullFit } from '../../.storybook/fits'; +import { fullFit } from "../../.storybook/fits"; -import { EveDataProvider } from '../EveDataProvider'; -import { DogmaEngineContext, DogmaEngineProvider } from './'; +import { EveDataProvider } from "../EveDataProvider"; +import { DogmaEngineContext, DogmaEngineProvider } from "./"; const meta: Meta = { component: DogmaEngineProvider, - tags: ['autodocs'], - title: 'Provider/DogmaEngineProvider', + tags: ["autodocs"], + title: "Provider/DogmaEngineProvider", }; export default meta; @@ -18,9 +18,7 @@ type Story = StoryObj; /** Convert an ES6 map to an Object, which JSON can stringify. */ function MapToDict(_key: string, value: unknown) { if (value instanceof Map) { - return Array.from(value.entries()).reduce((obj, [key, item]) => ( - Object.assign(obj, { [key]: item }) - ), {}); + return Array.from(value.entries()).reduce((obj, [key, item]) => Object.assign(obj, { [key]: item }), {}); } return value; @@ -34,18 +32,20 @@ const TestDogmaEngine = () => { return (
- DogmaEngine: loaded
+ DogmaEngine: loaded +
Stats: {JSON.stringify(stats, MapToDict)}
- ) + ); } return (
- DogmaEngine: loading
+ DogmaEngine: loading +
); -} +}; export const Default: Story = { render: () => ( diff --git a/src/DogmaEngineProvider/DogmaEngineProvider.tsx b/src/DogmaEngineProvider/DogmaEngineProvider.tsx index 5b4cf47..68cab09 100644 --- a/src/DogmaEngineProvider/DogmaEngineProvider.tsx +++ b/src/DogmaEngineProvider/DogmaEngineProvider.tsx @@ -1,17 +1,24 @@ import React from "react"; -import { DogmaAttribute, DogmaEffect, TypeDogmaAttribute, TypeDogmaEffect, TypeID, EveDataContext } from "../EveDataProvider"; +import { + DogmaAttribute, + DogmaEffect, + TypeDogmaAttribute, + TypeDogmaEffect, + TypeID, + EveDataContext, +} from "../EveDataProvider"; import type { init, calculate } from "@eveshipfit/dogma-engine"; interface EsfDogmaEngine { - init: typeof init, - calculate: typeof calculate, + init: typeof init; + calculate: typeof calculate; } interface DogmaEngine { - loaded?: boolean, - loadedData?: boolean, - engine?: EsfDogmaEngine, + loaded?: boolean; + loadedData?: boolean; + engine?: EsfDogmaEngine; } export const DogmaEngineContext = React.createContext({}); @@ -86,7 +93,7 @@ export const DogmaEngineProvider = (props: DogmaEngineProps) => { window.get_dogma_effects = undefined; window.get_dogma_effect = undefined; window.get_type_id = undefined; - } + }; }, [eveData]); React.useEffect(() => { @@ -103,7 +110,5 @@ export const DogmaEngineProvider = (props: DogmaEngineProps) => { }); }, []); - return - {props.children} - + return {props.children}; }; diff --git a/src/EsiCharacterSelection/EsiCharacterSelection.module.css b/src/EsiCharacterSelection/EsiCharacterSelection.module.css index ebcdf66..2661be5 100644 --- a/src/EsiCharacterSelection/EsiCharacterSelection.module.css +++ b/src/EsiCharacterSelection/EsiCharacterSelection.module.css @@ -1,26 +1,26 @@ .character { - width: 100%; + width: 100%; } .character > select { - background-color: #1d1d1d; - color: #c5c5c5; - height: 24px; - padding-left: 5px; - width: calc(100% - 20px); + background-color: #1d1d1d; + color: #c5c5c5; + height: 24px; + padding-left: 5px; + width: calc(100% - 20px); } .character > button { - background-color: #1d1d1d; - color: #c5c5c5; - cursor: pointer; - height: 24px; - text-align: center; - width: 20px; + background-color: #1d1d1d; + color: #c5c5c5; + cursor: pointer; + height: 24px; + text-align: center; + width: 20px; } .character > button.noCharacter { - text-align: left; - padding-left: 5px; - width: 100%; + text-align: left; + padding-left: 5px; + width: 100%; } diff --git a/src/EsiCharacterSelection/EsiCharacterSelection.stories.tsx b/src/EsiCharacterSelection/EsiCharacterSelection.stories.tsx index d178b84..d13adf3 100644 --- a/src/EsiCharacterSelection/EsiCharacterSelection.stories.tsx +++ b/src/EsiCharacterSelection/EsiCharacterSelection.stories.tsx @@ -1,14 +1,14 @@ -import type { Decorator, Meta, StoryObj } from '@storybook/react'; +import type { Decorator, Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { EsiProvider } from '../EsiProvider'; -import { EsiCharacterSelection } from './'; -import { EveDataProvider } from '../EveDataProvider'; +import { EsiProvider } from "../EsiProvider"; +import { EsiCharacterSelection } from "./"; +import { EveDataProvider } from "../EveDataProvider"; const meta: Meta = { component: EsiCharacterSelection, - tags: ['autodocs'], - title: 'Component/EsiCharacterSelection', + tags: ["autodocs"], + title: "Component/EsiCharacterSelection", }; export default meta; @@ -22,10 +22,9 @@ const withEsiProvider: Decorator> = (Story) => { ); -} +}; export const Default: Story = { - args: { - }, + args: {}, decorators: [withEsiProvider], }; diff --git a/src/EsiCharacterSelection/EsiCharacterSelection.tsx b/src/EsiCharacterSelection/EsiCharacterSelection.tsx index 25418cb..d97f2d3 100644 --- a/src/EsiCharacterSelection/EsiCharacterSelection.tsx +++ b/src/EsiCharacterSelection/EsiCharacterSelection.tsx @@ -13,14 +13,22 @@ import styles from "./EsiCharacterSelection.module.css"; export const EsiCharacterSelection = () => { const esi = React.useContext(EsiContext); - return
- - -
+ return ( +
+ + +
+ ); }; diff --git a/src/EsiProvider/EsiAccessToken.tsx b/src/EsiProvider/EsiAccessToken.tsx index 67b13df..61cfd0a 100644 --- a/src/EsiProvider/EsiAccessToken.tsx +++ b/src/EsiProvider/EsiAccessToken.tsx @@ -1,8 +1,8 @@ -export async function getAccessToken(refreshToken: string): Promise<{ accessToken?: string, refreshToken?: string }> { +export async function getAccessToken(refreshToken: string): Promise<{ accessToken?: string; refreshToken?: string }> { let response; try { - response = await fetch('https://esi.eveship.fit/', { - method: 'POST', + response = await fetch("https://esi.eveship.fit/", { + method: "POST", body: JSON.stringify({ refresh_token: refreshToken, }), @@ -17,4 +17,4 @@ export async function getAccessToken(refreshToken: string): Promise<{ accessToke const data = await response.json(); return { accessToken: data.access_token, refreshToken: data.refresh_token }; -}; +} diff --git a/src/EsiProvider/EsiFittings.tsx b/src/EsiProvider/EsiFittings.tsx index eec691c..d9ab19a 100644 --- a/src/EsiProvider/EsiFittings.tsx +++ b/src/EsiProvider/EsiFittings.tsx @@ -6,7 +6,7 @@ export async function getCharFittings(characterId: string, accessToken: string): response = await fetch(`https://esi.evetech.net/v1/characters/${characterId}/fittings/`, { headers: { authorization: `Bearer ${accessToken}`, - 'content-type': 'application/json', + "content-type": "application/json", }, }); } catch (e) { diff --git a/src/EsiProvider/EsiProvider.stories.tsx b/src/EsiProvider/EsiProvider.stories.tsx index d536174..4a26463 100644 --- a/src/EsiProvider/EsiProvider.stories.tsx +++ b/src/EsiProvider/EsiProvider.stories.tsx @@ -1,13 +1,13 @@ -import type { Meta, StoryObj } from '@storybook/react'; +import type { Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { EsiContext, EsiProvider } from './'; -import { EveDataProvider } from '../EveDataProvider'; +import { EsiContext, EsiProvider } from "./"; +import { EveDataProvider } from "../EveDataProvider"; const meta: Meta = { component: EsiProvider, - tags: ['autodocs'], - title: 'Provider/EsiProvider', + tags: ["autodocs"], + title: "Provider/EsiProvider", }; export default meta; @@ -19,22 +19,26 @@ const TestEsi = () => { if (!esi.loaded) { return (
- Esi: loading
+ Esi: loading +
); } return (
- Esi: loaded
+ Esi: loaded +
{JSON.stringify(esi, null, 2)}
); -} +}; export const Default: Story = { args: { - setSkills: (skills: Record) => { console.log(skills); } + setSkills: (skills: Record) => { + console.log(skills); + }, }, render: (args) => ( diff --git a/src/EsiProvider/EsiProvider.tsx b/src/EsiProvider/EsiProvider.tsx index 99a1160..f5470c8 100644 --- a/src/EsiProvider/EsiProvider.tsx +++ b/src/EsiProvider/EsiProvider.tsx @@ -68,54 +68,60 @@ export const EsiProvider = (props: EsiProps) => { accessTokens: {}, }); - const [characters, setCharacters] = useLocalStorage>('characters', {}); - const [refreshTokens, setRefreshTokens] = useLocalStorage('refreshTokens', {}); - const [currentCharacter, setCurrentCharacter] = useLocalStorage('currentCharacter', undefined); + const [characters, setCharacters] = useLocalStorage>("characters", {}); + const [refreshTokens, setRefreshTokens] = useLocalStorage("refreshTokens", {}); + const [currentCharacter, setCurrentCharacter] = useLocalStorage("currentCharacter", undefined); - const changeCharacter = React.useCallback((character: string) => { - setCurrentCharacter(character); + const changeCharacter = React.useCallback( + (character: string) => { + setCurrentCharacter(character); - setEsi((oldEsi: Esi) => { - return { - ...oldEsi, - currentCharacter: character, - }; - }); - }, [setCurrentCharacter]); + setEsi((oldEsi: Esi) => { + return { + ...oldEsi, + currentCharacter: character, + }; + }); + }, + [setCurrentCharacter], + ); const login = React.useCallback(() => { - if (typeof window === 'undefined') return; + if (typeof window === "undefined") return; window.location.href = "https://esi.eveship.fit/"; }, []); - const ensureAccessToken = React.useCallback(async (characterId: string): Promise => { - if (esiPrivate.accessTokens[characterId]) { - return esiPrivate.accessTokens[characterId]; - } + const ensureAccessToken = React.useCallback( + async (characterId: string): Promise => { + if (esiPrivate.accessTokens[characterId]) { + return esiPrivate.accessTokens[characterId]; + } - const { accessToken, refreshToken } = await getAccessToken(esiPrivate.refreshTokens[characterId]); - if (accessToken === undefined || refreshToken === undefined) { - console.log('Failed to get access token'); - return undefined; - } + const { accessToken, refreshToken } = await getAccessToken(esiPrivate.refreshTokens[characterId]); + if (accessToken === undefined || refreshToken === undefined) { + console.log("Failed to get access token"); + return undefined; + } - /* New access token; store for later use. */ - setEsiPrivate((oldEsiPrivate: EsiPrivate) => { - return { - ...oldEsiPrivate, - refreshTokens: { - ...oldEsiPrivate.refreshTokens, - [characterId]: refreshToken, - }, - accessToken: { - ...oldEsiPrivate.accessTokens, - [characterId]: accessToken, - }, - }; - }); + /* New access token; store for later use. */ + setEsiPrivate((oldEsiPrivate: EsiPrivate) => { + return { + ...oldEsiPrivate, + refreshTokens: { + ...oldEsiPrivate.refreshTokens, + [characterId]: refreshToken, + }, + accessToken: { + ...oldEsiPrivate.accessTokens, + [characterId]: accessToken, + }, + }; + }); - return accessToken; - }, [esiPrivate.accessTokens, esiPrivate.refreshTokens]); + return accessToken; + }, + [esiPrivate.accessTokens, esiPrivate.refreshTokens], + ); React.useEffect(() => { if (!eveData.loaded) return; @@ -129,8 +135,8 @@ export const EsiProvider = (props: EsiProps) => { return; } - if (characterId === '.all-0' || characterId === '.all-5') { - const level = characterId === '.all-0' ? 0 : 5; + if (characterId === ".all-0" || characterId === ".all-5") { + const level = characterId === ".all-0" ? 0 : 5; const skills: Record = {}; for (const typeId in eveData.typeIDs) { @@ -208,13 +214,13 @@ export const EsiProvider = (props: EsiProps) => { }, [esi.currentCharacter, eveData.loaded]); React.useEffect(() => { - if (typeof window === 'undefined') return; + if (typeof window === "undefined") return; async function loginCharacter(code: string) { let response; try { - response = await fetch('https://esi.eveship.fit/', { - method: 'POST', + response = await fetch("https://esi.eveship.fit/", { + method: "POST", body: JSON.stringify({ code: code, }), @@ -289,11 +295,11 @@ export const EsiProvider = (props: EsiProps) => { async function startup() { const charactersDefault = { - '.all-0': { - name: 'Default character - All Skills L0', + ".all-0": { + name: "Default character - All Skills L0", }, - '.all-5': { - name: 'Default character - All Skills L5', + ".all-5": { + name: "Default character - All Skills L5", }, ...characters, }; @@ -313,13 +319,13 @@ export const EsiProvider = (props: EsiProps) => { /* Check if this was a login request. */ const urlParams = new URLSearchParams(window.location.search); - const code = urlParams.get('code'); + const code = urlParams.get("code"); if (code) { /* Remove the code from the URL. */ window.history.replaceState(null, "", window.location.pathname + window.location.hash); - if (!await loginCharacter(code)) { - console.log('Failed to login character'); + if (!(await loginCharacter(code))) { + console.log("Failed to login character"); } } } @@ -330,7 +336,5 @@ export const EsiProvider = (props: EsiProps) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - return - {props.children} - + return {props.children}; }; diff --git a/src/EsiProvider/EsiSkills.tsx b/src/EsiProvider/EsiSkills.tsx index 0d52407..f385e51 100644 --- a/src/EsiProvider/EsiSkills.tsx +++ b/src/EsiProvider/EsiSkills.tsx @@ -1,11 +1,10 @@ - export async function getSkills(characterId: string, accessToken: string): Promise | undefined> { let response; try { response = await fetch(`https://esi.evetech.net/v4/characters/${characterId}/skills/`, { headers: { authorization: `Bearer ${accessToken}`, - 'content-type': 'application/json', + "content-type": "application/json", }, }); } catch (e) { diff --git a/src/EveDataProvider/DataTypes.tsx b/src/EveDataProvider/DataTypes.tsx index e84993b..eb5073d 100644 --- a/src/EveDataProvider/DataTypes.tsx +++ b/src/EveDataProvider/DataTypes.tsx @@ -1,76 +1,75 @@ - export interface TypeDogmaAttribute { - attributeID: number, - value: number, + attributeID: number; + value: number; } export interface TypeDogmaEffect { - effectID: number, - isDefault: boolean, + effectID: number; + isDefault: boolean; } export interface TypeDogma { - dogmaAttributes: TypeDogmaAttribute[], - dogmaEffects: TypeDogmaEffect[], + dogmaAttributes: TypeDogmaAttribute[]; + dogmaEffects: TypeDogmaEffect[]; } export interface TypeID { - name: string, - groupID: number, - categoryID: number, - published: boolean, - factionID?: number, - marketGroupID?: number, - metaGroupID?: number, - capacity?: number, - mass?: number, - radius?: number, - volume?: number, + name: string; + groupID: number; + categoryID: number; + published: boolean; + factionID?: number; + marketGroupID?: number; + metaGroupID?: number; + capacity?: number; + mass?: number; + radius?: number; + volume?: number; } export interface GroupID { - name: string, - categoryID: number, - published: boolean, + name: string; + categoryID: number; + published: boolean; } export interface MarketGroup { - name: string, - parentGroupID?: number, - iconID?: number, + name: string; + parentGroupID?: number; + iconID?: number; } export interface DogmaAttribute { - name: string - published: boolean, - defaultValue: number, - highIsGood: boolean, - stackable: boolean, + name: string; + published: boolean; + defaultValue: number; + highIsGood: boolean; + stackable: boolean; } export interface DogmaEffect { - name: string, - effectCategory: number, - electronicChance: boolean, - isAssistance: boolean, - isOffensive: boolean, - isWarpSafe: boolean, - propulsionChance: boolean, - rangeChance: boolean, - dischargeAttributeID?: number, - durationAttributeID?: number, - rangeAttributeID?: number, - falloffAttributeID?: number, - trackingSpeedAttributeID?: number, - fittingUsageChanceAttributeID?: number, - resistanceAttributeID?: number, + name: string; + effectCategory: number; + electronicChance: boolean; + isAssistance: boolean; + isOffensive: boolean; + isWarpSafe: boolean; + propulsionChance: boolean; + rangeChance: boolean; + dischargeAttributeID?: number; + durationAttributeID?: number; + rangeAttributeID?: number; + falloffAttributeID?: number; + trackingSpeedAttributeID?: number; + fittingUsageChanceAttributeID?: number; + resistanceAttributeID?: number; modifierInfo: { - domain: number, - func: number, - modifiedAttributeID?: number, - modifyingAttributeID?: number, - operation?: number, - groupID?: number, - skillTypeID?: number, - }[], + domain: number; + func: number; + modifiedAttributeID?: number; + modifyingAttributeID?: number; + operation?: number; + groupID?: number; + skillTypeID?: number; + }[]; } diff --git a/src/EveDataProvider/EveDataProvider.stories.tsx b/src/EveDataProvider/EveDataProvider.stories.tsx index 8737b86..555b364 100644 --- a/src/EveDataProvider/EveDataProvider.stories.tsx +++ b/src/EveDataProvider/EveDataProvider.stories.tsx @@ -1,12 +1,12 @@ -import type { Meta, StoryObj } from '@storybook/react'; +import type { Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { EveDataContext, EveDataProvider } from './'; +import { EveDataContext, EveDataProvider } from "./"; const meta: Meta = { component: EveDataProvider, - tags: ['autodocs'], - title: 'Provider/EveDataProvider', + tags: ["autodocs"], + title: "Provider/EveDataProvider", }; export default meta; @@ -17,18 +17,25 @@ const TestEveData = () => { return (
- TypeIDs: {eveData.typeIDs ? Object.keys(eveData.typeIDs).length : "loading"}
- GroupIDs: {eveData.groupIDs ? Object.keys(eveData.groupIDs).length : "loading"}
- MarketGroups: {eveData.marketGroups ? Object.keys(eveData.marketGroups).length : "loading"}
- TypeDogma: {eveData.typeDogma ? Object.keys(eveData.typeDogma).length : "loading"}
- DogmaEffects: {eveData.dogmaEffects ? Object.keys(eveData.dogmaEffects).length : "loading"}
- DogmaAttributes: {eveData.dogmaAttributes ? Object.keys(eveData.dogmaAttributes).length : "loading"}
- AttributeMapper: {eveData.attributeMapping ? Object.keys(eveData.attributeMapping).length : "loading"}
-
+ TypeIDs: {eveData.typeIDs ? Object.keys(eveData.typeIDs).length : "loading"} +
+ GroupIDs: {eveData.groupIDs ? Object.keys(eveData.groupIDs).length : "loading"} +
+ MarketGroups: {eveData.marketGroups ? Object.keys(eveData.marketGroups).length : "loading"} +
+ TypeDogma: {eveData.typeDogma ? Object.keys(eveData.typeDogma).length : "loading"} +
+ DogmaEffects: {eveData.dogmaEffects ? Object.keys(eveData.dogmaEffects).length : "loading"} +
+ DogmaAttributes: {eveData.dogmaAttributes ? Object.keys(eveData.dogmaAttributes).length : "loading"} +
+ AttributeMapper: {eveData.attributeMapping ? Object.keys(eveData.attributeMapping).length : "loading"} +
+
All loaded: {eveData.loaded ? "yes" : "no"}
); -} +}; export const Default: Story = { render: () => ( diff --git a/src/EveDataProvider/EveDataProvider.tsx b/src/EveDataProvider/EveDataProvider.tsx index 2d35cd5..d5de575 100644 --- a/src/EveDataProvider/EveDataProvider.tsx +++ b/src/EveDataProvider/EveDataProvider.tsx @@ -76,8 +76,8 @@ export const EveDataProvider = (props: DogmaDataProps) => { newDogmaData.loaded = isLoaded(newDogmaData); return newDogmaData; - } - )}); + }); + }); } fetchAndLoadDataFile("typeIDs", esf_pb2.esf.TypeIDs); @@ -102,14 +102,12 @@ export const EveDataProvider = (props: DogmaDataProps) => { const newDogmaData = { ...prevDogmaData, attributeMapping: attributeMapping, - } + }; newDogmaData.loaded = isLoaded(newDogmaData); return newDogmaData; }); }, [dogmaData.dogmaAttributes]); - return - {props.children} - + return {props.children}; }; diff --git a/src/EveShipFitHash/EveShipFitHash.stories.tsx b/src/EveShipFitHash/EveShipFitHash.stories.tsx index c1199fe..cb3b9b1 100644 --- a/src/EveShipFitHash/EveShipFitHash.stories.tsx +++ b/src/EveShipFitHash/EveShipFitHash.stories.tsx @@ -1,32 +1,31 @@ -import type { Decorator, Meta, StoryObj } from '@storybook/react'; +import type { Decorator, Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { hashFit } from '../../.storybook/fits'; +import { hashFit } from "../../.storybook/fits"; -import { EveDataProvider } from '../EveDataProvider'; -import { EveShipFitHash } from './EveShipFitHash'; +import { EveDataProvider } from "../EveDataProvider"; +import { EveShipFitHash } from "./EveShipFitHash"; const meta: Meta = { component: EveShipFitHash, - tags: ['autodocs'], - title: 'Function/EveShipFitHash', + tags: ["autodocs"], + title: "Function/EveShipFitHash", }; -const withEveDataProvider: Decorator<{fitHash: string}> = (Story) => { +const withEveDataProvider: Decorator<{ fitHash: string }> = (Story) => { return ( ); -} - +}; export default meta; type Story = StoryObj; export const Default: Story = { args: { - "fitHash": hashFit, + fitHash: hashFit, }, decorators: [withEveDataProvider], }; diff --git a/src/EveShipFitHash/EveShipFitHash.tsx b/src/EveShipFitHash/EveShipFitHash.tsx index 2108787..af87f45 100644 --- a/src/EveShipFitHash/EveShipFitHash.tsx +++ b/src/EveShipFitHash/EveShipFitHash.tsx @@ -3,16 +3,16 @@ import React from "react"; import { EsiFit } from "../ShipSnapshotProvider"; async function decompress(base64compressedBytes: string): Promise { - const stream = new Blob([Uint8Array.from(atob(base64compressedBytes), c => c.charCodeAt(0))]).stream(); + const stream = new Blob([Uint8Array.from(atob(base64compressedBytes), (c) => c.charCodeAt(0))]).stream(); const decompressedStream = stream.pipeThrough(new DecompressionStream("gzip")); const reader = decompressedStream.getReader(); let result = ""; while (true) { - const {done, value} = await reader.read(); - if (done) break; + const { done, value } = await reader.read(); + if (done) break; - result += String.fromCharCode.apply(null, value); + result += String.fromCharCode.apply(null, value); } return result; @@ -80,5 +80,5 @@ export const EveShipFitHash = (props: EveShipFitHashProps) => { getFit(props.fitHash); }, [props.fitHash]); - return
{JSON.stringify(esiFit, null, 2)}
+ return
{JSON.stringify(esiFit, null, 2)}
; }; diff --git a/src/EveShipFitLink/EveShipFitLink.stories.tsx b/src/EveShipFitLink/EveShipFitLink.stories.tsx index c17de1e..8ac3b81 100644 --- a/src/EveShipFitLink/EveShipFitLink.stories.tsx +++ b/src/EveShipFitLink/EveShipFitLink.stories.tsx @@ -1,17 +1,17 @@ -import type { Decorator, Meta, StoryObj } from '@storybook/react'; +import type { Decorator, Meta, StoryObj } from "@storybook/react"; import React from "react"; -import { fullFit } from '../../.storybook/fits'; +import { fullFit } from "../../.storybook/fits"; -import { EveDataProvider } from '../EveDataProvider'; -import { DogmaEngineProvider } from '../DogmaEngineProvider'; -import { ShipSnapshotProvider } from '../ShipSnapshotProvider'; -import { EveShipFitLink } from './EveShipFitLink'; +import { EveDataProvider } from "../EveDataProvider"; +import { DogmaEngineProvider } from "../DogmaEngineProvider"; +import { ShipSnapshotProvider } from "../ShipSnapshotProvider"; +import { EveShipFitLink } from "./EveShipFitLink"; const meta: Meta = { component: EveShipFitLink, - tags: ['autodocs'], - title: 'Function/EveShipFitLink', + tags: ["autodocs"], + title: "Function/EveShipFitLink", }; const withShipSnapshotProvider: Decorator<{ radius?: number }> = (Story, context) => { @@ -24,20 +24,18 @@ const withShipSnapshotProvider: Decorator<{ radius?: number }> = (Story, context
); -} - +}; export default meta; type Story = StoryObj; export const Default: Story = { - args: { - }, + args: {}, decorators: [withShipSnapshotProvider], parameters: { snapshot: { fit: fullFit, skills: {}, - } + }, }, }; diff --git a/src/EveShipFitLink/EveShipFitLink.tsx b/src/EveShipFitLink/EveShipFitLink.tsx index 18f678c..39988b2 100644 --- a/src/EveShipFitLink/EveShipFitLink.tsx +++ b/src/EveShipFitLink/EveShipFitLink.tsx @@ -9,10 +9,10 @@ async function compress(str: string): Promise { let result = ""; while (true) { - const {done, value} = await reader.read(); - if (done) break; + const { done, value } = await reader.read(); + if (done) break; - result += String.fromCharCode.apply(null, value); + result += String.fromCharCode.apply(null, value); } return btoa(result); @@ -25,7 +25,7 @@ async function encodeEsiFit(esiFit: EsiFit): Promise { result += `${item.flag},${item.type_id},${item.quantity}\n`; } - return "v1:" + await compress(result); + return "v1:" + (await compress(result)); } /** @@ -51,7 +51,7 @@ export function useEveShipFitLink() { }, [shipSnapshot?.loaded, shipSnapshot?.fit]); return fitLink; -}; +} /** * useEveShipFitLink() converts the current fit into a link to https://eveship.fit. @@ -61,5 +61,5 @@ export function useEveShipFitLink() { export const EveShipFitLink = () => { const eveShipFitLink = useEveShipFitLink(); - return
{eveShipFitLink}
+ return
{eveShipFitLink}
; }; diff --git a/src/FitButtonBar/ClipboardButton.tsx b/src/FitButtonBar/ClipboardButton.tsx index 072b7b9..d744c1f 100644 --- a/src/FitButtonBar/ClipboardButton.tsx +++ b/src/FitButtonBar/ClipboardButton.tsx @@ -51,35 +51,42 @@ export const ClipboardButton = () => { setIsPopupOpen(false); }, [eftToEsiFit, shipSnapshot]); - return <> -
setIsPopupOpen(true)} onMouseOut={() => setIsPopupOpen(false)}> -
- {copied ? "In Clipboard" : "Clipboard"} -
-
-
-
setIsPasteOpen(true)}> - Import from Clipboard -
-
copyToClipboard()}> - Copy to Clipboard + return ( + <> +
setIsPopupOpen(true)} + onMouseOut={() => setIsPopupOpen(false)} + > +
{copied ? "In Clipboard" : "Clipboard"}
+
+
+
setIsPasteOpen(true)}> + Import from Clipboard +
+
copyToClipboard()}> + Copy to Clipboard +
-
- setIsPasteOpen(false)} className={styles.paste} title="Import from Clipboard"> -
+ setIsPasteOpen(false)} + className={styles.paste} + title="Import from Clipboard" + >
- Paste your fit here +
Paste your fit here
+
+