-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(community): add proposals comments (#1136)
- Loading branch information
Showing
7 changed files
with
292 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
src/containers/governance/proposalsDetailTableComments.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import { useState, useEffect } from 'react'; | ||
import InfiniteScroll from 'react-infinite-scroll-component'; | ||
import Spark from 'src/components/search/Spark/Spark'; | ||
import useSearchData from 'src/containers/Search/hooks/useSearchData'; | ||
import { LinksTypeFilter, SortBy } from 'src/containers/Search/types'; | ||
import styles from 'src/containers/Search/SearchResults.module.scss'; | ||
import FirstItems from 'src/containers/Search/_FirstItems.refactor'; | ||
import Loader2 from 'src/components/ui/Loader2'; | ||
import Display from 'src/components/containerGradient/Display/Display'; | ||
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 { IpfsContentType } from 'src/utils/ipfs/ipfs'; | ||
|
||
export const initialContentTypeFilterState = { | ||
text: false, | ||
image: false, | ||
video: false, | ||
pdf: false, | ||
link: false, | ||
// audio: false, | ||
}; | ||
|
||
const sortByLSKey = 'search-sort'; | ||
|
||
function ProposalsDetailTableComments({ proposalId }) { | ||
const { ipfsApi } = useBackend(); | ||
const query = `bostrom proposal ${proposalId}`; | ||
|
||
const [proposalHash, setproposalHash] = useState(''); | ||
const [rankLink, setRankLink] = useState(null); | ||
|
||
const [contentType, setContentType] = useState<{ | ||
[key: string]: IpfsContentType; | ||
}>({}); | ||
|
||
const [contentTypeFilter, setContentTypeFilter] = useState( | ||
initialContentTypeFilterState | ||
); | ||
const [sortBy, setSortBy] = useState( | ||
localStorage.getItem(sortByLSKey) || SortBy.rank | ||
); | ||
const [linksTypeFilter, setLinksTypeFilter] = useState(LinksTypeFilter.all); | ||
|
||
const { isMobile: mobile } = useDevice(); | ||
|
||
useEffect(() => { | ||
setContentTypeFilter(initialContentTypeFilterState); | ||
setContentType({}); | ||
|
||
(async () => { | ||
let keywordHashTemp = ''; | ||
|
||
keywordHashTemp = await ipfsApi.addContent(query); | ||
|
||
setproposalHash(keywordHashTemp); | ||
})(); | ||
}, [query]); | ||
|
||
const onClickRank = async (key) => { | ||
if (rankLink === key) { | ||
setRankLink(null); | ||
} else { | ||
setRankLink(key); | ||
} | ||
}; | ||
|
||
const { | ||
data: items, | ||
total, | ||
error, | ||
hasMore, | ||
isInitialLoading, | ||
refetch, | ||
fetchNextPage: next, | ||
} = useSearchData(proposalHash, { | ||
sortBy, | ||
linksType: linksTypeFilter, | ||
}); | ||
|
||
const renderItems = items | ||
.filter((item) => { | ||
const { cid } = item; | ||
|
||
if (!Object.values(contentTypeFilter).some((value) => value)) { | ||
return true; | ||
} | ||
if (!contentType[cid]) { | ||
return false; | ||
} | ||
return contentTypeFilter[contentType[cid]]; | ||
}) | ||
.map((key, i) => { | ||
|
||
return ( | ||
<Spark | ||
itemData={key} | ||
cid={key.cid} | ||
key={key.cid + i} | ||
linkType={key.type} | ||
query={query} | ||
rankSelected={rankLink === key.cid} | ||
handleRankClick={onClickRank} | ||
handleContentType={(type) => | ||
setContentType((items) => { | ||
return { | ||
...items, | ||
[key.cid]: type, | ||
}; | ||
}) | ||
} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<Filters | ||
filters={contentTypeFilter} | ||
setFilters={setContentTypeFilter} | ||
filter2={sortBy} | ||
setFilter2={setSortBy} | ||
linksFilter={linksTypeFilter} | ||
setLinksFilter={setLinksTypeFilter} | ||
total={total} | ||
total2={items.length} | ||
contentType={contentType} | ||
/> | ||
|
||
<div className={styles.search}> | ||
<FirstItems query={query} /> | ||
|
||
{isInitialLoading ? ( | ||
<Loader2 /> | ||
) : Object.keys(renderItems).length > 0 ? ( | ||
<InfiniteScroll | ||
dataLength={items.length} | ||
next={next} | ||
className={styles.infiniteScroll} | ||
hasMore={hasMore} | ||
loader={<Loader2 />} | ||
> | ||
{renderItems} | ||
</InfiniteScroll> | ||
) : error ? ( | ||
<Display color="red"> | ||
<p>{error.message}</p> | ||
</Display> | ||
) : ( | ||
<Display color="white"> | ||
there are no comments to this proposal <br /> be the first and | ||
create one | ||
</Display> | ||
)} | ||
</div> | ||
{!mobile && ( | ||
<div className={styles.actionBar}> | ||
<ActionBarContainer | ||
textBtn={'Comment'} | ||
keywordHash={proposalHash} | ||
update={() => { | ||
refetch(); | ||
setRankLink(null); | ||
}} | ||
rankLink={rankLink} | ||
/> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} | ||
export default ProposalsDetailTableComments; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Routes, Route } from 'react-router-dom'; | ||
import ProposalsDetailTableComments from './proposalsDetailTableComments'; | ||
import ProposalsIdDetail from './proposalsIdDetail'; | ||
import ProposalsIdDetailTableVoters from './proposalsDetailTableVoters'; | ||
import Layout from './Layout'; | ||
|
||
function ProposalsRoutes({ | ||
proposalId, | ||
proposals, | ||
tallying, | ||
tally, | ||
totalDeposit, | ||
updateFunc, | ||
proposalStatus, | ||
}) { | ||
return ( | ||
<Routes> | ||
<Route path="/" element={<Layout />}> | ||
<Route | ||
index | ||
element={<ProposalsDetailTableComments proposalId={proposalId} />} | ||
/> | ||
<Route | ||
path="comments" | ||
element={<ProposalsDetailTableComments proposalId={proposalId} />} | ||
/> | ||
<Route | ||
path="meta" | ||
element={ | ||
<ProposalsIdDetail | ||
proposals={proposals} | ||
tallying={tallying} | ||
tally={tally} | ||
totalDeposit={totalDeposit} | ||
/> | ||
} | ||
/> | ||
<Route | ||
path="voters" | ||
element={ | ||
proposals.status > proposalStatus.PROPOSAL_STATUS_DEPOSIT_PERIOD ? ( | ||
<ProposalsIdDetailTableVoters | ||
proposalId={proposalId} | ||
updateFunc={updateFunc} | ||
/> | ||
) : null | ||
} | ||
/> | ||
</Route> | ||
</Routes> | ||
); | ||
} | ||
|
||
export default ProposalsRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Tabs } from 'src/components'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { TypePages } from './type'; | ||
|
||
function TabListGoverance() { | ||
const location = useLocation(); | ||
const locationSplit = location.pathname.replace(/^\/|\/$/g, '').split('/'); | ||
let active = Object.values(TypePages).find( | ||
(item) => item === locationSplit[2] | ||
); | ||
if (!active) { | ||
return null; | ||
} | ||
return ( | ||
<Tabs | ||
selected={active} | ||
options={Object.keys(TypePages).map((key) => ({ to: key, key }))} | ||
/> | ||
); | ||
} | ||
|
||
export default TabListGoverance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Outlet } from 'react-router-dom'; | ||
import TabListGoverance from './tabList'; | ||
|
||
function Layout() { | ||
return ( | ||
<div> | ||
<TabListGoverance /> | ||
<Outlet /> | ||
</div> | ||
); | ||
} | ||
|
||
export default Layout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum TypePages { | ||
voters = 'voters', | ||
comments = 'comments', | ||
meta = 'meta', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters