Skip to content

Commit

Permalink
Merge pull request #548 from DemocracyEarth/mobile
Browse files Browse the repository at this point in the history
Deep filtering of queries for daos, addresses and tokens.
  • Loading branch information
santisiri authored Nov 3, 2020
2 parents 324556b + b8d83e7 commit fc01635
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 107 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<p align="center">
<img src="docs/democracy-earth.png" width="400" title="Democracy Earth Foundation">
</p>

<p align="center">
Explore and participate in Digital Autonomous Organizations (DAOs).
</p>

[![Join the chat at https://discord.com/invite/HGsyGXw](https://img.shields.io/discord/490948346773635102?color=%237289DA&label=DemocracyEarth&logo=discord&logoColor=white)](https://discord.com/invite/HGsyGXw)

<img src="docs/sovereign-screenshot-2020.png" width="800" title="Democracy Earth Dapp Screenshot 2019">
<p align="center">
<img src="docs/sovereign-screenshot-2020.png" width="800" title="Democracy Earth Dapp Screenshot 2020">
</p>

[![Join the chat at https://discord.com/invite/HGsyGXw](https://img.shields.io/discord/490948346773635102?color=%237289DA&label=DemocracyEarth&logo=discord&logoColor=white)](https://discord.com/invite/HGsyGXw)

## Features

- [X] Built for Ethereum using [Web3](https://github.com/ethereum/web3.js/).
Expand Down
2 changes: 1 addition & 1 deletion src/components/Browser/Browser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Browser extends Component {
}

if (this.props.match.params.token) {
return <Search contextTag={{ id: this.props.match.params.token, text: i18n.t('search-token', { searchTerm: this.props.match.params.token }) }} />
return <Search contextTag={{ id: this.props.match.params.token, text: i18n.t('search-token', { searchTerm: this.props.match.params.token.toUpperCase() }) }} />
}

if (this.props.match.params.date) {
Expand Down
3 changes: 3 additions & 0 deletions src/components/Dapp/Dapp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const routes = [
{
path: '/address/:address/period/:period',
},
{
path: '/address/:address/period/:period',
},
{
path: '/proposal/:proposal',
},
Expand Down
8 changes: 4 additions & 4 deletions src/components/Item/Item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ItemLink extends Component {
}

getTagStyle() {
return `sidebar-tag ${(this.props.location.pathname === this.props.href) ? 'sidebar-tag-selected' : null}`;
return `sidebar-tag ${(`${this.props.location.pathname}${this.props.location.search}` === this.props.href) ? 'sidebar-tag-selected' : null}`;
}

getLabelStyle() {
Expand All @@ -48,14 +48,14 @@ class ItemLink extends Component {
if (this.props.icon) {
return this.props.icon;
}
return (this.props.location.pathname === this.props.href) ? paperActive : paper;
return (`${this.props.location.pathname}${this.props.location.search}` === this.props.href) ? paperActive : paper;
}

render() {
if (this.props.hideEmpty && this.props.score === 0) return null;
return (
<NavLink to={this.props.href}
isActive={(match, location) => { if (!match) { return false }; return (location.pathname === this.props.href); }}
<NavLink to={this.props.href} exact={true}
isActive={(match, location) => { if (!match) { return false }; return (`${location.pathname}${location.search}` === this.props.href); }}
className="menu-item" activeClassName="menu-item-selected"
>
{(this.props.sharp) ?
Expand Down
9 changes: 7 additions & 2 deletions src/components/Layout/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useParams } from 'react-router-dom';
import { useParams, useLocation } from 'react-router-dom';

import Menu from 'components/Menu/Menu';
import Timeline from 'components/Timeline/Timeline';
Expand All @@ -20,6 +20,7 @@ import 'styles/Dapp.css';
*/
const Layout = (props) => {
const { dao, address, period, proposal, token, date, search } = useParams();
const searchParams = new URLSearchParams(useLocation().search);

// defaults
let view = routerView.HOME;
Expand All @@ -31,10 +32,12 @@ const Layout = (props) => {
// context specific
let description = i18n.t('meta-description');
if (dao) {
periodEpoch = searchParams.get('period');
renderAddress = dao;
view = routerView.DAO;
description = i18n.t('meta-dao', { address: dao });
} else if (address) {
periodEpoch = searchParams.get('period');
renderAddress = address;
view = routerView.ADDRESS;
description = i18n.t('meta-address', { address });
Expand All @@ -47,10 +50,12 @@ const Layout = (props) => {
view = routerView.PROPOSAL;
description = i18n.t('meta-proposal', { proposal });
} else if (token) {
periodEpoch = searchParams.get('period');
param = token.toUpperCase();
view = routerView.TOKEN;
description = i18n.t('meta-token', { token: token.toUpperCase() });
} else if (date) {
periodEpoch = searchParams.get('period');
param = date;
view = routerView.DATE;
description = i18n.t('meta-date', { date });
Expand Down Expand Up @@ -103,7 +108,7 @@ const Layout = (props) => {
<div id="proposals" className="content content-feed max100">
<div id="non-editable-feed">
<Timeline address={renderAddress} period={periodEpoch} view={view} proposalId={proposalId} param={param}
field={'memberAddress'} first={25} skip={0} page={1} orderBy={'createdAt'} orderDirection={'desc'} />
field={'memberAddress'} first={25} skip={0} page={1} orderBy={'createdAt'} orderDirection={'desc'} />
</div>
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/components/Menu/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ const _getMenu = (view, data, address, param) => {
return (
<div className="submenu">
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[0])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[0])} key={0} href={(atHome) ? `/` : baseRoute } />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[1])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[1])} key={1} href={(atHome) ? '/period/queue' : `${baseRoute}/period/queue`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[2])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[2])} key={2} href={(atHome) ? '/period/voting' : `${baseRoute}/period/voting`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[3])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[3])} key={3} href={(atHome) ? '/period/grace' : `${baseRoute}/period/grace`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[4])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[4])} key={4} href={(atHome) ? '/period/ready' : `${baseRoute}/period/ready`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[5])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[5])} key={5} href={(atHome) ? '/period/rejected' : `${baseRoute}/period/rejected`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[6])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[6])} key={6} href={(atHome) ? '/period/approved' : `${baseRoute}/period/approved`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[1])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[1])} key={1} href={(atHome) ? '/period/queue' : `${baseRoute}?period=queue`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[2])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[2])} key={2} href={(atHome) ? '/period/voting' : `${baseRoute}?period=voting`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[3])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[3])} key={3} href={(atHome) ? '/period/grace' : `${baseRoute}?period=grace`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[4])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[4])} key={4} href={(atHome) ? '/period/ready' : `${baseRoute}?period=ready`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[5])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[5])} key={5} href={(atHome) ? '/period/rejected' : `${baseRoute}?period=rejected`} />
<Item sharp hideEmpty={hideEmpty} label={`${i18n.t(defaultLabels[6])}`} score={(atHome) ? null : _getProposalCount(data.proposals, defaultLabels[6])} key={6} href={(atHome) ? '/period/approved' : `${baseRoute}?period=approved`} />
</div>
);
};
Expand Down
9 changes: 2 additions & 7 deletions src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const _getDescription = (description) => {
const json = JSON.parse(description);

content = {
title: json.title ? json.title : json,
title: json.title ? json.title : '',
description: json.description ? wrapURLs(json.description) : '',
link: (typeof json.link === 'function' || !json.link) ? '' : json.link,
};
Expand All @@ -57,11 +57,6 @@ class Post extends Component {
constructor(props) {
super(props);
this.state = _getDescription(this.props.description);
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
// this.props.history.push(this.props.href);
}

render() {
Expand All @@ -72,7 +67,7 @@ class Post extends Component {
includeInSearch(this.props.href, searchCache, 'search-contract');

return (
<div className="vote vote-search vote-feed nondraggable vote-poll" onClick={this.handleClick}>
<div className="vote vote-search vote-feed nondraggable vote-poll">
<div className="checkbox checkbox-custom">
<div className="meta meta-search meta-bar">
<Account publicAddress={this.props.memberAddress} width="16px" height="16px" />
Expand Down
42 changes: 17 additions & 25 deletions src/components/Timeline/Timeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Search from 'components/Search/Search';
import Paginator from 'components/Paginator/Paginator';
import Expand from 'components/Expand/Expand';

import { query } from 'components/Timeline/queries';
import { getQuery } from 'components/Timeline/queries';
import { config } from 'config'
import { defaults, view as routerView, period as routerPeriod } from 'lib/const';
import { uniqBy, orderBy as _orderBy } from 'lodash';
Expand All @@ -46,51 +46,42 @@ import 'styles/Dapp.css';

/**
* @summary retrieves the corresponding query for the timeline.
* @param {string} view based on router context
* @param {string} field if required for a specific query
*/
const composeQuery = (view, field, period) => {
const composeQuery = (view, period) => {
switch (view) {
case routerView.HOME:
return query.GET_PROPOSALS;
return getQuery('GET_PROPOSALS');
case routerView.DAO:
return query.GET_PROPOSALS_DAO;
return getQuery('GET_PROPOSALS_DAO', period);
case routerView.PROPOSAL:
return query.GET_PROPOSAL_ID;
return getQuery('GET_PROPOSAL_ID');
case routerView.PERIOD:
switch (period) {
case routerPeriod.QUEUE:
return query.GET_PROPOSALS_PERIOD_QUEUE;
return getQuery('GET_PROPOSALS_PERIOD_QUEUE');
case routerPeriod.VOTING:
return query.GET_PROPOSALS_PERIOD_VOTING;
return getQuery('GET_PROPOSALS_PERIOD_VOTING');
case routerPeriod.GRACE:
return query.GET_PROPOSALS_PERIOD_GRACE;
return getQuery('GET_PROPOSALS_PERIOD_GRACE');
case routerPeriod.READY:
return query.GET_PROPOSALS_PERIOD_READY;
return getQuery('GET_PROPOSALS_PERIOD_READY');
case routerPeriod.REJECTED:
return query.GET_PROPOSALS_PERIOD_REJECTED;
return getQuery('GET_PROPOSALS_PERIOD_REJECTED');
case routerPeriod.APPROVED:
return query.GET_PROPOSALS_PERIOD_APPROVED;
return getQuery('GET_PROPOSALS_PERIOD_APPROVED');
default:
}
break;
case routerView.TOKEN:
return query.GET_PROPOSALS_TOKEN;
return getQuery('GET_PROPOSALS_TOKEN', period);
case routerView.DATE:
return query.GET_PROPOSALS_DATE;
return getQuery('GET_PROPOSALS_DATE', period);
case routerView.ADDRESS:
return query.GET_PROPOSALS_ADDRESS;
return getQuery('GET_PROPOSALS_ADDRESS', period);
case routerView.SEARCH:
return query.GET_PROPOSALS_SEARCH;
return getQuery('GET_PROPOSALS_SEARCH');
default:
switch (field) {
case 'applicant':
return query.GET_PROPOSALS_APPLICANT;
case 'memberAddress':
return query.GET_PROPOSALS_MEMBER;
default:
return query.GET_PROPOSALS;
}
}
}

Expand Down Expand Up @@ -141,7 +132,7 @@ const Feed = (props) => {
dateEnd = Math.floor((new Date(param).getTime() / 1000) + 86400).toString();
}

const [getFeed, { data, loading, error }] = useLazyQuery(composeQuery(props.view, props.field, props.period), { variables: { address, first, skip, orderBy, orderDirection, now, proposalId, param, dateBegin, dateEnd } });
const [getFeed, { data, loading, error }] = useLazyQuery(composeQuery(props.view, props.period), { variables: { address, first, skip, orderBy, orderDirection, now, proposalId, param, dateBegin, dateEnd } });

let isMounted = true;
useEffect(() => {
Expand Down Expand Up @@ -236,6 +227,7 @@ const Feed = (props) => {
}
if (proposal.cancelled) {
status = 'CANCELLED';
return null;
}

const noShares = (proposal.sharesRequested === '0');
Expand Down
Loading

0 comments on commit fc01635

Please sign in to comment.