Skip to content

Commit

Permalink
fix(senate): fix unable to add comments (#1151)
Browse files Browse the repository at this point in the history
  • Loading branch information
OggyKUN authored Apr 15, 2024
1 parent d0ea8e9 commit d70a976
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
8 changes: 5 additions & 3 deletions src/containers/governance/proposalsDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ function ProposalsDetail({ defaultAccount }) {
proposalStatus={PROPOSAL_STATUS}
/>
</MainContainer>
{addressActive !== null && addressActive.keys === 'keplr' ? (
{addressActive !== null &&
addressActive.keys === 'keplr' &&
location.pathname === `/senate/${proposalId}/voters` ? (
<ActionBarDetail
id={proposalId}
proposals={proposals}
Expand All @@ -307,7 +309,7 @@ function ProposalsDetail({ defaultAccount }) {
update={() => setUpdateFunc((item) => item + 1)}
addressActive={addressActive}
/>
) : (
) : addressActive === null ? (
<ActionBar>
<Pane>
<Link
Expand All @@ -323,7 +325,7 @@ function ProposalsDetail({ defaultAccount }) {
</Link>
</Pane>
</ActionBar>
)}
) : null}
</>
);
}
Expand Down
72 changes: 46 additions & 26 deletions src/containers/governance/proposalsDetailTableComments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import ActionBarContainer from 'src/containers/Search/ActionBarContainer';
import Filters from 'src/containers/Search/Filters/Filters';
import { useBackend } from 'src/contexts/backend/backend';
import { useDevice } from 'src/contexts/device';
import { useParams } from 'react-router-dom';

import { getIpfsHash } from 'src/utils/ipfs/helpers';
import { encodeSlash } from '../../utils/utils';

import { IpfsContentType } from 'src/utils/ipfs/ipfs';

Expand All @@ -25,8 +29,11 @@ export const initialContentTypeFilterState = {

const sortByLSKey = 'search-sort';

function ProposalsDetailTableComments({ proposalId }) {
function ProposalsDetailTableComments() {
const { proposalId } = useParams();

const { ipfsApi } = useBackend();

const query = `bostrom proposal ${proposalId}`;

const [proposalHash, setproposalHash] = useState('');
Expand All @@ -40,25 +47,54 @@ function ProposalsDetailTableComments({ proposalId }) {
initialContentTypeFilterState
);
const [sortBy, setSortBy] = useState(
localStorage.getItem(sortByLSKey) || SortBy.rank
localStorage.getItem(sortByLSKey) || SortBy.date
);
const [linksTypeFilter, setLinksTypeFilter] = useState(LinksTypeFilter.all);


const {
data: items,
total,
error,
hasMore,
isInitialLoading,
refetch,
fetchNextPage: next,
} = useSearchData(proposalHash, {
sortBy,
linksType: linksTypeFilter,
});
const { isMobile: mobile } = useDevice();

useEffect(() => {
setContentTypeFilter(initialContentTypeFilterState);
setContentType({});

(async () => {
(async () => {
try {
let keywordHashTemp = '';

keywordHashTemp = await ipfsApi.addContent(query);

keywordHashTemp = await getIpfsHash(encodeSlash(query));
setproposalHash(keywordHashTemp);
})();
}, [query]);
} catch (error) {
console.error("Error getting hash from getIpfsHash:", error);
try {
keywordHashTemp = await ipfsApi.addContent(query);
setproposalHash(keywordHashTemp);
} catch (error) {
console.error("Error adding content using ipfsApi:", error);
}
}
})();
}, [query]);

const updateComments = async () => {
try {
await refetch();
setRankLink(null);
} finally {
console.error('Error updating comments:', error);
}
};

const onClickRank = async (key) => {
if (rankLink === key) {
setRankLink(null);
Expand All @@ -67,19 +103,6 @@ function ProposalsDetailTableComments({ proposalId }) {
}
};

const {
data: items,
total,
error,
hasMore,
isInitialLoading,
refetch,
fetchNextPage: next,
} = useSearchData(proposalHash, {
sortBy,
linksType: linksTypeFilter,
});

const renderItems = items
.filter((item) => {
const { cid } = item;
Expand Down Expand Up @@ -160,10 +183,7 @@ function ProposalsDetailTableComments({ proposalId }) {
<ActionBarContainer
textBtn={'Comment'}
keywordHash={proposalHash}
update={() => {
refetch();
setRankLink(null);
}}
update={updateComments}
rankLink={rankLink}
/>
</div>
Expand Down
5 changes: 1 addition & 4 deletions src/containers/governance/proposalsRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ function ProposalsRoutes({
index
element={<ProposalsDetailTableComments proposalId={proposalId} />}
/>
<Route
path="comments"
element={<ProposalsDetailTableComments proposalId={proposalId} />}
/>
<Route path="comments" element={<ProposalsDetailTableComments />} />
<Route
path="meta"
element={
Expand Down

0 comments on commit d70a976

Please sign in to comment.