From d5377987d90f56c4161d7e59d1db3cdfe6b485ef Mon Sep 17 00:00:00 2001 From: Ru Singh Date: Wed, 22 Dec 2021 13:24:09 +0530 Subject: [PATCH] Allow site toggle to work with minimal info for guests (#1510) * chore(docker): improve repeat contributions workflow * This change adds two new commands to gracefully stop and remove the Postgres and Clickhouse docker containers. To do so, it also gives them a recognizable name. * Additionally, the Postgres container is updated to use a named volume for its data. This lower friction for repeat contributions where one would otherwise sign up and activate their accounts again and again each time. * fix(ui): site switcher should toggle, instead of just opening * feat/wip: public site toggle dropdown * fix(ux): toggling the site switcher & closing from anywhere * Do not react to key presses for guest users * Cleanup duplicate code * Fix logic left in for local testing * Add a changelog entry for guest dropdown toggle --- CHANGELOG.md | 1 + assets/js/dashboard/site-switcher.js | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ac98a90..8d864dc2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file. ### Fixed - UI fix where multi-line text in pills would not be underlined properly on small screens. - UI fix to align footer columns +- Guests can now use the favicon to toggle additional info about the site bing viewed (such as in public embeds). ## v1.4.1 diff --git a/assets/js/dashboard/site-switcher.js b/assets/js/dashboard/site-switcher.js index 54c7385c7..56111eede 100644 --- a/assets/js/dashboard/site-switcher.js +++ b/assets/js/dashboard/site-switcher.js @@ -54,6 +54,8 @@ export default class SiteSwitcher extends React.Component { } handleKeydown(e) { + if (!this.props.loggedIn) return; + const { site } = this.props; const { sites } = this.state; @@ -82,20 +84,21 @@ export default class SiteSwitcher extends React.Component { open: !prevState.open })) - if (!this.state.sites) { + if (this.props.loggedIn && !this.state.sites) { this.populateSites(); } } renderSiteLink(domain, index) { const extraClass = domain === this.props.site.domain ? 'font-medium text-gray-900 dark:text-gray-100 cursor-default font-bold' : 'hover:bg-gray-100 dark:hover:bg-gray-900 hover:text-gray-900 dark:hover:text-gray-100 focus:outline-none focus:bg-gray-100 dark:focus:bg-gray-900 focus:text-gray-900 dark:focus:text-gray-100' + const showHotkey = !this.props.loggedIn return ( {domain} - {index < 9 && {index+1}} + {showHotkey ? index < 9 && {index+1} : null} ) } @@ -116,11 +119,22 @@ export default class SiteSwitcher extends React.Component { } } + /** + * Render a dropdown regardless of whether the user is logged in or not. In case they are not logged in (such as in an embed), the dropdown merely contains the current domain name. + */ renderDropdown() { if (this.state.loading) { return
} else if (this.state.error) { return
Something went wrong, try again
+ } else if (!this.props.loggedIn) { + return ( + +
+ { [this.props.site.domain].map(this.renderSiteLink.bind(this)) } +
+
+ ) } else { return (