diff --git a/app/components/simple-voting/PollsList.js b/app/components/simple-voting/PollsList.js index e0ac458..6b9dbda 100644 --- a/app/components/simple-voting/PollsList.js +++ b/app/components/simple-voting/PollsList.js @@ -24,6 +24,11 @@ const styles = { } }; +const getIdeaFromStr = str => { + const match = str.match(/\(([^)]+)\)/) + if (match) return match[1].toLowerCase(); + return match; +} const sortingFn = { MOST_VOTES: (a, b) => b._qvResults - a._qvResults, MOST_VOTERS: (a, b) => b._voters - a._voters, @@ -110,7 +115,8 @@ class Poll extends PureComponent { _results, _canVote, balance, - classes + classes, + ideaSites } = this.props; const { value, originalValue, isSubmitting, error } = this.state; const cantVote = balance == 0 || !_canVote; @@ -118,6 +124,8 @@ class Poll extends PureComponent { const { fromWei } = web3.utils; const maxValue = Math.floor(Math.sqrt(balance)); const buttonText = originalValue != 0 && value != originalValue ? 'Change Vote' : 'Vote'; + const idea = getIdeaFromStr(_description) + const ideaSite = ideaSites.filter(site => site.includes(idea)); return ( @@ -133,6 +141,7 @@ class Poll extends PureComponent { {balance != 0 && !_canVote && You can not vote on this poll} } {error && {error}} + {ideaSite.length && {ideaSite}} {!cantVote && @@ -146,12 +155,12 @@ class Poll extends PureComponent { const PollsList = ({ classes }) => ( - {({ updatePoll, rawPolls, pollOrder, appendToPoll }) => + {({ updatePoll, rawPolls, pollOrder, appendToPoll, ideaSites }) => {rawPolls .map((poll, i) => ({ ...poll, idPoll: i }) ) .sort(sortingFn[pollOrder]) - .map((poll) => )} + .map((poll) => )} } diff --git a/app/dapp.js b/app/dapp.js index 4a1a4dd..90e8ed0 100644 --- a/app/dapp.js +++ b/app/dapp.js @@ -7,7 +7,8 @@ import AdminView from './components/AdminView'; import Voting from './components/Voting'; import SNT from 'Embark/contracts/SNT'; import { VotingContext } from './context'; -import Web3Render from './components/standard/Web3Render' +import Web3Render from './components/standard/Web3Render'; +import fetchIdeas from './utils/fetchIdeas'; window['SNT'] = SNT; import './dapp.css'; @@ -40,6 +41,7 @@ class App extends React.Component { web3.eth.net.getId((err, netId) => { if (netId !== MAINNET) this.setState({ web3Provider: false}) }) + fetchIdeas().then(ideaSites => { this.setState({ ideaSites })}); }) } diff --git a/app/utils/fetchIdeas.js b/app/utils/fetchIdeas.js new file mode 100644 index 0000000..2aee7a6 --- /dev/null +++ b/app/utils/fetchIdeas.js @@ -0,0 +1,30 @@ +import axios from 'axios'; + +const repoFilter = (repo) => { + const { path } = repo; + if (path.includes('ideas')) { + const split = path.split('/'); + if (split.length < 3) return true; + if (path.includes('README')) return true; + } + return false; +} + +const convertToUrl = (repo) => { + const { path } = repo; + const base = 'https://ideas.status.im/'; + const suffix = path.split('.md')[0]; + return `${base}${suffix}`; +} + +const fetchContent = async () => { + const response = await axios.get('https://api.github.com/repos/status-im/ideas/git/trees/master?recursive=1'); + return response['data']['tree'].filter(repoFilter).map(convertToUrl); +} + +const pluckIdeas = async () => { + const data = await fetchContent(); + return data; +} +export default pluckIdeas; + diff --git a/package.json b/package.json index 907ec66..f9e6329 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@material-ui/core": "^1.3.0", "@material-ui/icons": "^1.1.0", "@material-ui/lab": "^1.0.0-alpha.5", + "axios": "^0.18.0", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-stage-2": "^6.24.1", "bignumber.js": "^5.0.0",