Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when Filtering High Impact News in Masonry Layout #164

Open
Saud-Ahmad97 opened this issue Jul 27, 2024 · 2 comments
Open

Error when Filtering High Impact News in Masonry Layout #164

Saud-Ahmad97 opened this issue Jul 27, 2024 · 2 comments
Labels
question Further information is requested

Comments

@Saud-Ahmad97
Copy link

Saud-Ahmad97 commented Jul 27, 2024

Describe the bug
First, thank you for this amazing package. It perfectly meets my requirements.

I am creating a news feed application where news items are displayed in cards. I am using the Masonry layout to handle the different card sizes, as some cards include images while others do not.

The Masonry layout is working well overall, but I have encountered an issue when implementing a filter functionality. The filter allows users to sort news based on their impact levels: high, medium, and low. Currently, there are 3 high-impact news items, and more than 60 items for both medium and low impact.

When switching to display only high-impact news, I encounter the following error:

` const filterByImpactHigh = filteredData?.filter((item) => item?.impact === 'High');
const filterByImpactMedium = filteredData?.filter((item) => item?.impact === 'Medium');
const filterByImpactLow = filteredData?.filter((item) => item?.impact=== 'Low');

const dataToDisplay =
tab === '0'
? filteredData
: tab === '1'
? filterByImpactHigh
: tab === '2'
? filterByImpactMedium
: filterByImpactLow;

`

` <Box sx={{ margin: '1rem 0', direction: 'rtl' }}>
{dataToDisplay?.length > 0 &&
<Masonry
items={dataToDisplay}
columnGutter={10}
columnWidth={250}
overscanBy={1}
render={({ data}: any) => {

        return (
          <>
         {data &&   <NewsCard
            key={data?.id}
            id={data?.id}
            title={data?.title}
            translated_message={data?.translated_message}
            imageUrl={data?.image_paths}
            impact_on_UAE={data?.impact_on_UAE}
            time={data?.timestamp?.$date}
            category={data?.category}
            videoUrl={data?.video_paths}
            channel_name={data?.channel_name}
          />}
          </>
         
        );
      }}
    />
    }
    </Box>`

Actual Behavior
An error occurs when switching to the high-impact filter, preventing the news items from being displayed correctly. while switching to others work fine as long as the there is large set of data

To Reproduce

  1. Implement a Masonry layout for news cards.
  2. Add a filter functionality to sort news by impact levels (high, medium, low).
  3. Populate the feed with 3 high-impact news items and over 60 medium and low impact news items.
  4. Switch to the high-impact filter.

Expected behavior
The Masonry layout should correctly display the 3 high-impact news items without any errors.

Screenshots
Screenshot 2024-07-27 at 10 46 29 AM
Screenshot 2024-07-27 at 11 04 41 AM

  • OS: [macOS]
  • Browser [ chrome,]
@Saud-Ahmad97
Copy link
Author

After looking into the documentation, I was able to resolve the issue successfully.

  <Masonry
        key={tab}
        items={dataToDisplay}
        columnGutter={10}
        columnWidth={250}
          overscanBy={1}
        
         
        />

added a key prop resolved my issue👍

Thank you once again for your excellent work and comprehensive documentation!

@jaredLunde jaredLunde added the question Further information is requested label Jul 27, 2024
@jaredLunde
Copy link
Owner

Awesome! I'm glad the key prop worked for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants