Refactor socket context usage in CategoryBox, SearchBar, and Home components for improved clarity and consistency in data fetching.

This commit is contained in:
seb
2025-07-03 05:55:36 +02:00
parent 245f5067ed
commit e4d077e402
3 changed files with 12 additions and 12 deletions

View File

@@ -151,16 +151,16 @@ const Home = () => {
const [rootCategories, setRootCategories] = useState(() =>
initializeCategories()
);
const {socket} = useContext(SocketContext);
const context = useContext(SocketContext);
useEffect(() => {
// Only fetch from socket if we don't already have categories and we're in browser
if (
rootCategories.length === 0 &&
socket &&
context && context.socket && context.socket.connected &&
typeof window !== "undefined"
) {
socket.emit("categoryList", { categoryId: 209 }, (response) => {
context.socket.emit("categoryList", { categoryId: 209 }, (response) => {
if (response && response.categoryTree) {
// Store in cache
try {
@@ -176,7 +176,7 @@ const Home = () => {
}
});
}
}, [socket, rootCategories.length]);
}, [context, context?.socket?.connected, rootCategories.length]);
// Filter categories (excluding specific IDs)
const filteredCategories = rootCategories.filter(