Skip to content

Commit

Permalink
Fix issue with children list
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Oct 10, 2021
1 parent 4babb40 commit c2a2288
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/components/GrampsjsChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class GrampsjsChildren extends GrampsjsEditableTable {
row (obj, i, arr) {
return html`
<tr
@click=${() => this._handleClick(obj.gramps_id)}
@click=${() => this._handleClick(this.profile[i].gramps_id)}
class="${obj.gramps_id === this.highlightId ? 'highlight' : ''}"
>
<td>${genderIcon(this.profile[i]?.sex)}</td>
Expand Down
3 changes: 2 additions & 1 deletion src/components/GrampsjsObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ export class GrampsjsObject extends LitElement {
grampsId="${this.data.gramps_id}"
.strings=${this.strings}
?edit=${this.edit}
.familyList=${this.data?.extended?.family_list || []}
.familyList=${this.data?.extended?.families || []}
.parentFamilyList=${this.data?.extended?.parent_families || []}
.families=${this.data?.profile?.families || []}
.primaryParentFamily=${this.data?.profile?.primary_parent_family || {}}
.otherParentFamilies=${this.data?.profile?.other_parent_families || []}
Expand Down
44 changes: 28 additions & 16 deletions src/components/GrampsjsRelationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {renderPerson} from '../util.js'
import './GrampsjsChildren.js'

export class GrampsjsRelationships extends LitElement {

static get styles() {
static get styles () {
return [
sharedStyles,
css`
Expand All @@ -24,28 +23,30 @@ export class GrampsjsRelationships extends LitElement {
]
}

static get properties() {
static get properties () {
return {
grampsId: {type: String},
familyList: {type: Array},
families: {type: Array},
parentFamilies: {type: Array},
primaryParentFamily: {type: Object},
otherParentFamilies: {type: Array},
strings: {type: Object}
}
}

constructor() {
constructor () {
super()
this.grampsId = ''
this.familyList = []
this.parentFamilyList = []
this.families = []
this.otherParentFamilies = []
this.primaryParentFamily = {}
this.strings = {}
}

render() {
render () {
return html`
${this._renderFamily(this.primaryParentFamily, this._('Parents'), this._('Siblings'))}
${this.otherParentFamilies.map((familyProfile, i) => {
Expand All @@ -57,23 +58,27 @@ export class GrampsjsRelationships extends LitElement {
`
}

_renderFamily(familyProfile, parentTitle, childrenTitle) {
_renderFamily (familyProfile, parentTitle, childrenTitle) {
if (Object.keys(familyProfile).length === 0) {
return html``
}
return html`
<h3>${parentTitle} ${this._renderFamilyBtn(familyProfile.gramps_id)}</h3>
${familyProfile?.father?.gramps_id === this.grampsId || Object.keys(familyProfile?.father || {}).length === 0 ? '' : html`
${familyProfile?.father?.gramps_id === this.grampsId || Object.keys(familyProfile?.father || {}).length === 0
? ''
: html`
<p>${renderPerson(familyProfile.father)}</p>
`}
${familyProfile?.mother?.gramps_id === this.grampsId || Object.keys(familyProfile?.mother || {}).length === 0 ? '' : html`
${familyProfile?.mother?.gramps_id === this.grampsId || Object.keys(familyProfile?.mother || {}).length === 0
? ''
: html`
<p>${renderPerson(familyProfile.mother)}</p>
`}
${this._renderChildren(familyProfile, childrenTitle)}
`
}

_renderFamilyBtn(grampsId) {
_renderFamilyBtn (grampsId) {
return html`
<mwc-button
class="familybtn"
Expand All @@ -83,30 +88,37 @@ export class GrampsjsRelationships extends LitElement {
</mwc-button>`
}

_handleButtonClick(grampsId) {
_handleButtonClick (grampsId) {
this.dispatchEvent(new CustomEvent('nav', {
bubbles: true, composed: true, detail: {
bubbles: true,
composed: true,
detail: {
path: `family/${grampsId}`
}
}))
}

_renderChildren(obj, childrenTitle) {
_renderChildren (profile, childrenTitle) {
const allFamilies = [...this.familyList, ...this.parentFamilyList]
const [family] = allFamilies.filter(obj => obj.handle === profile.handle)
return html`
${obj?.children?.length ? html`
${profile?.children?.length
? html`
<h3>${childrenTitle}</h3>
<grampsjs-children
.profile=${obj?.children || []}
.profile=${profile?.children || []}
.data=${family.child_ref_list}
.strings=${this.strings}
highlightId="${this.grampsId}"
>
</grampsjs-children>
` : ''}
`
: ''}
`
}

_(s) {
_ (s) {
if (s in this.strings) {
return this.strings[s]
}
Expand Down

0 comments on commit c2a2288

Please sign in to comment.