-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EMFXD-0000: Refactor global state (#20)
* feat: ♻️ refactorize all global state of the card maker from context to zustand+immer
- Loading branch information
1 parent
3392048
commit 78c74e4
Showing
75 changed files
with
955 additions
and
910 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 was deleted.
Oops, something went wrong.
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
2 changes: 0 additions & 2 deletions
2
...rdGenerator/components/LoadingContent.tsx → src/components/LoadingContent.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,5 +1,3 @@ | ||
import React from "react"; | ||
|
||
import { Center, Spinner } from "@chakra-ui/react"; | ||
|
||
const LoadingContent = () => ( | ||
|
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
73 changes: 73 additions & 0 deletions
73
src/features/FoxtrotCardMaker/components/CardGeneratorForm.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,73 @@ | ||
import { Box, Divider, Flex } from "@chakra-ui/react"; | ||
|
||
import { | ||
DescriptionEditor, | ||
FactionSelection, | ||
ImageUpload, | ||
NameInput, | ||
QualitySelector, | ||
RaritySelector, | ||
StatsInput, | ||
TypeSelector, | ||
} from "."; | ||
|
||
const CardGeneratorForm = () => { | ||
return ( | ||
<Flex direction="column" w={{ base: "100%", md: "auto" }}> | ||
<Box | ||
mt="0" | ||
height="100%" | ||
w="100%" | ||
bg="whiteAlpha.100" | ||
p="20px" | ||
borderRadius={8} | ||
> | ||
<Flex flexDirection="column" justify="space-between" h="100%"> | ||
<Box> | ||
<Flex direction={{ base: "column", lg: "row" }} gap={2}> | ||
<NameInput /> | ||
<StatsInput /> | ||
</Flex> | ||
|
||
<Flex | ||
mt={4} | ||
gap={{ base: 4, md: 0 }} | ||
direction={{ base: "column", lg: "row" }} | ||
> | ||
<Box w={{ base: "100%", lg: "50%" }}> | ||
<DescriptionEditor /> | ||
</Box> | ||
|
||
<Flex | ||
direction={{ base: "row", lg: "column" }} | ||
gap={2} | ||
w={{ base: "100%", lg: "50%" }} | ||
pl={{ base: 0, lg: 6 }} | ||
> | ||
<ImageUpload /> | ||
<TypeSelector /> | ||
</Flex> | ||
</Flex> | ||
|
||
<Flex | ||
gap={4} | ||
mt="10px" | ||
direction="column" | ||
w="100%" | ||
position="relative" | ||
> | ||
<FactionSelection /> | ||
<RaritySelector /> | ||
</Flex> | ||
</Box> | ||
<Flex justify="flex-end" flexDirection="column"> | ||
<Divider mt="14px" /> | ||
<QualitySelector key="main_card_selector" /> | ||
</Flex> | ||
</Flex> | ||
</Box> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default CardGeneratorForm; |
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,63 @@ | ||
import { BoxProps } from "@chakra-ui/react"; | ||
import LoadingContent from "components/LoadingContent"; | ||
import { convertToRaw } from "draft-js"; | ||
import draftToHtml from "draftjs-to-html"; | ||
import { | ||
Attack, | ||
CardWrapper, | ||
Description, | ||
Frame, | ||
Health, | ||
Image, | ||
Mana, | ||
Title, | ||
Type, | ||
} from "features/FoxtrotCardMaker/components/Parts"; | ||
import { | ||
CardType, | ||
WRAPPER_ID, | ||
} from "features/FoxtrotCardMaker/constants/cards"; | ||
import { useCardStore } from "features/FoxtrotCardMaker/stores/CardStore"; | ||
|
||
type Props = BoxProps & { | ||
showFrame?: boolean; | ||
}; | ||
|
||
const CardView = ({ showFrame = true }: Props) => { | ||
const { cardState, loadingState, editorState } = useCardStore(); | ||
return ( | ||
<> | ||
{loadingState.cardContent && <LoadingContent />} | ||
|
||
<CardWrapper id={WRAPPER_ID} opacity={loadingState.cardContent ? 0.4 : 1}> | ||
<Image image={cardState.selectedImage!} id="FXD" /> | ||
|
||
<Description rich> | ||
{editorState | ||
? draftToHtml(convertToRaw(editorState?.getCurrentContent())) | ||
: ""} | ||
</Description> | ||
<Title text={cardState?.name} /> | ||
|
||
{showFrame && ( | ||
<> | ||
<Frame | ||
image={`/images/parts/frames/${cardState.rarity}/${cardState.faction}.png`} | ||
/> | ||
<Mana value={cardState.stats.mana} /> | ||
|
||
{cardState.type?.toLowerCase() !== CardType.TACTIC && ( | ||
<> | ||
<Health value={cardState.stats.health} /> | ||
<Attack value={cardState.stats.attack} /> | ||
</> | ||
)} | ||
</> | ||
)} | ||
<Type value={cardState.type} /> | ||
</CardWrapper> | ||
</> | ||
); | ||
}; | ||
|
||
export default CardView; |
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
2 changes: 0 additions & 2 deletions
2
...rdGenerator/components/DownloadButton.tsx → ...dMaker/components/Form/DownloadButton.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
28 changes: 28 additions & 0 deletions
28
src/features/FoxtrotCardMaker/components/Form/FactionSelection.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,28 @@ | ||
import { Flex, HStack, Radio, RadioGroup } from "@chakra-ui/react"; | ||
import { factionCheckbox } from "features/FoxtrotCardMaker/constants/cards"; | ||
import { useCardStore } from "features/FoxtrotCardMaker/stores/CardStore"; | ||
import { TCardFaction } from "features/FoxtrotCardMaker/types/cards"; | ||
import { capitalize } from "utils"; | ||
|
||
const FactionSelection = () => { | ||
const { cardState, setFaction } = useCardStore(); | ||
|
||
return ( | ||
<Flex direction="column" gap={4} w="100%" position="relative"> | ||
<RadioGroup | ||
onChange={(value) => setFaction(value as TCardFaction)} | ||
value={cardState.faction} | ||
> | ||
<HStack flexWrap="wrap"> | ||
{factionCheckbox.map(({ name, isDisabled }, index: number) => ( | ||
<Radio value={capitalize(name)} key={index} isDisabled={isDisabled}> | ||
{capitalize(name)} | ||
</Radio> | ||
))} | ||
</HStack> | ||
</RadioGroup> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default FactionSelection; |
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
Oops, something went wrong.