-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reworked all providers, so they are more well defined in th…
…eir actions This basically touches every file in this repository; so while at it, also reworked how the storybooks work (you can now select different fits to test with), and did a bunch of cleanup where I saw it. There should be no functional difference, just mostly providers (and hooks) that are named differently.
- Loading branch information
Showing
113 changed files
with
3,093 additions
and
2,605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import { StoryFn } from "@storybook/react"; | ||
|
||
import { ModalDialogAnchor } from "@/components/ModalDialog"; | ||
import { EveDataProvider } from "@/providers/EveDataProvider"; | ||
import { DogmaEngineProvider } from "@/providers/DogmaEngineProvider"; | ||
import { CurrentFitProvider, EsfFit, useCurrentFit } from "@/providers/CurrentFitProvider"; | ||
import { LocalFitsProvider } from "@/providers/LocalFitsProvider"; | ||
import { DefaultCharactersProvider, EsiCharactersProvider } from "@/providers/Characters"; | ||
import { CurrentCharacterProvider } from "@/providers/CurrentCharacterProvider"; | ||
import { StatisticsProvider } from "@/providers/StatisticsProvider"; | ||
import { FitManagerProvider } from "@/providers/FitManagerProvider"; | ||
|
||
export const withDecoratorFull = (Story: StoryFn) => ( | ||
<EveDataProvider> | ||
<DogmaEngineProvider> | ||
<CurrentFitProvider> | ||
<LocalFitsProvider> | ||
<DefaultCharactersProvider> | ||
<EsiCharactersProvider> | ||
<CurrentCharacterProvider> | ||
<StatisticsProvider> | ||
<FitManagerProvider> | ||
<ModalDialogAnchor /> | ||
<Story /> | ||
</FitManagerProvider> | ||
</StatisticsProvider> | ||
</CurrentCharacterProvider> | ||
</EsiCharactersProvider> | ||
</DefaultCharactersProvider> | ||
</LocalFitsProvider> | ||
</CurrentFitProvider> | ||
</DogmaEngineProvider> | ||
</EveDataProvider> | ||
); | ||
|
||
export const useFitSelection = (fit: EsfFit | null) => { | ||
const currentFit = useCurrentFit(); | ||
const setFit = currentFit.setFit; | ||
|
||
React.useEffect(() => { | ||
setFit(fit); | ||
}, [setFit, fit]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 18 additions & 30 deletions
48
src/components/CalculationDetail/CalculationDetail.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
import type { Decorator, Meta, StoryObj } from "@storybook/react"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
import { fullFit } from "../../../.storybook/fits"; | ||
import { fitArgType } from "../../../.storybook/fits"; | ||
import { useFitSelection, withDecoratorFull } from "../../../.storybook/helpers"; | ||
|
||
import { EsfFit } from "@/providers/CurrentFitProvider"; | ||
|
||
import { DogmaEngineProvider } from "@/providers/DogmaEngineProvider"; | ||
import { EsiProvider } from "@/providers/EsiProvider"; | ||
import { EveDataProvider } from "@/providers/EveDataProvider"; | ||
import { ShipSnapshotProvider } from "@/providers/ShipSnapshotProvider"; | ||
import { CalculationDetail } from "./"; | ||
|
||
const meta: Meta<typeof CalculationDetail> = { | ||
type StoryProps = React.ComponentProps<typeof CalculationDetail> & { fit: EsfFit | null }; | ||
|
||
const meta: Meta<StoryProps> = { | ||
component: CalculationDetail, | ||
tags: ["autodocs"], | ||
title: "Component/CalculationDetail", | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof CalculationDetail>; | ||
|
||
const useShipSnapshotProvider: Decorator<{ | ||
source: "Ship" | "Char" | "Structure" | "Target" | { Item?: number; Cargo?: number }; | ||
}> = (Story, context) => { | ||
return ( | ||
<EveDataProvider> | ||
<DogmaEngineProvider> | ||
<ShipSnapshotProvider {...context.parameters.snapshot}> | ||
<EsiProvider> | ||
<Story {...context.args} /> | ||
</EsiProvider> | ||
</ShipSnapshotProvider> | ||
</DogmaEngineProvider> | ||
</EveDataProvider> | ||
); | ||
}; | ||
type Story = StoryObj<StoryProps>; | ||
|
||
export const Default: Story = { | ||
argTypes: { | ||
fit: fitArgType, | ||
}, | ||
args: { | ||
fit: null, | ||
source: "Ship", | ||
}, | ||
decorators: [useShipSnapshotProvider], | ||
parameters: { | ||
snapshot: { | ||
initialFit: fullFit, | ||
}, | ||
decorators: [withDecoratorFull], | ||
render: ({ fit, ...args }) => { | ||
useFitSelection(fit); | ||
|
||
return <CalculationDetail {...args} />; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
30 changes: 30 additions & 0 deletions
30
src/components/CharacterSelection/CharacterSelection.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
import { EveDataProvider } from "@/providers/EveDataProvider"; | ||
import { DefaultCharactersProvider, EsiCharactersProvider } from "@/providers/Characters"; | ||
import { CurrentCharacterProvider } from "@/providers/CurrentCharacterProvider"; | ||
|
||
import { CharacterSelection } from "./"; | ||
|
||
const meta: Meta<typeof CharacterSelection> = { | ||
component: CharacterSelection, | ||
tags: ["autodocs"], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof CharacterSelection>; | ||
|
||
export const Default: Story = { | ||
render: () => ( | ||
<EveDataProvider> | ||
<DefaultCharactersProvider> | ||
<EsiCharactersProvider> | ||
<CurrentCharacterProvider> | ||
<CharacterSelection /> | ||
</CurrentCharacterProvider> | ||
</EsiCharactersProvider> | ||
</DefaultCharactersProvider> | ||
</EveDataProvider> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react"; | ||
|
||
import { useCharacters, useEsiCharacters } from "@/providers/Characters"; | ||
import { useCurrentCharacter } from "@/providers/CurrentCharacterProvider"; | ||
|
||
import styles from "./CharacterSelection.module.css"; | ||
|
||
/** | ||
* Character selection for EsiProvider. | ||
* | ||
* It shows both a dropdown for all the characters that the EsiProvider knows, | ||
* and a button to add another character. | ||
*/ | ||
export const CharacterSelection = () => { | ||
const characters = useCharacters(); | ||
const currentCharacter = useCurrentCharacter(); | ||
const esiCharactersProvider = useEsiCharacters(); | ||
|
||
const isExpired = currentCharacter.character?.expired ?? false; | ||
|
||
return ( | ||
<div className={styles.character}> | ||
<select onChange={(e) => currentCharacter.setCharacterId(e.target.value)} value={currentCharacter.characterId}> | ||
{Object.entries(characters) | ||
.sort() | ||
.map(([id, name]) => { | ||
return ( | ||
<option key={id} value={id}> | ||
{name.name} {name.expired ? "(access expired)" : ""} | ||
</option> | ||
); | ||
})} | ||
</select> | ||
{isExpired && ( | ||
<button onClick={esiCharactersProvider.refresh} title="Refresh access"> | ||
R | ||
</button> | ||
)} | ||
{!isExpired && ( | ||
<button onClick={esiCharactersProvider.login} title="Add another character"> | ||
+ | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CharacterSelection } from "./CharacterSelection"; |
Oops, something went wrong.