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

filtered duplicate tweets #306

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions components/TwitterContainer.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import TwitterResultCard from '@components/TwitterResult';
import useFetch from '@hooks/use-fetch';

const Selector = ({ searchStr, resourceType, noRes, noResText }) => {
const [covidConnectResults, loading] = useFetch({ city: searchStr, materialType: resourceType });
const [tweets, setTweets] = useState(covidConnectResults);
useEffect(() => {
const memo = {};
const filteredResults = covidConnectResults.filter(result => {
if(!(result.full_text in memo)) {
memo[result.full_text] = true;
return true;
}
return false;
});

setTweets(filteredResults);
}, [covidConnectResults, loading]);
Comment on lines +7 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const [covidConnectResults, loading] = useFetch({ city: searchStr, materialType: resourceType });
const removeDuplicateTweets = () => {
    const memo = {};
    const filteredResults = covidConnectResults.filter(result => {
        if(!(result.full_text in memo)) {
            memo[result.full_text] = true;
            return true;
        }
        return false;
    });
    return filteredResults;
}
const covidTweetResults = removeDuplicateTweets(covidConnectResults);

return <></>

and here,
covidConnectResults={covidTweetResults}

Instead of having a state and updating it, can we have a the simple filter function before it going to component ?
This is because already while typing, for each letter it renders the component. Having another state inside the component double the render. 🤔

Just my opinion 🤔 Can we do the above ?👆


return (
<div className="mb-2 h-full max-w-3xl mx-auto">
Expand All @@ -17,11 +30,12 @@ const Selector = ({ searchStr, resourceType, noRes, noResText }) => {
<TwitterResultCard
searchStr={searchStr}
loading={loading}
covidConnectResults={covidConnectResults}
covidConnectResults={tweets}
/>
)}
</div>
);
};

export default Selector;