From cee69c9a3125706acf53247ce9e1f4c185e71ff0 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Wed, 23 Jul 2025 08:46:35 +0200 Subject: [PATCH] refactor: remove SocketContext and related dependencies from OrdersTab and ProfilePage components for improved performance and code clarity --- src/components/CartDropdown.js | 1 - src/components/ProductList.js | 2 -- src/components/profile/OrdersTab.js | 12 +----------- src/contexts/SocketContext.js | 7 ------- src/pages/ProfilePage.js | 12 +++++------- 5 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 src/contexts/SocketContext.js diff --git a/src/components/CartDropdown.js b/src/components/CartDropdown.js index 54829ee..8e26f68 100644 --- a/src/components/CartDropdown.js +++ b/src/components/CartDropdown.js @@ -74,7 +74,6 @@ class CartDropdown extends Component { {cartItems.map((item) => ( diff --git a/src/components/ProductList.js b/src/components/ProductList.js index 88be347..663af24 100644 --- a/src/components/ProductList.js +++ b/src/components/ProductList.js @@ -471,8 +471,6 @@ class ProductList extends Component { floweringWeeks={product.floweringWeeks} versandklasse={product.versandklasse} weight={product.weight} - socket={this.props.socket} - socketB={this.props.socketB} pictureList={product.pictureList} availableSupplier={product.availableSupplier} komponenten={product.komponenten} diff --git a/src/components/profile/OrdersTab.js b/src/components/profile/OrdersTab.js index beaf88f..d8088c9 100644 --- a/src/components/profile/OrdersTab.js +++ b/src/components/profile/OrdersTab.js @@ -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 { withI18n } from "../../i18n/withTranslation.js"; import { @@ -23,7 +23,6 @@ import { } from "@mui/material"; import SearchIcon from "@mui/icons-material/Search"; import CancelIcon from "@mui/icons-material/Cancel"; -import SocketContext from "../../contexts/SocketContext.js"; import OrderDetailsDialog from "./OrderDetailsDialog.js"; // Constants @@ -81,7 +80,6 @@ const OrdersTab = ({ orderIdFromHash, t }) => { const [orderToCancel, setOrderToCancel] = useState(null); const [isCancelling, setIsCancelling] = useState(false); - const {socket} = useContext(SocketContext); const navigate = useNavigate(); const handleViewDetails = useCallback( @@ -116,14 +114,6 @@ const OrdersTab = ({ orderIdFromHash, t }) => { 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(() => { if (orderIdFromHash && orders.length > 0) { handleViewDetails(orderIdFromHash); diff --git a/src/contexts/SocketContext.js b/src/contexts/SocketContext.js deleted file mode 100644 index 673679e..0000000 --- a/src/contexts/SocketContext.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/src/pages/ProfilePage.js b/src/pages/ProfilePage.js index 22aaf34..03baa97 100644 --- a/src/pages/ProfilePage.js +++ b/src/pages/ProfilePage.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useContext } from 'react'; +import React, { useState, useEffect } from 'react'; import { Container, Paper, @@ -10,7 +10,6 @@ import { } from '@mui/material'; import { useLocation, useNavigate, Navigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import SocketContext from '../contexts/SocketContext.js'; // Import extracted components import OrdersTab from '../components/profile/OrdersTab.js'; @@ -19,7 +18,7 @@ import CartTab from '../components/profile/CartTab.js'; import LoginComponent from '../components/LoginComponent.js'; // Functional Profile Page Component -const ProfilePage = (props) => { +const ProfilePage = () => { const location = useLocation(); const navigate = useNavigate(); const { t } = useTranslation(); @@ -211,7 +210,7 @@ const ProfilePage = (props) => { } if (showLogin) { - return ; + return ; } if (loading) { @@ -284,7 +283,7 @@ const ProfilePage = (props) => { {tabValue === 0 && } {tabValue === 1 && } - {tabValue === 2 && } + {tabValue === 2 && } @@ -294,8 +293,7 @@ const ProfilePage = (props) => { // Wrap with socket context const ProfilePageWithSocket = (props) => { - const {socket,socketB} = useContext(SocketContext); - return ; + return ; }; export default ProfilePageWithSocket; \ No newline at end of file