Skip to content

Commit

Permalink
Merge pull request #82 from AutarkLabs/ui-fixes
Browse files Browse the repository at this point in the history
feat: vote linking
  • Loading branch information
topocount authored May 3, 2020
2 parents b2791e4 + 2065fa0 commit dd24e3e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/api-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ const functions =


// TODO: Add and export usePath
const { AragonApi, useAragonApi, useNetwork } = buildStubbedApiReact({
const { AragonApi, useAppState, useAragonApi, useInstalledApps, useNetwork } = buildStubbedApiReact({
functions,
initialState,
})

export { AragonApi, useAragonApi, useNetwork }
export { AragonApi, useAppState, useAragonApi, useInstalledApps, useNetwork }
61 changes: 44 additions & 17 deletions app/components/Widget/Votes/Votes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
IconCheck,
IconClose,
IdentityBadge,
Link,
ProgressBar,
textStyle,
useTheme,
} from '@aragon/ui'
import { useAragonApi, useNetwork } from '../../../api-react'
import { useAppState, useInstalledApps, useNetwork } from '../../../api-react'
import {
VOTING_STATUS,
VOTING_STATUS_ONGOING,
Expand All @@ -23,13 +24,21 @@ import { useIdentity } from '../../../utils/identity-manager'
import LocalLabelAppBadge from '../../LocalIdentityBadge/LocalLabelAppBadge'

const Votes = () => {
const { appState: { votes = [] } } = useAragonApi()
const { votes = [] } = useAppState()
const network = useNetwork()
const installedApps = useInstalledApps()
const kernel = installedApps.find(app => app.name === 'Kernel').appAddress
const voting = installedApps.find(app => app.name === 'Voting').appAddress
console.log('Network: ', network)
const voteUrl = network.type === 'private'
? `http://localhost:3000/#/${kernel}/${voting}/vote`
: `https://${network.type}.aragon.org/#/${kernel}/${voting}/vote`

const reversedVotes = [...votes]
reversedVotes.reverse()

const mappedVotes = useMemo(() => reversedVotes.slice(0, 4).map(vote => (
<Vote key={vote.id}>
<Vote key={vote.id} href={`${voteUrl}/${vote.id}`}>
<div css={`
display: flex;
justify-content: space-between;
Expand All @@ -49,7 +58,7 @@ const Votes = () => {
<Result yea={vote.yea} nay={vote.nay} />
</div>
</Vote>
)), [reversedVotes])
)), [ reversedVotes, voteUrl ])

return (
<div css={`
Expand All @@ -62,20 +71,38 @@ const Votes = () => {
)
}

const Vote = styled(Card)`
/* :not(:last-child) {
margin-bottom: ${2 * GU}px;
} */
const Vote = ({ children, href }) => {
const theme = useTheme()
return (
<Link
href={href}
css={`
text-decoration: none;
color: ${theme.surfaceContent};
`}
>
<Card
css={`
padding: ${2 * GU}px;
display: flex;
height: 100%;
width: 100%;
flex-direction: column;
align-items: stretch;
text-align: left;
cursor: pointer;
`}
>
{children}
</Card>
</Link>
)
}

padding: ${2 * GU}px;
display: flex;
height: 100%;
width: 100%;
/* max-width: ${41.75 * GU}px; */
flex-direction: column;
justify-content: space-between;
align-items: stretch;
`
Vote.propTypes = {
children: PropTypes.node.isRequired,
href: PropTypes.string.isRequired,
}

const AppBadge = ({ address }) => {
return (
Expand Down
4 changes: 3 additions & 1 deletion app/utils/api-react/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
AragonApi,
useAppState,
useGuiStyle,
useInstalledApps,
usePath,
useAragonApi as useProductionApi,
useNetwork as useProductionNetwork,
Expand All @@ -25,5 +27,5 @@ export default ({ initialState = {}, functions = (() => {}) }) => {
}
}

return { AragonApi, useAragonApi, useGuiStyle, useNetwork, usePath }
return { AragonApi, useAppState, useAragonApi, useGuiStyle, useInstalledApps, useNetwork, usePath }
}

0 comments on commit dd24e3e

Please sign in to comment.