Skip to content

Commit

Permalink
Build Issues Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshpw committed Dec 3, 2024
1 parent 4e04b6b commit 96ad603
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 187 deletions.
1 change: 0 additions & 1 deletion src/modules/explorer/components/NetworkSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ResponsiveDialog } from "./ResponsiveDialog"
import { ColorDot } from "./ChangeNetworkButton"
import { ContentContainer } from "./ContentContainer"
import { ActionTypes, CreatorContext } from "modules/creator/state"
import { ContentContainer } from "components/ui/Table"

const SheetItem = styled(ContentContainer)({
"height": 50,
Expand Down
174 changes: 98 additions & 76 deletions src/modules/explorer/components/ProposalsList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Collapse, Grid, styled, Typography } from "@material-ui/core"
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useCallback, useEffect, useMemo, useState } from "react"
import { CircularProgress, Collapse, Grid, Typography, styled } from "@material-ui/core"
import { ProposalItem } from "modules/explorer/pages/User"
import React, { useState } from "react"
import { Link } from "react-router-dom"
import { Proposal } from "services/services/dao/mappers/proposal/types"
import { ProposalTableRow } from "modules/lite/explorer/components/ProposalTableRow"
import { Poll } from "models/Polls"
import ReactPaginate from "react-paginate"
import "../pages/DAOList/styles.css"
import { Filters } from "../pages/User/components/UserMovements"
import { Order, ProposalType, StatusOption } from "./FiltersUserDialog"

