add fetch idea link for poll
This commit is contained in:
parent
f60a12c32c
commit
498742dc11
|
@ -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 (
|
||||
<Card>
|
||||
<CardContent>
|
||||
|
@ -133,6 +141,7 @@ class Poll extends PureComponent {
|
|||
{balance != 0 && !_canVote && <span>You can not vote on this poll</span>}
|
||||
</Typography>}
|
||||
{error && <Typography variant="body2" color="error">{error}</Typography>}
|
||||
{ideaSite.length && <Typography variant="subheading" color="primary">{ideaSite}</Typography>}
|
||||
</CardContent>
|
||||
{!cantVote && <CardActions className={classes.card}>
|
||||
<Slider style={{ width: '95%' }} classes={{ thumb: classes.thumb }} disabled={disableVote} value={value || 0} min={0} max={maxValue} step={1} onChange={this.handleChange} />
|
||||
|
@ -146,12 +155,12 @@ class Poll extends PureComponent {
|
|||
|
||||
const PollsList = ({ classes }) => (
|
||||
<VotingContext.Consumer>
|
||||
{({ updatePoll, rawPolls, pollOrder, appendToPoll }) =>
|
||||
{({ updatePoll, rawPolls, pollOrder, appendToPoll, ideaSites }) =>
|
||||
<Fragment>
|
||||
{rawPolls
|
||||
.map((poll, i) => ({ ...poll, idPoll: i }) )
|
||||
.sort(sortingFn[pollOrder])
|
||||
.map((poll) => <Poll key={poll._token} classes={classes} appendToPoll={appendToPoll} updatePoll={updatePoll} {...poll} />)}
|
||||
.map((poll) => <Poll key={poll._token} classes={classes} appendToPoll={appendToPoll} updatePoll={updatePoll} ideaSites={ideaSites} {...poll} />)}
|
||||
</Fragment>
|
||||
}
|
||||
</VotingContext.Consumer>
|
||||
|
|
|
@ -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 })});
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue