mirror of
https://github.com/status-im/snt-voting.git
synced 2025-02-23 23:58:13 +00:00
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 = {
|
const sortingFn = {
|
||||||
MOST_VOTES: (a, b) => b._qvResults - a._qvResults,
|
MOST_VOTES: (a, b) => b._qvResults - a._qvResults,
|
||||||
MOST_VOTERS: (a, b) => b._voters - a._voters,
|
MOST_VOTERS: (a, b) => b._voters - a._voters,
|
||||||
@ -110,7 +115,8 @@ class Poll extends PureComponent {
|
|||||||
_results,
|
_results,
|
||||||
_canVote,
|
_canVote,
|
||||||
balance,
|
balance,
|
||||||
classes
|
classes,
|
||||||
|
ideaSites
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { value, originalValue, isSubmitting, error } = this.state;
|
const { value, originalValue, isSubmitting, error } = this.state;
|
||||||
const cantVote = balance == 0 || !_canVote;
|
const cantVote = balance == 0 || !_canVote;
|
||||||
@ -118,6 +124,8 @@ class Poll extends PureComponent {
|
|||||||
const { fromWei } = web3.utils;
|
const { fromWei } = web3.utils;
|
||||||
const maxValue = Math.floor(Math.sqrt(balance));
|
const maxValue = Math.floor(Math.sqrt(balance));
|
||||||
const buttonText = originalValue != 0 && value != originalValue ? 'Change Vote' : 'Vote';
|
const buttonText = originalValue != 0 && value != originalValue ? 'Change Vote' : 'Vote';
|
||||||
|
const idea = getIdeaFromStr(_description)
|
||||||
|
const ideaSite = ideaSites.filter(site => site.includes(idea));
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
@ -133,6 +141,7 @@ class Poll extends PureComponent {
|
|||||||
{balance != 0 && !_canVote && <span>You can not vote on this poll</span>}
|
{balance != 0 && !_canVote && <span>You can not vote on this poll</span>}
|
||||||
</Typography>}
|
</Typography>}
|
||||||
{error && <Typography variant="body2" color="error">{error}</Typography>}
|
{error && <Typography variant="body2" color="error">{error}</Typography>}
|
||||||
|
{ideaSite.length && <Typography variant="subheading" color="primary">{ideaSite}</Typography>}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
{!cantVote && <CardActions className={classes.card}>
|
{!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} />
|
<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 }) => (
|
const PollsList = ({ classes }) => (
|
||||||
<VotingContext.Consumer>
|
<VotingContext.Consumer>
|
||||||
{({ updatePoll, rawPolls, pollOrder, appendToPoll }) =>
|
{({ updatePoll, rawPolls, pollOrder, appendToPoll, ideaSites }) =>
|
||||||
<Fragment>
|
<Fragment>
|
||||||
{rawPolls
|
{rawPolls
|
||||||
.map((poll, i) => ({ ...poll, idPoll: i }) )
|
.map((poll, i) => ({ ...poll, idPoll: i }) )
|
||||||
.sort(sortingFn[pollOrder])
|
.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>
|
</Fragment>
|
||||||
}
|
}
|
||||||
</VotingContext.Consumer>
|
</VotingContext.Consumer>
|
||||||
|
@ -7,7 +7,8 @@ import AdminView from './components/AdminView';
|
|||||||
import Voting from './components/Voting';
|
import Voting from './components/Voting';
|
||||||
import SNT from 'Embark/contracts/SNT';
|
import SNT from 'Embark/contracts/SNT';
|
||||||
import { VotingContext } from './context';
|
import { VotingContext } from './context';
|
||||||
import Web3Render from './components/standard/Web3Render'
|
import Web3Render from './components/standard/Web3Render';
|
||||||
|
import fetchIdeas from './utils/fetchIdeas';
|
||||||
window['SNT'] = SNT;
|
window['SNT'] = SNT;
|
||||||
|
|
||||||
import './dapp.css';
|
import './dapp.css';
|
||||||
@ -40,6 +41,7 @@ class App extends React.Component {
|
|||||||
web3.eth.net.getId((err, netId) => {
|
web3.eth.net.getId((err, netId) => {
|
||||||
if (netId !== MAINNET) this.setState({ web3Provider: false})
|
if (netId !== MAINNET) this.setState({ web3Provider: false})
|
||||||
})
|
})
|
||||||
|
fetchIdeas().then(ideaSites => { this.setState({ ideaSites })});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
app/utils/fetchIdeas.js
Normal file
30
app/utils/fetchIdeas.js
Normal file
@ -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/core": "^1.3.0",
|
||||||
"@material-ui/icons": "^1.1.0",
|
"@material-ui/icons": "^1.1.0",
|
||||||
"@material-ui/lab": "^1.0.0-alpha.5",
|
"@material-ui/lab": "^1.0.0-alpha.5",
|
||||||
|
"axios": "^0.18.0",
|
||||||
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
||||||
"babel-preset-stage-2": "^6.24.1",
|
"babel-preset-stage-2": "^6.24.1",
|
||||||
"bignumber.js": "^5.0.0",
|
"bignumber.js": "^5.0.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user