refactor: remove socket context dependencies and streamline socket handling in components for improved performance and readability
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import React, { useState, useEffect, useContext } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import Paper from '@mui/material/Paper';
|
||||
import { Link } from 'react-router-dom';
|
||||
import SocketContext from '../contexts/SocketContext.js';
|
||||
|
||||
|
||||
// @note SwashingtonCP font is now loaded globally via index.css
|
||||
|
||||
@@ -22,7 +22,7 @@ const CategoryBox = ({
|
||||
const [imageUrl, setImageUrl] = useState(null);
|
||||
const [imageError, setImageError] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const context = useContext(SocketContext);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
let objectUrl = null;
|
||||
@@ -60,11 +60,10 @@ const CategoryBox = ({
|
||||
return;
|
||||
}
|
||||
|
||||
// If socket is available and connected, fetch the image
|
||||
if (context && context.socket /*&& context.socket.connected*/ && id && !isLoading) {
|
||||
if (id && !isLoading) {
|
||||
setIsLoading(true);
|
||||
|
||||
context.socket.emit('getCategoryPic', { categoryId: id }, (response) => {
|
||||
|
||||
window.socketManager.emit('getCategoryPic', { categoryId: id }, (response) => {
|
||||
setIsLoading(false);
|
||||
|
||||
if (response.success) {
|
||||
@@ -119,7 +118,7 @@ const CategoryBox = ({
|
||||
URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
};
|
||||
}, [context, context?.socket?.connected, id, isLoading]);
|
||||
}, [id, isLoading]);
|
||||
|
||||
return (
|
||||
<Paper
|
||||
|
||||
Reference in New Issue
Block a user