diff --git a/core/language/us.json b/core/language/us.json index 958573ae..1dd2dbbb 100644 --- a/core/language/us.json +++ b/core/language/us.json @@ -1231,6 +1231,9 @@ "profile12": "Field name", "profile13": "Fill out", "profile14": "Activity", - "profile15": "No data" + "profile15": "No data", + "profile16": "This name has no profile", + "profile17": "Unable to fetch profile", + "profile18": "Open profile" } } \ No newline at end of file diff --git a/core/src/components/friends-view/profile.js b/core/src/components/friends-view/profile.js index f71f1354..da62ec58 100644 --- a/core/src/components/friends-view/profile.js +++ b/core/src/components/friends-view/profile.js @@ -43,7 +43,8 @@ class ProfileQdn extends connect(store)(LitElement) { dialogOpenedProfile: {type: Boolean}, profileDataVisiting: {type: Object}, nameVisiting: {type: String}, - hasName: {type: Boolean} + hasName: {type: Boolean}, + resourceExistsVisiting: {type:Boolean} }; } @@ -53,6 +54,7 @@ class ProfileQdn extends connect(store)(LitElement) { this.getProfile = this.getProfile.bind(this); this._handleQortalRequestSetData = this._handleQortalRequestSetData.bind(this); + this._handleOpenVisiting = this._handleOpenVisiting.bind(this) this.setValues = this.setValues.bind(this); this.saveToQdn = this.saveToQdn.bind(this); this.syncPercentage = 0; @@ -76,6 +78,7 @@ class ProfileQdn extends connect(store)(LitElement) { this.profileDataVisiting = null; this.nameVisiting = "" this.hasName = false + this.resourceExistsVisiting = undefined } static styles = css` @@ -173,7 +176,7 @@ class ProfileQdn extends connect(store)(LitElement) { border-radius: 15px; padding: 25px; box-shadow: 0px 10px 15px rgba(0, 0, 0, 0.1); - display: block !important + display: block !important; } .full-info-logo { @@ -193,6 +196,7 @@ class ProfileQdn extends connect(store)(LitElement) { display:flex; flex-direction: column; align-items: flex-start; + min-height: 55vh; max-height: 55vh; overflow: auto; } @@ -361,6 +365,62 @@ class ProfileQdn extends connect(store)(LitElement) { } } + async getVisitingProfile(name) { + console.log('name2', name) + try { + this.isLoadingVisitingProfile = true + this.nameVisiting = name + this.imageUrl = `${this.nodeUrl}/arbitrary/THUMBNAIL/${name}/qortal_avatar?async=true&apiKey=${this.myNode.apiKey}`; + this.error = ''; + const url = `${this.nodeUrl}/arbitrary/resources/search?service=DOCUMENT&identifier=qortal_profile&name=${name}&prefix=true&exactmatchnames=true&excludeblocked=true&limit=20`; + const res = await fetch(url); + let data = ''; + try { + console.log({ res }); + data = await res.json(); + console.log({ data }); + if (Array.isArray(data)) { + data = data.filter( + (item) => item.identifier === 'qortal_profile' + ); + + if (data.length > 0) { + this.resourceExistsVisiting = true; + const dataItem = data[0]; + try { + const response = await this.getRawData(dataItem); + console.log({ response }); + if (response.wallets) { + this.profileDataVisiting = response + // this.setValues(response, dataItem); + } else { + this.error = 'Cannot get saved user settings'; + } + } catch (error) { + console.log({ error }); + this.error = 'Cannot get saved user settings'; + } + } else { + this.resourceExistsVisiting = false; + } + } else { + this.error = 'Unable to perform query'; + } + } catch (error) { + console.log({ error }); + data = { + error: 'No resource found', + }; + } + + } catch (error) { + console.log({ error }); + } finally { + this.isLoadingVisitingProfile = false + + } + } + async getProfile() { try { const arbFee = await this.getArbitraryFee(); @@ -640,12 +700,29 @@ class ProfileQdn extends connect(store)(LitElement) { } } + _handleOpenVisiting(event){ + try { + console.log({event}) + const name = event.detail; + console.log({name}) + // if(!name) return + this.getVisitingProfile(name) + this.dialogOpenedProfile = true + } catch (error) { + + } + } + connectedCallback() { super.connectedCallback(); window.addEventListener( 'qortal-request-set-profile-data', this._handleQortalRequestSetData ); + window.addEventListener( + 'open-visiting-profile', + this._handleOpenVisiting + ); } disconnectedCallback() { @@ -653,6 +730,10 @@ class ProfileQdn extends connect(store)(LitElement) { 'qortal-request-set-profile-data', this._handleQortalRequestSetData ); + window.removeEventListener( + 'open-visiting-profile', + this._handleOpenVisiting + ); super.disconnectedCallback(); } @@ -690,6 +771,26 @@ class ProfileQdn extends connect(store)(LitElement) { openEdit(){ this.isOpenProfileModalUpdate = !this.isOpenProfileModalUpdate; } + + onCloseVisitingProfile(){ + this.profileDataVisiting = null; + this.nameVisiting = "" + this.imageUrl = ''; + this.resourceExistsVisiting = undefined + } + + updated(changedProperties){ + if ( + changedProperties && + changedProperties.has('dialogOpenedProfile') && + this.dialogOpenedProfile === false + ) { + + const prevVal = changedProperties.get('dialogOpenedProfile') + if(prevVal === true) this.onCloseVisitingProfile() + } + + } render() { console.log('sup profile2', this.error, this.profileDataVisiting, this.dialogOpenedProfile ); return html` @@ -846,20 +947,35 @@ class ProfileQdn extends connect(store)(LitElement) { - ${this.profileDataVisiting && this.dialogOpenedProfile ? html` + ${this.dialogOpenedProfile ? html` -

${this.name}

+

${this.nameVisiting}

+ ${this.isLoadingVisitingProfile ? html` +
+ +
+ ` : this.resourceExistsVisiting === false ? html` +
+

${translate('profile.profile16')}

+
+ ` : this.profileDataVisiting === null ? html` +
+

${translate('profile.profile17')}

+
+ ` : html`

${translate('profile.profile4')}

${this.profileDataVisiting.tagline || translate('profile.profile15')}

${translate('profile.profile5')}

@@ -872,6 +988,8 @@ class ProfileQdn extends connect(store)(LitElement) {

` })} + `} +
diff --git a/plugins/plugins/core/components/UserInfo/UserInfo.js b/plugins/plugins/core/components/UserInfo/UserInfo.js index fc9685a2..13a7fb96 100644 --- a/plugins/plugins/core/components/UserInfo/UserInfo.js +++ b/plugins/plugins/core/components/UserInfo/UserInfo.js @@ -51,6 +51,16 @@ export class UserInfo extends LitElement { return imageHTMLRes } + openProfile(){ + try { + const customEvent = new CustomEvent('open-visiting-profile', { + detail: this.userName + }); + window.parent.dispatchEvent(customEvent); + + } catch (error) { /* empty */ } + } + render() { let avatarImg = "" @@ -84,7 +94,7 @@ export class UserInfo extends LitElement { avatar ` : ""} -
+
+ ${this.userName ? html` +
{ + setTimeout(() => { + this.openProfile() + }, 250); + this.setOpenUserInfo(false) + + + }}> + ${translate("profile.profile18")} +
+ ` : ''} +
` }