-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve ux in 'usedFor'. began refactoring towards feature sliced design
- Loading branch information
1 parent
02e154e
commit 12aaba0
Showing
11 changed files
with
218 additions
and
137 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { CompactItem } from '../../../components/CompactItem'; | ||
import Box from '@mui/material/Box'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import Typography from '@mui/material/Typography'; | ||
import { TItem } from '../../../../types'; | ||
import { useItemContext } from '../../../contexts/itemsContext'; | ||
import { ItemIconAndTitle } from './ItemIconAndTitle'; | ||
|
||
export function CraftsInto(props: { item: TItem }) { | ||
const { item } = props; | ||
const { items } = useItemContext(); | ||
|
||
const usedForItemsArr = item.partOf.map(id => items[id]) | ||
|
||
if (usedForItemsArr.length === 0) return null; | ||
|
||
|
||
return ( | ||
<Box sx={{ width: '500px', paddingTop: '5px' }}> | ||
<Typography variant="h6">Used for</Typography> | ||
{ | ||
usedForItemsArr.length > 4 | ||
? <TiledItems items={usedForItemsArr} /> | ||
: <ListedItems items={usedForItemsArr} /> | ||
} | ||
</Box> | ||
) | ||
} | ||
|
||
function TiledItems({ items }: { items: TItem[] }) { | ||
if (items.length === 0) return null; | ||
|
||
return ( | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap', paddingTop: '5px' }}> | ||
{items.map((item) => ( | ||
<CompactItem key={`used_for_${item.id}`} id={item.id} /> | ||
))} | ||
</Box> | ||
) | ||
} | ||
|
||
function ListedItems({ items }: { items: TItem[] }) { | ||
if (items.length === 0) return null; | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<Box sx={{ paddingTop: '5px' }}> | ||
{items.map((item) => ( | ||
<ItemIconAndTitle | ||
sx={{ | ||
paddingLeft: '30px', | ||
cursor: 'pointer', | ||
'&:hover': { | ||
background: '#2b2b2b' | ||
} | ||
}} | ||
onClick={() => { navigate(`/item/${item.id}`) }} | ||
item={item}/> | ||
))} | ||
</Box> | ||
) | ||
} |
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,66 @@ | ||
|
||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import Avatar from '@mui/material/Avatar'; | ||
import { TreeView } from '@mui/x-tree-view/TreeView'; | ||
import { TreeItem } from '@mui/x-tree-view/TreeItem'; | ||
import { ItemIconAndTitle } from './ItemIconAndTitle'; | ||
import { grey, lightBlue } from '@mui/material/colors'; | ||
import { TItem } from '../../../../types'; | ||
import { useItemContext } from '../../../contexts/itemsContext'; | ||
|
||
|
||
export function ItemDependenciesTree(props: {item: TItem}) { | ||
const { item } = props; | ||
if (item.recipe.length === 0) return null; | ||
return ( | ||
<Box sx={{ width: '500px', paddingTop: '15px'}}> | ||
<Typography variant="h6">Crafting</Typography> | ||
<TreeView sx={{ paddingTop: '10px' }}> | ||
{ | ||
item.recipe.map((craftingId: string) => ( | ||
<ItemDependency key={craftingId} index={item.id} id={craftingId} /> | ||
)) | ||
} | ||
</TreeView> | ||
</Box> | ||
) | ||
} | ||
|
||
|
||
function ItemDependency(props: {id: string; index: string;}) { | ||
const { items } = useItemContext(); | ||
const { id, index } = props; | ||
const item = items[id]; | ||
const newIndex = index + '_' + id; | ||
|
||
if (!item) { | ||
return ( | ||
<TreeItem nodeId={newIndex} label={ | ||
<Box sx={{display:'flex', flexDirection:'row', alignContent: 'center'}}> | ||
<Avatar sx={{ bgcolor: grey[500], marginRight: '10px' }} variant="rounded"> | ||
{id[0]} | ||
</Avatar> | ||
<Typography variant="body2">{id}</Typography> | ||
</Box> | ||
}/> | ||
); | ||
} | ||
return ( | ||
<TreeItem | ||
nodeId={newIndex} | ||
label={ | ||
<Box sx={{display:'flex', flexDirection:'row', alingItems: 'center', justifyContent: 'space-between'}}> | ||
<ItemIconAndTitle item={item} /> | ||
{ item.sourceShort && <Typography variant="body2" sx={{ color: lightBlue[300], lineHeight: '40px' }}>{item.sourceShort}</Typography> } | ||
</Box> | ||
}> | ||
{ | ||
item.recipe.map((id, index) => ( | ||
<ItemDependency key={newIndex + id + '_' + index} index={newIndex} id={id} /> | ||
)) | ||
} | ||
</TreeItem> | ||
) | ||
} | ||
|
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,46 @@ | ||
import Box, { BoxProps } from '@mui/material/Box'; | ||
import { iconFromId } from '../../../icons/icons'; | ||
import Typography from '@mui/material/Typography'; | ||
import { lightBlue } from '@mui/material/colors'; | ||
import { TItem } from '../../../../types'; | ||
import { CraftsInto } from './CraftsInto'; | ||
import { ItemDependenciesTree } from './DependencyTree'; | ||
|
||
interface EvoItemProps extends BoxProps { | ||
item: TItem | ||
} | ||
|
||
export function EvoItem(props: EvoItemProps) { | ||
const { item, sx,...rest } = props; | ||
const { color } = item.rarity; | ||
|
||
return ( | ||
<Box {...rest} sx={{ maxWidth: '600px'}}> | ||
<Box sx={{ display: 'flex', flexDirection: 'row', paddingBottom: '10px' }}> | ||
<img | ||
src={iconFromId(item.icon)} width={64} height={64} | ||
/> | ||
<Box sx={{ paddingLeft: '10px' }}> | ||
<Typography variant="subtitle1" color={color}> | ||
{item.id} | ||
</Typography> | ||
<Typography variant="subtitle2" color={lightBlue[300]}> | ||
{item.restriction} | ||
</Typography> | ||
</Box> | ||
</Box> | ||
<Typography variant="body2">{item.description}</Typography> | ||
<br /> | ||
{item.effects.map((effect, index) => ( | ||
<Typography key={effect + index} variant="body2"> | ||
{effect} | ||
</Typography> | ||
))} | ||
<ItemDependenciesTree item={item} /> | ||
<CraftsInto item={item} /> | ||
</Box> | ||
) | ||
} | ||
|
||
|
||
|
Oops, something went wrong.