Browse Source

Fix topic list condition for fetching contract data

develop
Apostolos Fanakis 4 years ago
parent
commit
d9f674db98
  1. 24
      packages/concordia-app/src/components/TopicList/index.jsx

24
packages/concordia-app/src/components/TopicList/index.jsx

@ -5,12 +5,12 @@ import React, {
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { List } from 'semantic-ui-react'; import { List } from 'semantic-ui-react';
import { useHistory } from 'react-router';
import AppContext from '../AppContext'; import AppContext from '../AppContext';
import TopicListRow from './TopicListRow'; import TopicListRow from './TopicListRow';
import { PLACEHOLDER_TYPE_TOPIC } from '../../constants/PlaceholderTypes'; import { PLACEHOLDER_TYPE_TOPIC } from '../../constants/PlaceholderTypes';
import Placeholder from '../Placeholder'; import Placeholder from '../Placeholder';
import './styles.css'; import './styles.css';
import { useHistory } from 'react-router';
const TopicList = (props) => { const TopicList = (props) => {
const { topicIds } = props; const { topicIds } = props;
@ -22,11 +22,26 @@ const TopicList = (props) => {
useEffect(() => { useEffect(() => {
// TODO: is the drizzleStatus check necessary? // TODO: is the drizzleStatus check necessary?
if (drizzleStatus.initialized && !drizzleStatus.failed && getTopicCallHashes.length === 0) { if (drizzleStatus.initialized && !drizzleStatus.failed) {
setGetTopicCallHashes(topicIds.map((topicId) => ({ const newTopicPosted = topicIds
.some((topicId) => !getTopicCallHashes
.map((getTopicCallHash) => getTopicCallHash.id)
.includes(topicId));
if (newTopicPosted) {
setGetTopicCallHashes(topicIds.map((topicId) => {
const foundGetTopicCallHash = getTopicCallHashes.find((getTopicCallHash) => getTopicCallHash.id === topicId);
if (foundGetTopicCallHash !== undefined) {
return ({ ...foundGetTopicCallHash });
}
return ({
id: topicId, id: topicId,
hash: getTopic.cacheCall(topicId), hash: getTopic.cacheCall(topicId),
}))); });
}));
}
} }
}, [drizzleStatus.failed, drizzleStatus.initialized, getTopic, getTopicCallHashes, topicIds]); }, [drizzleStatus.failed, drizzleStatus.initialized, getTopic, getTopicCallHashes, topicIds]);
@ -45,6 +60,7 @@ const TopicList = (props) => {
timestamp: getTopicResults[getTopicHash.hash].value[2] * 1000, timestamp: getTopicResults[getTopicHash.hash].value[2] * 1000,
numberOfReplies: getTopicResults[getTopicHash.hash].value[3].length, numberOfReplies: getTopicResults[getTopicHash.hash].value[3].length,
}; };
return ( return (
<List.Item key={topicId} className="list-item" name={topicId} onClick={() => handleTopicClick(topicId)}> <List.Item key={topicId} className="list-item" name={topicId} onClick={() => handleTopicClick(topicId)}>
<TopicListRow <TopicListRow

Loading…
Cancel
Save