From 11eca2cfa35855232aaa78b1b4e444d3e80b451c Mon Sep 17 00:00:00 2001 From: David Straub Date: Thu, 3 Dec 2020 20:49:06 +0100 Subject: [PATCH] Add profile photo to person page --- src/api.js | 30 +++++++++++++++-------------- src/components/GrampsJsImage.js | 16 ++++++++-------- src/components/GrampsjsObject.js | 20 +++++++++++++++++++ src/components/GrampsjsPerson.js | 33 +++++++++++++++++++++----------- 4 files changed, 66 insertions(+), 33 deletions(-) diff --git a/src/api.js b/src/api.js index d416a6d1..201d55b3 100644 --- a/src/api.js +++ b/src/api.js @@ -149,25 +149,27 @@ export async function apiGet(endpoint) { export function getMediaUrl(handle) { const jwt = localStorage.getItem('access_token'); if (jwt === null) { return '' } - return `${__APIHOST__}/media/${handle}/file?jwt=${jwt}` + return `${__APIHOST__}/api/media/${handle}/file?jwt=${jwt}` } export function getMediaUrlCropped(handle, rect) { - const jwt = localStorage.getItem('access_token'); - if (jwt === null) { return '' } - [x1, y1, x2, y2] = rect - return `${__APIHOST__}/media/${handle}/cropped/${x1}/${y1}/${x2}/${y2}?jwt=${jwt}` + const jwt = localStorage.getItem('access_token') + if (jwt === null) { + return '' + } + const [x1, y1, x2, y2] = rect + return `${__APIHOST__}/api/media/${handle}/cropped/${x1}/${y1}/${x2}/${y2}?jwt=${jwt}` } -export function getThumbnailUrl(handle, size) { - const jet = localStorage.getItem('access_token'); - if (jwt === null) { return '' } - return `${__APIHOST__}/media/${handle}/thumbnail/${size}?jwt=${jwt}` -} - -export function getThumbnailUrlCropped(handle, rect, size) { +export function getThumbnailUrl(handle, size, square=false) { const jwt = localStorage.getItem('access_token'); if (jwt === null) { return '' } - [x1, y1, x2, y2] = rect - return `${__APIHOST__}/media/${handle}/cropped/${x1}/${y1}/${x2}/${y2}/thumbnail/${size}?jwt=${jwt}` + return `${__APIHOST__}/api/media/${handle}/thumbnail/${size}?jwt=${jwt}&square=${square}` +} + +export function getThumbnailUrlCropped(handle, rect, size, square=false) { + const jwt = localStorage.getItem('access_token'); + if (jwt === null) { return '' } + const [x1, y1, x2, y2] = rect + return `${__APIHOST__}/api/media/${handle}/cropped/${x1}/${y1}/${x2}/${y2}/thumbnail/${size}?jwt=${jwt}&square=${square}` } diff --git a/src/components/GrampsJsImage.js b/src/components/GrampsJsImage.js index 73ac7c6d..9c382715 100644 --- a/src/components/GrampsJsImage.js +++ b/src/components/GrampsJsImage.js @@ -50,10 +50,10 @@ class GrampsjsImg extends LitElement { _renderImage() { return html` ` @@ -62,10 +62,10 @@ class GrampsjsImg extends LitElement { _renderImageCropped() { return html` ` diff --git a/src/components/GrampsjsObject.js b/src/components/GrampsjsObject.js index 325ce3c8..0663b6d7 100644 --- a/src/components/GrampsjsObject.js +++ b/src/components/GrampsjsObject.js @@ -43,12 +43,22 @@ export class GrampsjsObject extends LitElement { margin-top: 25px; } + #tabs { + clear: both; + } + mwc-tab-bar { border-top: solid #6D4C4133 1px; border-bottom: solid #6D4C4133 1px; margin-top: 15px; --mdc-tab-horizontal-padding: 16px; } + + #picture { + float: right; + margin-bottom: 20px; + margin-left: 40px; + } ` ]; } @@ -75,11 +85,17 @@ export class GrampsjsObject extends LitElement { return html`` } return html` +
+ ${this.renderPicture()} +
+ ${this.renderProfile()} ${this.renderTags()} +
${this.renderTabs()} +
${this.renderTabContent()} @@ -87,6 +103,10 @@ export class GrampsjsObject extends LitElement { `; } + renderPicture() { + return html`` + } + renderTabs() { const tabKeys = this._getTabs() if (!tabKeys.includes(this._currentTab)) { diff --git a/src/components/GrampsjsPerson.js b/src/components/GrampsjsPerson.js index 3a271423..04cc90b8 100644 --- a/src/components/GrampsjsPerson.js +++ b/src/components/GrampsjsPerson.js @@ -1,5 +1,6 @@ import { html, css } from 'lit-element'; import { GrampsjsObject } from './GrampsjsObject.js' +import './GrampsJsImage.js' export class GrampsjsPerson extends GrampsjsObject { @@ -7,30 +8,40 @@ export class GrampsjsPerson extends GrampsjsObject { return [ super.styles, css` - :host { - } `]; } renderProfile() { return html`

${this._displayName()}

- `; } + renderPicture() { + if (!this.data?.media_list?.length) { + return html`` + } + const ref = this.data.media_list[0] + const obj = this.data.extended.media[0] + return html` + + ` + } + _displayName() { if (!this.data.profile) { return '' } - const surname = this.data.profile.name_surname || 'NN'; - const given = this.data.profile.name_given || 'NN'; - return html`${surname}, ${given}` + const surname = this.data.profile.name_surname || html`…` + const given = this.data.profile.name_given || html`…` + return html`${given} ${surname}` } _getProfileEvent(type) {