const TableContainer = styled(Grid)({
width: "100%"
Expand All @@ -23,22 +26,34 @@ const ProposalsFooter = styled(Grid)({
minHeight: 34
})

const LoaderContainer = styled(Grid)({
paddingTop: 40,
paddingBottom: 40
})

interface Props {
currentLevel: number
proposals: Proposal[] | undefined
showFooter?: boolean
rightItem?: (proposal: Proposal) => React.ReactElement
liteProposals: Poll[] | undefined
proposalStyle?: any
showFullList?: boolean
filters: undefined | Filters
}

interface ProposalObj {
type: string
proposal: Proposal | Poll
}

export const ProposalsList: React.FC<Props> = ({
currentLevel,
proposals,
showFooter,
rightItem,
liteProposals,
proposalStyle
proposalStyle,
showFullList = true,
filters = undefined
}) => {
const [currentPage, setCurrentPage] = useState(0)
const [offset, setOffset] = useState(0)
Expand All @@ -48,22 +63,41 @@ export const ProposalsList: React.FC<Props> = ({
const [filterOnchain, setFilterOnchain] = useState<string>()
const [isLoading, setIsLoading] = useState(false)

const itemsPerPage = 24
const pageCount = Math.ceil(
proposals && liteProposals
? proposals.length + liteProposals.length / itemsPerPage
: proposals && liteProposals?.length === undefined
? proposals.length / itemsPerPage
: proposals?.length === undefined && liteProposals
? liteProposals.length / itemsPerPage
: 0
)
const listOfProposals = useMemo(() => {
const proposalList: { type: string; proposal: Proposal | Poll }[] = []
proposals?.map(proposal => {
const item = {
type: "lambda",
proposal: proposal
}
proposalList.push(item)
return
})
liteProposals?.map(proposal => {
const item = {
type: "lite",
proposal: proposal
}
proposalList.push(item)
return
})
return proposalList
}, [liteProposals, proposals])

useEffect(() => {
setFilteredProposals(listOfProposals)
}, [])

useEffect(() => {
setFilteredProposals(listOfProposals)
}, [showFullList])

const pageCount = Math.ceil(filteredProposals ? filteredProposals.length / 4 : 0)

// Invoke when user click to request another page.
const handlePageClick = (event: { selected: number }) => {
if (proposals) {
const newOffset = (event.selected * itemsPerPage) % proposals.length
setOffset(newOffset)
if (filteredProposals) {
setOffset((event.selected * 4) % filteredProposals.length)
setCurrentPage(event.selected)
}
}
Expand Down Expand Up @@ -174,66 +208,54 @@ export const ProposalsList: React.FC<Props> = ({

return (
<TableContainer item>
<Grid container direction="column" wrap={"nowrap"} style={{ gap: 16 }}>
{proposals && proposals.length && proposals.length > 0 ? (
<Grid
item
container
wrap={"nowrap"}
component={Collapse}
in={open}
timeout="auto"
unmountOnExit
// style={{ display: "block" }}
direction="column"
>
{proposals.slice(offset, offset + itemsPerPage).map((p, i) => (
<CustomGrid item key={`proposal-${i}`} style={proposalStyle}>
<Link to={`proposal/${p.id}`}>
<ProposalItem proposal={p} status={p.getStatus(currentLevel).status}>
{rightItem ? rightItem(p) : null}
</ProposalItem>
</Link>
</CustomGrid>
))}
{isLoading ? (
<LoaderContainer container direction="row" justifyContent="center">
<CircularProgress color="secondary" />
</LoaderContainer>
) : (
<>
<Grid container direction="column" wrap={"nowrap"} style={{ gap: 16 }}>
{filteredProposals && filteredProposals.length && filteredProposals.length > 0 ? (
<Grid item container wrap={"nowrap"} direction="column">
{filteredProposals.slice(offset, offset + 4).map((p, i) =>
p.type === "lambda" ? (
<CustomGrid item key={`proposal-${i}`} style={proposalStyle}>
<Link to={`proposal/${p.proposal.id}`}>
<ProposalItem
proposal={p.proposal}
status={p.proposal.getStatus(currentLevel).status}
></ProposalItem>
</Link>
</CustomGrid>
) : (
<div style={{ width: "inherit", marginBottom: 16 }} key={`poll-${i}`}>
<ProposalTableRow poll={p.proposal} />
</div>
)
)}
</Grid>
) : (
<Typography color="textPrimary">No proposals found</Typography>
)}
</Grid>
) : null}
{liteProposals && liteProposals.length > 0
? liteProposals.slice(offset, offset + itemsPerPage).map((poll, i) => {
return (
<div style={{ width: "inherit" }} key={`poll-${i}`}>
<ProposalTableRow poll={poll} />
</div>
)
})
: null}

{showFooter && (
<ProposalsFooter item container direction="column" justifyContent="center">
<Grid item>
<Link to="proposals">
<Typography color="secondary" variant="body2" align="center">
View All Proposals
</Typography>
</Link>
{showFullList ? (
<Grid container direction="row" justifyContent="flex-end">
<ReactPaginate
previousLabel={"<"}
breakLabel="..."
nextLabel=">"
onPageChange={handlePageClick}
pageRangeDisplayed={2}
pageCount={pageCount}
renderOnZeroPageCount={null}
containerClassName={"pagination"}
activeClassName={"active"}
forcePage={currentPage}
/>
</Grid>
</ProposalsFooter>
)}
</Grid>
<Grid container direction="row" justifyContent="flex-end">
<ReactPaginate
previousLabel={"<"}
breakLabel="..."
nextLabel=">"
onPageChange={handlePageClick}
pageRangeDisplayed={2}
pageCount={pageCount}
renderOnZeroPageCount={null}
containerClassName={"pagination"}
activeClassName={"active"}
forcePage={currentPage}
/>
</Grid>
) : null}
</>
)}
</TableContainer>
)
}
61 changes: 1 addition & 60 deletions src/modules/explorer/pages/DAOList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,66 +114,7 @@ const TabsContainer = styled(Grid)(({ theme }) => ({
}))

export const DAOList: React.FC = () => {
const { network, account, etherlink } = useTezos()
const { data: daos, isLoading } = useAllDAOs(network)

const theme = useTheme()
const isMobileSmall = useMediaQuery(theme.breakpoints.down("mobile"))
const myDAOs = useMemo(() => {
if (daos) {
const formattedDAOs = daos
.map(dao => ({
id: dao.address,
name: dao.name,
symbol: dao.token.symbol,
votingAddresses: dao.ledgers ? dao.ledgers.map(l => l.holder.address) : [],
votingAddressesCount:
dao.dao_type.name === "lite" ? dao.votingAddressesCount : dao.ledgers ? dao.ledgers?.length : 0,
dao_type: {
name: dao.dao_type.name
},
description: dao.description,
allowPublicAccess: dao.dao_type.name === "lite" ? dao.allowPublicAccess : true
}))
.sort((a, b) => b.votingAddresses.length - a.votingAddresses.length)

if (searchText) {
return formattedDAOs.filter(
formattedDao =>
(formattedDao.name && formattedDao.name.toLowerCase().includes(searchText.toLowerCase())) ||
(formattedDao.symbol && formattedDao.symbol.toLowerCase().includes(searchText.toLowerCase()))
)
}
return formattedDAOs.filter(dao => dao.votingAddresses.includes(account))
}

return []
}, [daos, account, searchText])

if (!account) return <ConnectMessage />

if (isLoading)
return (
<Typography color="textPrimary">
<CircularProgress color="secondary" />
</Typography>
)

if (myDAOs.length === 0) return <Typography color="textPrimary">You have not joined any DAO</Typography>

return (
<DAOItemGrid container justifyContent={isMobileSmall ? "center" : "flex-start"}>
{myDAOs.map((dao, i) => (
<DAOItemCard key={`mine-${i}`} item>
<DAOItem dao={dao} />
</DAOItemCard>
))}
</DAOItemGrid>
)
}

export const DAOList: React.FC = () => {
const { network } = useTezos()
const { network, etherlink, account } = useTezos()
const { data: daos, isLoading } = useAllDAOs(network)

const theme = useTheme()
Expand Down
2 changes: 2 additions & 0 deletions src/modules/explorer/pages/Proposals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ export const Proposals: React.FC = () => {
currentLevel={cycleInfo.currentLevel}
proposals={proposals}
liteProposals={undefined}
filters={filters}
/>
)}
{!(proposals && proposals.length > 0) ? (
Expand All @@ -302,6 +303,7 @@ export const Proposals: React.FC = () => {
currentLevel={cycleInfo.currentLevel}
proposals={undefined}
liteProposals={polls}
filters={filters}
/>
)}
{!(polls && polls.length > 0) ? (
Expand Down
31 changes: 4 additions & 27 deletions src/modules/explorer/pages/User/components/UserMovements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,33 +197,6 @@ export const UserMovements: React.FC<{
setFilters(filters)
}

const handleChangeTabTransactions = (newValue: number) => {
if (newValue === 0) {
setFilteredTransactions(transfers)
setPageCount(Math.ceil(transfers ? transfers.length / 2 : 0))
}
if (newValue === 1) {
const newArray = transfers?.filter(item => item.type === "Withdrawal")
setFilteredTransactions(newArray)
setPageCount(Math.ceil(newArray ? newArray.length / 2 : 1))
}
if (newValue === 2) {
const newArray = transfers?.filter(item => item.type === "Deposit")
setFilteredTransactions(newArray)
setPageCount(Math.ceil(newArray ? newArray.length / 2 : 1))
}
setSelectedTabTransactions(newValue)
}

// Invoke when user click to request another page.
const handlePageClick = (event: { selected: number }) => {
if (transfers) {
const newOffset = (event.selected * count) % (filteredTransactions ? filteredTransactions.length : 1)
setOffset(newOffset)
setCurrentPage(event.selected)
}
}

return (
<Grid item>
{showActivity ? (
Expand Down Expand Up @@ -306,6 +279,8 @@ export const UserMovements: React.FC<{
currentLevel={cycleInfo.currentLevel}
proposals={showActivity ? proposalsCreated : proposalsCreated.slice(0, 2)}
liteProposals={showActivity ? pollsPosted : pollsPosted?.slice(0, 2)}
showFullList={showActivity}
filters={filters}
/>
)}
{!(proposalsCreated && proposalsCreated.length > 0) && !(pollsPosted && pollsPosted.length > 0) ? (
Expand All @@ -328,6 +303,8 @@ export const UserMovements: React.FC<{
currentLevel={cycleInfo.currentLevel}
proposals={showActivity ? proposalsVoted : proposalsVoted.slice(0, 2)}
liteProposals={showActivity ? votedPolls : votedPolls.slice(0, 2)}
showFullList={showActivity}
filters={filters}
/>
)}
{!(proposalsVoted && proposalsVoted.length > 0) && !(votedPolls && votedPolls.length > 0) ? (
Expand Down
10 changes: 2 additions & 8 deletions src/modules/explorer/pages/User/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ import { StatusBadge } from "../../components/StatusBadge"
import { ProfileAvatar } from "../../components/styled/ProfileAvatar"
import { UserBalances } from "../../components/UserBalances"
import { UserProfileName } from "../../components/UserProfileName"
import { usePolls } from "modules/lite/explorer/hooks/usePolls"

import { Delegation } from "./components/DelegationBanner"
import { useTokenDelegationSupported } from "services/contracts/token/hooks/useTokenDelegationSupported"
import { UserMovements } from "./components/UserMovements"
import { useUserVotes } from "modules/lite/explorer/hooks/useUserVotes"
import { Poll } from "models/Polls"

import { CopyButton } from "modules/explorer/components/CopyButton"

const ContentBlockItem = styled(Grid)(({ theme }: { theme: Theme }) => ({
Expand Down Expand Up @@ -65,11 +64,6 @@ const TitleText = styled(Typography)({
fontSize: 32
})

const TitleText = styled(Typography)({
fontWeight: 600,
fontSize: 32
})

export const ProposalItem: React.FC<{
proposal: Proposal | any
status: ProposalStatus
Expand Down
Loading

0 comments on commit 96ad603

Please sign in to comment.