refactor: remove SocketContext and related dependencies from OrdersTab and ProfilePage components for improved performance and code clarity
This commit is contained in:
@@ -74,7 +74,6 @@ class CartDropdown extends Component {
|
|||||||
{cartItems.map((item) => (
|
{cartItems.map((item) => (
|
||||||
<CartItem
|
<CartItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
socket={this.props.socket}
|
|
||||||
item={item}
|
item={item}
|
||||||
id={item.id}
|
id={item.id}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -471,8 +471,6 @@ class ProductList extends Component {
|
|||||||
floweringWeeks={product.floweringWeeks}
|
floweringWeeks={product.floweringWeeks}
|
||||||
versandklasse={product.versandklasse}
|
versandklasse={product.versandklasse}
|
||||||
weight={product.weight}
|
weight={product.weight}
|
||||||
socket={this.props.socket}
|
|
||||||
socketB={this.props.socketB}
|
|
||||||
pictureList={product.pictureList}
|
pictureList={product.pictureList}
|
||||||
availableSupplier={product.availableSupplier}
|
availableSupplier={product.availableSupplier}
|
||||||
komponenten={product.komponenten}
|
komponenten={product.komponenten}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useContext, useCallback } from "react";
|
import React, { useState, useEffect, useCallback } from "react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { withI18n } from "../../i18n/withTranslation.js";
|
import { withI18n } from "../../i18n/withTranslation.js";
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
import CancelIcon from "@mui/icons-material/Cancel";
|
import CancelIcon from "@mui/icons-material/Cancel";
|
||||||
import SocketContext from "../../contexts/SocketContext.js";
|
|
||||||
import OrderDetailsDialog from "./OrderDetailsDialog.js";
|
import OrderDetailsDialog from "./OrderDetailsDialog.js";
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
@@ -81,7 +80,6 @@ const OrdersTab = ({ orderIdFromHash, t }) => {
|
|||||||
const [orderToCancel, setOrderToCancel] = useState(null);
|
const [orderToCancel, setOrderToCancel] = useState(null);
|
||||||
const [isCancelling, setIsCancelling] = useState(false);
|
const [isCancelling, setIsCancelling] = useState(false);
|
||||||
|
|
||||||
const {socket} = useContext(SocketContext);
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleViewDetails = useCallback(
|
const handleViewDetails = useCallback(
|
||||||
@@ -116,14 +114,6 @@ const OrdersTab = ({ orderIdFromHash, t }) => {
|
|||||||
fetchOrders();
|
fetchOrders();
|
||||||
}, [fetchOrders]);
|
}, [fetchOrders]);
|
||||||
|
|
||||||
// Monitor socket connection changes
|
|
||||||
useEffect(() => {
|
|
||||||
if (socket && socket.connected && orders.length === 0) {
|
|
||||||
// Socket just connected and we don't have orders yet, fetch them
|
|
||||||
fetchOrders();
|
|
||||||
}
|
|
||||||
}, [socket, socket?.connected, orders.length, fetchOrders]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (orderIdFromHash && orders.length > 0) {
|
if (orderIdFromHash && orders.length > 0) {
|
||||||
handleViewDetails(orderIdFromHash);
|
handleViewDetails(orderIdFromHash);
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
// Create a new context for Socket.IO
|
|
||||||
const SocketContext = React.createContext(null);
|
|
||||||
|
|
||||||
export const SocketConsumer = SocketContext.Consumer;
|
|
||||||
export default SocketContext;
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useContext } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Paper,
|
Paper,
|
||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { useLocation, useNavigate, Navigate } from 'react-router-dom';
|
import { useLocation, useNavigate, Navigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import SocketContext from '../contexts/SocketContext.js';
|
|
||||||
|
|
||||||
// Import extracted components
|
// Import extracted components
|
||||||
import OrdersTab from '../components/profile/OrdersTab.js';
|
import OrdersTab from '../components/profile/OrdersTab.js';
|
||||||
@@ -19,7 +18,7 @@ import CartTab from '../components/profile/CartTab.js';
|
|||||||
import LoginComponent from '../components/LoginComponent.js';
|
import LoginComponent from '../components/LoginComponent.js';
|
||||||
|
|
||||||
// Functional Profile Page Component
|
// Functional Profile Page Component
|
||||||
const ProfilePage = (props) => {
|
const ProfilePage = () => {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -211,7 +210,7 @@ const ProfilePage = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (showLogin) {
|
if (showLogin) {
|
||||||
return <LoginComponent open={showLogin} handleClose={handleLoginClose} location={location} socket={props.socket} />;
|
return <LoginComponent open={showLogin} handleClose={handleLoginClose} location={location}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
@@ -284,7 +283,7 @@ const ProfilePage = (props) => {
|
|||||||
|
|
||||||
{tabValue === 0 && <CartTab onOrderSuccess={handleGoToOrders} paymentCompletion={paymentCompletion} onClearPaymentCompletion={handleClearPaymentCompletion} />}
|
{tabValue === 0 && <CartTab onOrderSuccess={handleGoToOrders} paymentCompletion={paymentCompletion} onClearPaymentCompletion={handleClearPaymentCompletion} />}
|
||||||
{tabValue === 1 && <OrdersTab orderIdFromHash={orderIdFromHash} />}
|
{tabValue === 1 && <OrdersTab orderIdFromHash={orderIdFromHash} />}
|
||||||
{tabValue === 2 && <SettingsTab socket={props.socket} />}
|
{tabValue === 2 && <SettingsTab/>}
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
@@ -294,8 +293,7 @@ const ProfilePage = (props) => {
|
|||||||
|
|
||||||
// Wrap with socket context
|
// Wrap with socket context
|
||||||
const ProfilePageWithSocket = (props) => {
|
const ProfilePageWithSocket = (props) => {
|
||||||
const {socket,socketB} = useContext(SocketContext);
|
return <ProfilePage {...props}/>;
|
||||||
return <ProfilePage {...props} socket={socket} socketB={socketB} />;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ProfilePageWithSocket;
|
export default ProfilePageWithSocket;
|
||||||
Reference in New Issue
Block a user