From b9778da550d9c38544a2db92947da7057ce9762c Mon Sep 17 00:00:00 2001 From: dasai tamago Date: Sat, 16 Nov 2019 02:56:45 +0000 Subject: [PATCH 1/5] minor update on fav-district --- web/src/locales/en/translation.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/src/locales/en/translation.json b/web/src/locales/en/translation.json index 91705ecd..188a449c 100644 --- a/web/src/locales/en/translation.json +++ b/web/src/locales/en/translation.json @@ -101,8 +101,7 @@ "battleground.alert.text3": "This constituency is 2019", "battleground.button.hide": "Hide Map", "battleground.button.show": "Show Map", - "battleground.button.follow": "Follow this District⭐", - "battleground.button.unfollow": "Unfollow this District", + "disclaimer.paragraph1": "candidates for political camps, reflecting their views on political issues. Generally speaking, each person has a different position on each topic and it is difficult to summarize the background of the candidate in one or two terms.", "disclaimer.header.text1": "Category of camps (2019 District Council Election)", "disclaimer.paragraph2.segment1": "The political camp of candidates for the District Council election was taken from", From 0e24832fbd03dc38bd9c88a9295cd415250d68fc Mon Sep 17 00:00:00 2001 From: dasai tamago Date: Tue, 19 Nov 2019 13:53:47 +0000 Subject: [PATCH 2/5] modified the fav-district page and functions --- .../components/pages/fav-district/index.js | 97 ++++++++++++++++--- web/src/queries/gql.js | 43 ++++++-- 2 files changed, 117 insertions(+), 23 deletions(-) diff --git a/web/src/components/pages/fav-district/index.js b/web/src/components/pages/fav-district/index.js index 241e0057..060d276e 100644 --- a/web/src/components/pages/fav-district/index.js +++ b/web/src/components/pages/fav-district/index.js @@ -1,19 +1,27 @@ import React, { Component } from 'react' -import styled from 'styled-components' import { Query } from 'react-apollo' import { QUERY_GET_CONSTITUENCIES_BY_DISTRICT_CODES } from 'queries/gql' -import ConstituencyCard from 'components/organisms/ConstituencyCard' -import { Typography } from '@material-ui/core' -import Paper from '@material-ui/core/Paper' +import ConstituencyTableContent from 'components/molecules/constituency/ConstituencyTableContent' +import CampSelector from 'components/atoms/CampSelector' import { Loading } from 'components/atoms/Loading' import { withTranslation } from 'react-i18next' import localforage from 'localforage' +import { Container, Typography } from '@material-ui/core' +import Table from '@material-ui/core/Table' +import TableBody from '@material-ui/core/TableBody' +import TableHead from '@material-ui/core/TableHead' +import TableCell from '@material-ui/core/TableCell' +import TableRow from '@material-ui/core/TableRow' +import { HtmlTooltip } from 'components/atoms/Tooltip' +import styled from 'styled-components' -const Container = styled(Paper)` +const StyledTableCell = styled(TableCell)` && { - width: 100%; - padding: 16px; - box-shadow: none; + padding: 6px 0px 6px 16px; + :last-child { + padding: 6px 0px 6px 16px; + } + line-height: 1rem; } ` @@ -22,6 +30,12 @@ class FavDistrictListPage extends Component { super(props) this.state = { battlegroundArr: [], + checked: { + democracy: true, + establishment: true, + others: true, + blank: true, + }, } localforage.getItem('battleground').then(value => { @@ -29,6 +43,11 @@ class FavDistrictListPage extends Component { }) } + handleChange(democracy, establishment, others, blank) { + const checked = { democracy, establishment, others, blank } + this.setState({ ...this.state, checked: checked }) + } + render() { const { t } = this.props @@ -41,20 +60,68 @@ class FavDistrictListPage extends Component { if (loading) return if (error) return `Error! ${error}` + const constituencies = data.dcd_constituencies + const { democracy, establishment, others, blank } = this.state.checked return ( - <> +
+ {`${data.dcd_constituencies.length}`} {t('no_of_districts')} - - {data.dcd_constituencies.map(c => ( - - ))} - - + + + + + {/* 候選人 */} + {t('candidates')} + + + {/* 相關組織{' '} */} + {t('relatedOrganizations')}{' '} + + + + {/* 報稱政治聯繫{' '} */} + {t('reportedPoliticalAffiliation')}{' '} + + + {/* 得票 */} + + + + {constituencies.map(constituency => { + return ( + + ) + })} + +
+
) }} diff --git a/web/src/queries/gql.js b/web/src/queries/gql.js index e4c71f0c..0bb7d9d2 100644 --- a/web/src/queries/gql.js +++ b/web/src/queries/gql.js @@ -88,14 +88,41 @@ query($year: Int!, $code: String!) { ` export const QUERY_GET_CONSTITUENCIES_BY_DISTRICT_CODES = gql` -query($year: Int!, $dc: [String!]) { - dcd_constituencies( - where: { year: { _eq: $year }, code: { _in: $dc } } - order_by: {code: asc } - ) { - ${CONSTITUENCIES_DATA} - } -} + query($year: Int!, $dc: [String!]) { + dcd_constituencies( + where: { year: { _eq: $year }, code: { _in: $dc } } + order_by: { code: asc } + ) { + id + name_zh + name_en + code + candidates( + where: { year: { _eq: $year } } + order_by: { candidate_number: asc } + ) { + candidate_number + is_won + political_affiliation + political_affiliation_zh + political_affiliation_en + election_type + camp + person { + id + uuid + name_zh + name_en + related_organization + } + nominate_status + tags { + tag + type + } + } + } + } ` export const QUERY_GET_CONSTITUENCIES_BY_TAG = gql` From 101e8f4258e3fab3a7e4cbc1e21268cc8e66344e Mon Sep 17 00:00:00 2001 From: dasai tamago Date: Tue, 19 Nov 2019 15:18:13 +0000 Subject: [PATCH 3/5] add page favourite candidate --- web/src/App.js | 12 +++++++ web/src/components/organisms/SearchMenu.js | 11 ++++++ web/src/components/pages/profile/index.js | 39 ++++++++++++++++++++ web/src/locales/en/translation.json | 6 +++- web/src/locales/zh/translation.json | 3 ++ web/src/queries/gql.js | 41 ++++++++++++++++++++++ 6 files changed, 111 insertions(+), 1 deletion(-) diff --git a/web/src/App.js b/web/src/App.js index 8034e0ec..9c1d0e92 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -40,6 +40,10 @@ const FavDistrictListPage = loadable(() => import(/* webpackPrefetch: true */ 'components/pages/fav-district') ) +const FavCandidateListPage = loadable(() => + import(/* webpackPrefetch: true */ 'components/pages/fav-candidate') +) + const NotfoundPage = loadable(() => import(/* webpackPrefetch: true */ 'components/pages/notfound') ) @@ -144,6 +148,10 @@ const LangSwitch = props => { path={`${path}/SelectedDistrict`} component={withTracker(FavDistrictListPage)} /> + @@ -212,6 +220,10 @@ const App = props => { path="/SelectedDistrict" component={withTracker(FavDistrictListPage)} /> + diff --git a/web/src/components/organisms/SearchMenu.js b/web/src/components/organisms/SearchMenu.js index 0fa299b9..0ac50251 100644 --- a/web/src/components/organisms/SearchMenu.js +++ b/web/src/components/organisms/SearchMenu.js @@ -85,6 +85,17 @@ const SearchMenu = props => { + + goToPage(`/${currentLanguage}/SelectedCandidate`)} + > + {/* 己關注候選人 */} + {t('searchMenu.text5')} + + + { + this.setState({ candidateArr: value === null ? [] : value }) + }) } async componentDidMount() {} @@ -367,6 +383,21 @@ class ProfilePage extends Component { return null } + TriggerFavCandidate = candidateId => { + const cid = candidateId + var candidateArr = this.state.candidateArr + if (this.state.candidateArr.find(code => code === cid)) { + candidateArr = candidateArr.filter((value, index, arr) => { + return value !== cid + }) + this.setState({ candidateArr: candidateArr }) + } else { + candidateArr.push(cid) + this.setState({ candidateArr: candidateArr }) + } + localforage.setItem('candidate', candidateArr.sort()) + } + render() { const { match: { @@ -654,6 +685,14 @@ class ProfilePage extends Component { )} + this.TriggerFavCandidate(person.id)} + > + {this.state.candidateArr.find(id => id === person.id) + ? t('candidate.button.unfollow') + : t('candidate.button.follow')} + + Date: Tue, 19 Nov 2019 23:38:40 +0000 Subject: [PATCH 4/5] add page favourite candidate --- goorm.manifest | 1 + package-lock.json | 3 + .../components/pages/fav-candidate/index.js | 132 ++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100755 goorm.manifest create mode 100644 package-lock.json create mode 100644 web/src/components/pages/fav-candidate/index.js diff --git a/goorm.manifest b/goorm.manifest new file mode 100755 index 00000000..f725d875 --- /dev/null +++ b/goorm.manifest @@ -0,0 +1 @@ +{"author":"dasaitamago_ke78fcizy","name":"district-councils-dashboard","type":"nodejs","detailedtype":"default","description":"Development area","date":"2019-11-06T08:02:29.000Z","plugins":{"goorm.plugin.nodejs":[{"plugin.nodejs.main":"main","plugin.nodejs.source_path":"./","plugin.nodejs.run_option":"","plugin.nodejs.run_on":"console","plugin.nodejs.log_path":"./server.log","name":"nodejs"}]},"is_user_plugin":false,"storage":"container","project_domain":[{"id":"dasaitamago_ke78fcizy","url":"hk-sth-jdhbn.run.goorm.io","port":"3000"}],"author_email":"dasaitamago@gmail.com","author_name":"dasai tamago","ignore_patterns":[]} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..48e341a0 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/web/src/components/pages/fav-candidate/index.js b/web/src/components/pages/fav-candidate/index.js new file mode 100644 index 00000000..8ff65939 --- /dev/null +++ b/web/src/components/pages/fav-candidate/index.js @@ -0,0 +1,132 @@ +import React, { Component } from 'react' +import { Query } from 'react-apollo' +import { QUERY_GET_CANDIDATES_BY_IDS } from 'queries/gql' +import ConstituencyTableContent from 'components/molecules/constituency/ConstituencyTableContent' +import CampSelector from 'components/atoms/CampSelector' +import { Loading } from 'components/atoms/Loading' +import { withTranslation } from 'react-i18next' +import localforage from 'localforage' +import { Container, Typography } from '@material-ui/core' +import Table from '@material-ui/core/Table' +import TableBody from '@material-ui/core/TableBody' +import TableHead from '@material-ui/core/TableHead' +import TableCell from '@material-ui/core/TableCell' +import TableRow from '@material-ui/core/TableRow' +import { HtmlTooltip } from 'components/atoms/Tooltip' +import styled from 'styled-components' + +const StyledTableCell = styled(TableCell)` + && { + padding: 6px 0px 6px 16px; + :last-child { + padding: 6px 0px 6px 16px; + } + line-height: 1rem; + } +` + +class FavCandidateListPage extends Component { + constructor(props) { + super(props) + this.state = { + candidateArr: [], + checked: { + democracy: true, + establishment: true, + others: true, + blank: true, + }, + } + + localforage.getItem('candidate').then(value => { + this.setState({ candidateArr: value === null ? [] : value }) + }) + } + + handleChange(democracy, establishment, others, blank) { + const checked = { democracy, establishment, others, blank } + this.setState({ ...this.state, checked: checked }) + } + + render() { + const { t } = this.props + + return ( + + {({ loading, error, data }) => { + if (loading) return + if (error) return `Error! ${error}` + + const constituencies = data.dcd_constituencies + const { democracy, establishment, others, blank } = this.state.checked + return ( +
+ + + + {`${data.dcd_constituencies.length}`} + {t('no_of_districts')} + + + + + + + {/* 候選人 */} + {t('candidates')} + + + {/* 相關組織{' '} */} + {t('relatedOrganizations')}{' '} + + + + {/* 報稱政治聯繫{' '} */} + {t('reportedPoliticalAffiliation')}{' '} + + + {/* 得票 */} + + + + {constituencies.map(constituency => { + return ( + + ) + })} + +
+
+ ) + }} +
+ ) + } +} + +export default withTranslation()(FavCandidateListPage) From 5a0f9e9213cdb62fa451071fa9a51633382cbf7b Mon Sep 17 00:00:00 2001 From: dasaitamago <57379117+dasaitamago@users.noreply.github.com> Date: Wed, 20 Nov 2019 07:41:48 +0800 Subject: [PATCH 5/5] Delete redundant --- goorm.manifest | 1 - 1 file changed, 1 deletion(-) delete mode 100755 goorm.manifest diff --git a/goorm.manifest b/goorm.manifest deleted file mode 100755 index f725d875..00000000 --- a/goorm.manifest +++ /dev/null @@ -1 +0,0 @@ -{"author":"dasaitamago_ke78fcizy","name":"district-councils-dashboard","type":"nodejs","detailedtype":"default","description":"Development area","date":"2019-11-06T08:02:29.000Z","plugins":{"goorm.plugin.nodejs":[{"plugin.nodejs.main":"main","plugin.nodejs.source_path":"./","plugin.nodejs.run_option":"","plugin.nodejs.run_on":"console","plugin.nodejs.log_path":"./server.log","name":"nodejs"}]},"is_user_plugin":false,"storage":"container","project_domain":[{"id":"dasaitamago_ke78fcizy","url":"hk-sth-jdhbn.run.goorm.io","port":"3000"}],"author_email":"dasaitamago@gmail.com","author_name":"dasai tamago","ignore_patterns":[]} \ No newline at end of file