Skip to content

Commit

Permalink
feat: Enhance UI and functionality in deck and product components
Browse files Browse the repository at this point in the history
- Implemented advanced styling for SelectDeckList component, including modern button styling, improved typography, and icon enhancements.
- Added responsive pagination to the ProductGrid component using Material-UIs Pagination component.
- Updated the CartProvider to fix an infinite loop issue and optimized context value updates.
- Refactored and enhanced the updateExistingCardInUserCollection function to ensure synchronization with CardInCollection model and users collection data.
- Cleaned and optimized various React components for better performance and readability.
  • Loading branch information
reedoooo committed Dec 8, 2023
1 parent 00b410d commit a053a56
Show file tree
Hide file tree
Showing 45 changed files with 1,521 additions and 2,660 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const App = () => {
.catch((error) => console.error('Error fetching data:', error))
.finally(() => setIsPageLoading(false));
}
}, [userId, fetchAllCollectionsForUser, fetchAllDecksForUser, fetchUserCart]);
}, [userId, fetchAllCollectionsForUser, fetchAllDecksForUser]);

useEffect(() => {
// Check if loading takes more than 45 seconds
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/actionButtons/CardActionButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const CardActionButtons = ({
switch (context) {
case 'Collection':
if (action === 'add') {
addOneToCollection(card);
addOneToCollection(card, selectedCollection);
} else if (action === 'removeOne') {
removeOneFromCollection(card);
}
Expand Down
187 changes: 187 additions & 0 deletions src/components/cards/CarouselCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import React, { useContext, useEffect, useRef, useState } from 'react';
import SwipeableViews from 'react-swipeable-views';
import {
Box,
Button,
Container,
Grid,
MobileStepper,
Typography,
} from '@mui/material';
import { KeyboardArrowLeft, KeyboardArrowRight } from '@mui/icons-material';
import { useCollectionStore } from '../../context/CollectionContext/CollectionContext';
import { useMode } from '../../context/hooks/colormode';
import { makeStyles, styled } from '@mui/styles';
import { ModalContext } from '../../context/ModalContext/ModalContext';
import GenericCard from './GenericCard';
import {
MainContainer2,
MainContainer,
} from '../../pages/pageStyles/StyledComponents';
import { AspectRatio } from '@mui/joy';
import { debounce } from 'lodash';
import CardDetailsContainer from '../../containers/CardDetailsContainer';
const useStyles = makeStyles((theme) => ({
cardDetails: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
}));

const CarouselCard = ({ card }) => {
const { theme } = useMode();
const classes = useStyles();
const { openModalWithCard } = useContext(ModalContext); // Assuming ModalContext is imported
const cardRef = useRef(null);
const chartRef = useRef(null);
const [chartDimensions, setChartDimensions] = useState({
width: 0,
height: 0,
});
const HEIGHT_TO_WIDTH_RATIO = 1; // Define the ratio here

const handleClick = () => {
openModalWithCard(card);
};

useEffect(() => {
const handleResize = debounce(() => {
if (chartRef.current) {
const width = chartRef.current.offsetWidth;
const height = width * HEIGHT_TO_WIDTH_RATIO;
setChartDimensions({ width, height });
}
}, 100);

window.addEventListener('resize', handleResize);
handleResize();

return () => {
window.removeEventListener('resize', handleResize);
handleResize.cancel();
};
}, []);
return (
<MainContainer2>
<Grid
container
spacing={2}
sx={{
justifyContent: 'space-between',
}}
>
<Grid item xs={4} md={4}>
<GenericCard
card={card}
onClick={() => handleClick()}
context={'Collection'}
ref={cardRef}
/>
</Grid>
{/* Top section for card details */}
<Grid
container
item
xs={8}
md={8}
alignItems="center"
justifyContent="center"
>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
padding: theme.spacing(2),
}}
>
<Grid item xs={12}>
<Box
sx={{
padding: theme.spacing(2),
width: '100%',
border: `1px solid ${theme.palette.background.quaternary}`,
borderRadius: theme.shape.borderRadius,
}}
>
<Typography variant="h6" color={theme.palette.success.main}>
{card?.name}
</Typography>
{/* <CardDetailsContainer
card={card}
className={classes.cardDetails}
/> */}
{/* <Typography variant="subtitle2" color={'white'}>
Price: ${card?.latestPrice?.num || card?.price || 0}
</Typography>
<Typography variant="subtitle2" color={'white'}>
Quantity: {card?.quantity}
</Typography> */}
</Box>
<Box
sx={{
padding: theme.spacing(2),
width: '100%',
border: `1px solid ${theme.palette.background.quaternary}`,
borderRadius: theme.shape.borderRadius,
}}
>
{/* <CardDetailsContainer
card={card}
className={classes.cardDetails}
/> */}
<Typography variant="subtitle2" color={'white'}>
Price: ${card?.latestPrice?.num || card?.price || 0}
</Typography>
<Typography variant="subtitle2" color={'white'}>
Quantity: {card?.quantity}
</Typography>
</Box>
</Grid>

{/* Bottom section for chart */}
<Grid item xs={12}>
<AspectRatio ratio="1/1">
<Container
ref={chartRef}
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
padding: theme.spacing(2),
background: theme.palette.background.dark,
}}
>
<Box
ref={chartRef}
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
background: '#111',
}}
>
{/* Chart component goes here */}
</Box>
</Container>
</AspectRatio>
</Grid>
</Box>
</Grid>
</Grid>
</MainContainer2>
);
};

