From 6ad1ce65170ee9c2008e8b31194589614fe41979 Mon Sep 17 00:00:00 2001 From: Mel Heisey Date: Wed, 14 Apr 2021 00:25:40 -0700 Subject: [PATCH 1/4] use profile sections in side menu design choice to stick the information in session, mostly because I didn't want to put any load functionality in a header --- static/js/com/header.js | 21 +++++++++++++++------ static/js/lib/session.js | 6 +++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/static/js/com/header.js b/static/js/com/header.js index c1a36a5c..20b20781 100644 --- a/static/js/com/header.js +++ b/static/js/com/header.js @@ -9,6 +9,8 @@ import { CreateCommunityPopup } from './popups/create-community.js' import * as toast from './toast.js' import './button.js' +import {DEFAULT_CITIZEN_PROFILE_SECTIONS} from '../lib/const.js' + const CHECK_NOTIFICATIONS_INTERVAL = 10e3 export class Header extends LitElement { @@ -31,11 +33,14 @@ export class Header extends LitElement { this.isMenuOpen = false this.unreadNotificationsCount = 0 this.community = undefined + this.sections = DEFAULT_CITIZEN_PROFILE_SECTIONS + document.body.addEventListener('open-main-menu', e => { this.isMenuOpen = true }) setInterval(this.checkNotifications.bind(this), CHECK_NOTIFICATIONS_INTERVAL) - session.onChange(() => this.requestUpdate()) + session.onChange(() => this.requestUpdate()) + session.onSecondaryState(() => this.requestUpdate()) } firstUpdated () { @@ -110,11 +115,15 @@ export class Header extends LitElement { My Profile - - - My Inventory - -
+ ${session.mySections?.length > 0 ? repeat(session.mySections, (section) => { + return html` + + ${section.label} + ` + }) : ''} +
m.value.community) myFollowers = followers?.followers myFollowing = follows?.entries?.map(e => e.value.subject.userId) || [] + + let userProfile = await ctzn.getProfile(info.userId).catch(e => undefined) + mySections = userProfile?.value?.sections || DEFAULT_CITIZEN_PROFILE_SECTIONS emitter.dispatchEvent(new Event('secondary-state')) } From 383563d56c6a7d84a75f6d0d56ac6908b68185d0 Mon Sep 17 00:00:00 2001 From: Mel Heisey Date: Wed, 14 Apr 2021 06:57:00 -0700 Subject: [PATCH 2/4] fix render sidebar if not logged in --- static/js/com/header.js | 8 ++++++-- static/js/lib/api.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/static/js/com/header.js b/static/js/com/header.js index 20b20781..64676b92 100644 --- a/static/js/com/header.js +++ b/static/js/com/header.js @@ -41,6 +41,7 @@ export class Header extends LitElement { setInterval(this.checkNotifications.bind(this), CHECK_NOTIFICATIONS_INTERVAL) session.onChange(() => this.requestUpdate()) session.onSecondaryState(() => this.requestUpdate()) + // TODO make sure sections are reloaded on 'profile-updated' } firstUpdated () { @@ -100,6 +101,7 @@ export class Header extends LitElement { Communities + ${info ? html`
${section.label} ` - }) : ''} + }) : ''}
+ `: ''}
+ ${!info ? '' : html`
${displayNames.render(f)} `)} -
+ `} ${this.isMenuOpen ? html`
Date: Wed, 14 Apr 2021 07:48:02 -0700 Subject: [PATCH 3/4] still can't view profiles w/o logging in; render more useful error message --- static/js/com/custom-html.js | 3 +++ static/js/views/user.js | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/static/js/com/custom-html.js b/static/js/com/custom-html.js index eb3426bb..5a23de45 100644 --- a/static/js/com/custom-html.js +++ b/static/js/com/custom-html.js @@ -65,6 +65,9 @@ export class CustomHtml extends LitElement { this.loadedHtml = this.html return } + if (!session.ctzn?.blob) { + this.currentError = "Custom Html could not be loaded. If you are not logged in, please join a server to see this profile." + } try { let base64buf = (await session.ctzn.blob.get(this.userId, this.blobName))?.buf if (base64buf) this.loadedHtml = decodeBase64(base64buf) diff --git a/static/js/views/user.js b/static/js/views/user.js index 2f6ab236..9b236d19 100644 --- a/static/js/views/user.js +++ b/static/js/views/user.js @@ -262,11 +262,11 @@ class CtznUser extends LitElement { this.roles = roles console.log({userProfile: this.userProfile, members, roles}) - if (session.isActive() && !this.amIFollowing && this.isMembershipClosed) { + if (session.isActive() && session.ctzn && !this.amIFollowing && this.isMembershipClosed) { let inviteEntry = await session.ctzn.db(this.userId) .table('ctzn.network/community-invite') - .get(session.info.userId) - .catch(e => undefined) + ?.get(session.info.userId) + .catch((_) => undefined) this.isUserInvited = !!inviteEntry?.value } } From 4631db5e232fafddf5e54cdd4fb6b8e0a8f5271e Mon Sep 17 00:00:00 2001 From: Mel Heisey Date: Wed, 14 Apr 2021 07:58:57 -0700 Subject: [PATCH 4/4] fixup! still can't view profiles w/o logging in; render more useful error message --- static/js/com/custom-html.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/js/com/custom-html.js b/static/js/com/custom-html.js index 5a23de45..aed1b559 100644 --- a/static/js/com/custom-html.js +++ b/static/js/com/custom-html.js @@ -66,7 +66,8 @@ export class CustomHtml extends LitElement { return } if (!session.ctzn?.blob) { - this.currentError = "Custom Html could not be loaded. If you are not logged in, please join a server to see this profile." + this.currentError = "Custom HTML could not be loaded. If you are not logged in, please join a server to see this profile." + return } try { let base64buf = (await session.ctzn.blob.get(this.userId, this.blobName))?.buf