Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions thingmenn-frontend/src/components/about/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class About extends React.Component {
</p>
<p>
Markmið vefsins er að sækja gögn sem finna má á vef{' '}
<a className="u-link" href="http://www.althingi.is/altext/xml/">
<a className="u-link" href="http://www.althingi.is/altext/xml/" target="_blank" rel="noopener noreferrer">
Alþingis
</a>
, vinna úr þeim og setja fram á skemmtilegan, fræðandi og helst af
Expand Down Expand Up @@ -43,21 +43,23 @@ export default class About extends React.Component {
className="u-link"
href="http://twitter.com/baerinq"
target="_blank"
rel="noopener noreferrer"
>
Bæring Gunnar Steinþórsson
</a>
.
</p>
<p>
Sérstakar þakkir fá samstarfsfélagar mínir hjá{' '}
<a className="u-link" href="http://aranja.com" target="_blank">
<a className="u-link" href="http://aranja.com" target="_blank" rel="noopener noreferrer">
Aranja
</a>
;<br />{' '}
<a
className="u-link"
href="http://twitter.com/dbjcodes"
target="_blank"
rel="noopener noreferrer"
>
Davíð Bachmann Jóhannesson
</a>
Expand All @@ -66,6 +68,7 @@ export default class About extends React.Component {
className="u-link"
href="http://twitter.com/herrhelms"
target="_blank"
rel="noopener noreferrer"
>
Sebastian Helms
</a>{' '}
Expand All @@ -74,6 +77,7 @@ export default class About extends React.Component {
className="u-link"
href="http://twitter.com/thorsteinsson"
target="_blank"
rel="noopener noreferrer"
>
Ægir Giraldo Þorsteinsson
</a>{' '}
Expand Down
72 changes: 33 additions & 39 deletions thingmenn-frontend/src/components/mp-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export default class MpDetails extends React.Component {
super(props)

this.state = {
mp: { description: {}, lthings: [] },
lthing: null,
lthings: [],
lthingLookup: {},
mp: { description: {}, terms: [] },
params: {},
terms: [],
voteSummary: { votePercentages: [], voteSummary: [] },
speechSummary: [],
documentSummary: [],
Expand All @@ -46,124 +45,120 @@ export default class MpDetails extends React.Component {
}

componentWillReceiveProps(nextProps) {
this.getData(nextProps.routeParams.mpId, nextProps.routeParams.lthing)
this.getData(nextProps.routeParams.mpId, nextProps.routeParams)
}

getData(id, lthing) {
getData(id, nextParams) {
// TODO: HOC withData that injects correct props into components

const mpId = id || this.props.params.mpId
const lthingId = lthing || this.props.params.lthing
const params = nextParams || this.props.params

if (this.state.mp.id === mpId) return

mpService.getMpDetailsByLthing(mpId, lthingId).then((mp) => {
mpService.getMpDetails(mpId, params).then((mp) => {
this.setState(() => ({
mp,
}))
})

mpSummaryService
.getMpVoteSummaryByLthing(mpId, lthingId)
.getMpVoteSummary(mpId, params)
.then((voteSummary) => {
this.setState(() => ({
voteSummary,
}))
})

mpSummaryService
.getMpSpeechSummaryByLthing(mpId, lthingId)
.getMpSpeechSummary(mpId, params)
.then((speechSummary) => {
this.setState(() => ({
speechSummary,
}))
})

mpSummaryService
.getMpDocumentSummaryByLthing(mpId, lthingId)
.getMpDocumentSummary(mpId, params)
.then((documentSummary) => {
this.setState(() => ({
documentSummary,
}))
})

mpSummaryService
.getMpVotePositionsByLthing(mpId, lthingId)
.getMpVotePositions(mpId, params)
.then((votePositions) => {
this.setState(() => ({
votePositions,
}))
})

mpSummaryService
.getMpSpeechPositionsByLthing(mpId, lthingId)
.getMpSpeechPositions(mpId, params)
.then((speechPositions) => {
this.setState(() => ({
speechPositions,
}))
})

mpSummaryService
.getMpDocumentPositionsByLthing(mpId, lthingId)
.getMpDocumentPositions(mpId, params)
.then((documentPositions) => {
this.setState(() => ({
documentPositions,
}))
})

mpSummaryService
.getMpAbsentSummaryByLthing(mpId, lthingId)
.getMpAbsentSummary(mpId, params)
.then((absentSummary) => {
this.setState(() => ({
absentSummary,
}))
})

mpService.getSimilarMpsByLthing(mpId, lthingId).then((similarMps) => {
mpService.getSimilarMps(mpId, params).then((similarMps) => {
this.setState(() => ({
similarMps,
}))
})

mpService.getDifferentMpsByLthing(mpId, lthingId).then((differentMps) => {
mpService.getDifferentMps(mpId, params).then((differentMps) => {
this.setState(() => ({
differentMps,
}))
})

totalsService.getLthings().then((lthings) => {
const lthingLookup = {}
lthings.forEach((lthing) => (lthingLookup[lthing.id] = lthing))
totalsService.getTerms().then((terms) => {
this.setState(() => ({
lthings,
lthingLookup,
terms,
}))
})
}

generateLthingList(mp, lthings, lthingLookup) {
generateTermsList(mp, terms) {
const initialList = [
{
name: 'Samtölur',
url: `/thingmenn/${mp.id}/thing/allt`,
url: `/thingmenn/${mp.id}/kjortimabil/allt`,
},
]

if (!mp.lthings.length || !lthings.length) {
if (!mp.terms || !mp.terms.length || !terms.length) {
return initialList
}

const lthingsFormatted = mp.lthings.map((lthingInfo) => ({
year: lthingLookup[lthingInfo.lthing].start.split('.')[2],
thing: lthingInfo.lthing,
url: `/thingmenn/${mp.id}/thing/${lthingInfo.lthing}`,
const termsFormatted = mp.terms.map((termInfo) => ({
name: termInfo.id,
url: `/thingmenn/${mp.id}/kjortimabil/${termInfo.id}`,
}))

return initialList.concat(lthingsFormatted)
return initialList.concat(termsFormatted)
}

getDividerSize(tabName, lthing) {
if (lthing === 'allt') {
getDividerSize(tabName, params) {
if (params.term === 'allt' || params.lthing === 'allt') {
if (tabName === 'speeches') {
return 3
} else if (tabName === 'documents') {
Expand All @@ -183,8 +178,7 @@ export default class MpDetails extends React.Component {
render() {
const {
mp,
lthings,
lthingLookup,
terms,
voteSummary,
speechSummary,
documentSummary,
Expand All @@ -195,12 +189,12 @@ export default class MpDetails extends React.Component {
differentMps,
} = this.state

const lthing = this.props.params.lthing
const { params } = this.props

return (
<div className="fill">
<DetailsMenu
menuItems={this.generateLthingList(mp, lthings, lthingLookup)}
menuItems={this.generateTermsList(mp, terms)}
/>
<DetailsHeader {...mp} description={mp.description.asMp} />
<div className="Details">
Expand All @@ -214,7 +208,7 @@ export default class MpDetails extends React.Component {
title="Samherjar"
subTitle="Eins greidd atkvæði"
friends={similarMps.slice(0, 10)}
lthing={lthing}
params={params}
isDisplayingFriends={true}
/>
</div>
Expand Down Expand Up @@ -264,7 +258,7 @@ export default class MpDetails extends React.Component {
<div className="Topic-column">
<h1 className="Topic-heading">Ræður eftir flokkum</h1>
<Items
divider={this.getDividerSize('speeches', lthing)}
divider={this.getDividerSize('speeches', params)}
items={speechPositions}
/>
</div>
Expand All @@ -277,7 +271,7 @@ export default class MpDetails extends React.Component {
<div className="Topic-column">
<h1 className="Topic-heading">Þingskjöl eftir flokkum</h1>
<Items
divider={this.getDividerSize('documents', lthing)}
divider={this.getDividerSize('documents', params)}
items={documentPositions}
/>
</div>
Expand Down
44 changes: 20 additions & 24 deletions thingmenn-frontend/src/components/mps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ let searchInput = ''

const initialLthingsMenuList = [
{
name: 'Öll þing',
url: '/thing/allt',
name: 'Öll kjörtímabil',
url: '/kjortimabil/allt',
},
]

Expand All @@ -22,34 +22,33 @@ export default class Mps extends React.Component {
super(props)

this.state = {
lthing: null,
params: null,
mps: [],
lthings: [],
terms: [],
searchInput: '',
sortByParty: false,
}
}

componentWillMount() {
const lthing = this.props.params.lthing
this.getData(lthing)
const { lthing, term } = this.props.params
this.getData({ lthing, term })
this.setSorting(this.props)
}

componentWillReceiveProps(nextProps) {
const lthing = nextProps.params.lthing

this.getData(lthing)
const { lthing, term } = nextProps.params
this.getData({ lthing, term })
this.setSorting(this.props)
}

getData(lthing) {
mpService.getMpsByLthing(lthing).then((mps) => {
this.setState(() => ({ mps, lthing }))
getData(params) {
mpService.getMps(params).then((mps) => {
this.setState(() => ({ mps, params }))
})

totalService.getLthings().then((lthings) => {
this.setState(() => ({ lthings }))
totalService.getTerms().then((terms) => {
this.setState(() => ({ terms }))
})
}

Expand Down Expand Up @@ -82,27 +81,24 @@ export default class Mps extends React.Component {
}

render() {
const { mps, sortByParty, lthing, lthings } = this.state
const { mps, params, terms } = this.state

const items = mps
.filter(this.searchFilter.bind(this))
.sort(this.sortItem.bind(this))

const lthingsFormatted = lthings.map((lthing) => ({
year: lthing.start.split('.')[2],
thing: lthing.id,
url: `/thing/${lthing.id}`,
}))

const lthingsToRender = initialLthingsMenuList.concat(lthingsFormatted)
const termsToRender = initialLthingsMenuList.concat(terms.map((term) => ({
name: term.id,
url: `/kjortimabil/${term.id}`,
})))

return (
<div className="fill">
<h1 className="title">Allir þingmenn</h1>
<DetailsMenu menuItems={lthingsToRender} />
<DetailsMenu menuItems={termsToRender} />
<List>
{items.map((mp) => (
<Mp key={mp.id} lthing={lthing} {...mp} />
<Mp key={mp.id} params={params} {...mp} />
))}
</List>
</div>
Expand Down
Loading