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

Fix: useEffect logic #743

Merged
merged 7 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
23 changes: 10 additions & 13 deletions apps/moderation/src/components/content-card/content-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
} = props;

const [entryData, setEntryData] = React.useState<any>(null);
const [profileState, profileActions] = useProfile({
const [profile, profileActions] = useProfile({
onError: error => {
props.logger.error('[content-card.tsx]: useProfile err %j', error.error || '');
},
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
});

const [reporterProfileState, reporterProfileActions] = useProfile({
const [reporterProfile, reporterProfileActions] = useProfile({
onError: error => {
props.logger.error('[content-card.tsx]: useProfile err %j', error.error || '');
},
ipfsService: props.sdkModules.commons.ipfsService,
profileService: props.sdkModules.profiles.profileService,
});

const [moderatorProfileState, moderatorProfileActions] = useProfile({
const [moderatorProfile, moderatorProfileActions] = useProfile({
onError: error => {
props.logger.error('[content-card.tsx]: useProfile err %j', error.error || '');
},
Expand All @@ -81,11 +81,8 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
}
if (contentType === 'profile') {
profileActions.getProfileData({ ethAddress: entryId });
if (profileState) {
setEntryData(profileState);
}
}
}, [entryId, profileState]);
}, [entryId]);

React.useEffect(() => {
if (reporter) {
Expand All @@ -105,7 +102,7 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
<Content
isPending={isPending}
locale={locale}
entryData={entryData}
entryData={contentType === 'profile' ? profile : entryData}
showExplanationsLabel={showExplanationsLabel}
hideExplanationsLabel={hideExplanationsLabel}
determinationLabel={determinationLabel}
Expand All @@ -119,16 +116,16 @@ const ContentCard: React.FC<Omit<IContentProps, 'entryData'>> = props => {
entryId={entryId}
reasons={reasons}
reporter={reporter}
reporterAvatar={reporterProfileState.avatar}
reporterName={reporterProfileState.name}
reporterENSName={reporterProfileState.userName}
reporterAvatar={reporterProfile.avatar}
reporterName={reporterProfile.name}
reporterENSName={reporterProfile.userName}
otherReporters={otherReporters}
reportedOnLabel={reportedOnLabel}
reportedDateTime={reportedDateTime}
moderatorDecision={moderatorDecision}
moderator={moderator}
moderatorName={moderatorProfileState.name}
moderatorENSName={moderatorProfileState.userName}
moderatorName={moderatorProfile.name}
moderatorENSName={moderatorProfile.userName}
moderatedByLabel={moderatedByLabel}
moderatedOnLabel={moderatedOnLabel}
evaluationDateTime={evaluationDateTime}
Expand Down
7 changes: 1 addition & 6 deletions ui/design/src/components/VirtualList/card-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,9 @@ const CardRenderer = (props: IRenderItemProps) => {
{!shouldLoadData && <EntryLoadingPlaceholder height={averageItemHeight} />}
{itemData &&
shouldLoadData &&
!itemData.delisted &&
!itemData.reported &&
React.cloneElement(itemCard, { itemId, itemData })}
{itemData &&
shouldLoadData &&
!itemData.delisted &&
itemData.reported &&
itemCardAlt(itemData)}
{itemData && shouldLoadData && itemData.reported && itemCardAlt(itemData)}
josenriagu marked this conversation as resolved.
Show resolved Hide resolved

{afterEntities.map((entityObj, idx) => {
return entityObj.getComponent({
Expand Down
24 changes: 17 additions & 7 deletions ui/hooks/src/use-posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const usePosts = (props: UsePostsProps): [PostsState, PostsActions] => {
.map(entry => {
newIds.push(entry._id);
// check if entry has quote and id of such quote is not yet in the list
if (entry.quotes.length > 0 && newQuoteIds.indexOf(entry.quotes[0]._id) === -1) {
if (entry.quotes?.length > 0 && newQuoteIds.indexOf(entry.quotes[0]._id) === -1) {
newQuoteIds.push(entry.quotes[0]._id);
}
return mapEntry(entry, ipfsGateway, logger);
Expand Down Expand Up @@ -227,12 +227,22 @@ const usePosts = (props: UsePostsProps): [PostsState, PostsActions] => {
};
}

posts[res.contentId] = {
...target,
delisted: res.delisted,
reported: res.reported,
quote: quote,
};
if (res.delisted) {
const index = newIds.indexOf(res.contentId);
if (index > -1) {
// remove the entry id from newIds
newIds.splice(index, 1);
}
// remove the entry from posts object
delete posts[res.contentId];
} else {
posts[res.contentId] = {
...target,
delisted: res.delisted,
josenriagu marked this conversation as resolved.
Show resolved Hide resolved
reported: res.reported,
quote: quote,
};
}
});
}

Expand Down