export default CarouselCard;
7 changes: 6 additions & 1 deletion src/components/cards/GenericCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ const GenericCard = React.forwardRef((props, ref) => {
const name = card?.name;

const imgUrl = card?.card_images?.[0]?.image_url || placeholderImage;
const price = `Price: ${card?.card_prices?.[0]?.tcgplayer_price || 'N/A'}`;
const price = `Price: ${
card?.latestPrice?.num ||
card?.price ||
card?.card_prices?.[0]?.tcgplayer_price ||
'N/A'
}`;
const quantity = card?.quantity || 0;
let cartQuantity = 0;

Expand Down
3 changes: 0 additions & 3 deletions src/components/chart/ChartTooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const useStyles = makeStyles((theme) => ({

const ChartTooltip = ({ point, lastData, hoveredData, latestData }) => {
const classes = useStyles();

if (!point) return null;

// Formatting the date just once to be used in multiple places
const formattedTime = hoveredData
? new Date(hoveredData.x).toLocaleString()
: new Date((latestData || lastData).x).toLocaleString();
Expand Down
5 changes: 2 additions & 3 deletions src/components/chart/LinearChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,15 @@ const LinearChart = ({
tickPadding: 10,
tickSize: 10,
},
pointSize: 8,
pointSize: 10,
pointBorderWidth: 2,
pointBorderColor: theme.palette.primary.main,
pointColor: theme.palette.success.light,
colors: theme.palette.primaryDark.main,
lineWidth: 3,
curve: 'monotoneX',
useMesh: true,
theme: theme.chart,
// onMouseMove: (point) => setIsZoomed(point ? true : false),
// onMouseLeave: () => setIsZoomed(false),
onMouseMove: handleMouseMove,
onMouseLeave: handleMouseLeave,
onClick: () => setIsZoomed(!isZoomed),
Expand Down
52 changes: 37 additions & 15 deletions src/components/chart/PortfolioChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ import LinearChart from './LinearChart';
import { useChartContext } from '../../context/ChartContext/ChartContext';
import ErrorBoundary from '../../context/ErrorBoundary';
import { useCollectionStore } from '../../context/CollectionContext/CollectionContext';
import { useCombinedContext } from '../../context/CombinedContext/CombinedProvider';
import debounce from 'lodash/debounce';
import {
convertDataForNivo2,
getUniqueValidData,
groupAndAverageData,
} from '../reusable/chartUtils';
import { getFilteredData2 } from '../../context/CollectionContext/helpers';

const ChartPaper = styled(Paper)(({ theme }) => ({
borderRadius: theme.shape.borderRadius,
Expand All @@ -28,6 +23,17 @@ const ChartPaper = styled(Paper)(({ theme }) => ({
margin: theme.spacing(2, 0),
}));

const ResponsiveSquare = styled(Box)(({ theme }) => ({
width: '100%',
paddingTop: '100%',
backgroundColor: theme.palette.background.paper,
borderRadius: theme.shape.borderRadius,
boxShadow: theme.shadows[5],
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}));

function handleThresholdUpdate(lastUpdateTime, setLastUpdateTime) {
const currentTime = new Date().getTime();
if (!lastUpdateTime || currentTime - lastUpdateTime >= 600000) {
Expand All @@ -37,16 +43,20 @@ function handleThresholdUpdate(lastUpdateTime, setLastUpdateTime) {
}
return lastUpdateTime;
}
const getFilteredData2 = (collection, timeRange) => {
if (!collection) {
console.error('Invalid input: selectedCollection should not be null');
return [];
}
return getUniqueValidData(collection?.chartData?.allXYValues || []);
};

const PortfolioChart = () => {
const theme = useTheme();
const { latestData, setLatestData, timeRange } = useChartContext();
const {
latestData,
setLatestData,
timeRange,
groupAndAverageData,
convertDataForNivo2,
// getUniqueValidData,
getTickValues,
getFilteredData,
formatDateToString,
} = useChartContext();
const [lastUpdateTime, setLastUpdateTime] = useState(null);
const chartContainerRef = useRef(null);
const [chartDimensions, setChartDimensions] = useState({
Expand All @@ -61,10 +71,22 @@ const PortfolioChart = () => {
);

const filteredChartData2 = useMemo(
() => getFilteredData2(selectedCollection, timeRange), // Adjust to filter data based on timeRange
() => getFilteredData2(selectedCollection, timeRange),
[selectedCollection, timeRange]
);

if (filteredChartData2?.length < 5) {
return (
<Container maxWidth="lg" /* ... existing styles */>
<ErrorBoundary>
<ResponsiveSquare>
<div>Not enough data points</div>
</ResponsiveSquare>
</ErrorBoundary>
</Container>
);
}

if (!filteredChartData2 || filteredChartData2?.length === 0) {
console.warn(
'Invalid input: filteredChartData2 should not be null or empty'
Expand Down
Loading

0 comments on commit a053a56

Please sign in to comment.