Skip to content

Commit

Permalink
Fix hover cards freezing
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoni7 committed Sep 20, 2024
1 parent 530ba0e commit 92daf1c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/components/HoverCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { styled, Typography, Box } from '@mui/material';
import { db } from '../store/db';
import {
Expand Down Expand Up @@ -45,15 +45,14 @@ interface HoverCardProps {

const HoverCard: React.FC<HoverCardProps> = ({ item, children }) => {
const [hoverData, setHoverData] = useState<any | null>(null);
const [hovered, setHovered] = useState<boolean>(false);

const handleMouseEnter = async () => {
async function getItemData() {
if (!item) {
console.log('No item provided');
return;
}

const itemHash = item.itemHash;
console.log('Hovering over item with itemHash:', itemHash);

try {
let fullData;
Expand Down Expand Up @@ -120,11 +119,11 @@ const HoverCard: React.FC<HoverCardProps> = ({ item, children }) => {
} catch (error) {
console.error('Error fetching item data:', error);
}
};
}

const handleMouseLeave = () => {
setHoverData(null);
};
useEffect(() => {
getItemData().catch(console.error);
}, []);

const renderEnergyCapacity = (capacity: number) => {
return (
Expand Down Expand Up @@ -205,12 +204,12 @@ const HoverCard: React.FC<HoverCardProps> = ({ item, children }) => {

return (
<div
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onMouseOver={() => setHovered(true)}
onMouseOut={() => setHovered(false)}
style={{ position: 'relative' }}
>
{children}
{hoverData && (
{hovered && hoverData && (
<FadeIn duration={160}>
<HoverCardContainer>
{hoverData.type === 'armorMod' || hoverData.type === 'armorStatMod' ? (
Expand Down

0 comments on commit 92daf1c

Please sign in to comment.