From 6fb345dbbc35d636dde38d02eb5cad9c2fb002f3 Mon Sep 17 00:00:00 2001 From: zeppi Date: Wed, 6 Jan 2021 13:13:56 -0500 Subject: [PATCH 1/7] zh languages bugfix bugfix3 publish add zh back for homepage selector test revert i18n file DRY publish language --- electron/createWindow.js | 6 ++- ui/component/app/view.jsx | 10 +++++ ui/component/homepageSelector/view.jsx | 4 +- .../publishAdditionalOptions/view.jsx | 36 ++++------------ ui/constants/language-migrations.js | 6 +++ ui/constants/languages.js | 4 +- ui/constants/supported_browser_languages.js | 41 +++++++++++++++++++ ui/constants/supported_languages.js | 6 +-- ui/i18n.js | 1 - ui/redux/actions/settings.js | 5 ++- ui/redux/actions/user.js | 3 +- ui/redux/reducers/settings.js | 3 +- ui/redux/selectors/settings.js | 4 +- ui/util/default-languages.js | 15 +++---- 14 files changed, 93 insertions(+), 51 deletions(-) create mode 100644 ui/constants/language-migrations.js create mode 100644 ui/constants/supported_browser_languages.js diff --git a/electron/createWindow.js b/electron/createWindow.js index f1f0a649c..253c7b9f2 100644 --- a/electron/createWindow.js +++ b/electron/createWindow.js @@ -4,21 +4,23 @@ import isDev from 'electron-is-dev'; import windowStateKeeper from 'electron-window-state'; import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import { SUPPORTED_SUB_LANGUAGE_CODES, SUB_LANG_CODE_LEN } from 'constants/supported_sub_languages'; +import { SUPPORTED_BROWSER_LANGUAGES } from 'constants/supported_browser_languages'; import { TO_TRAY_WHEN_CLOSED } from 'constants/settings'; import setupBarMenu from './menu/setupBarMenu'; import * as PAGES from 'constants/pages'; function GetAppLangCode() { + // https://www.electronjs.org/docs/api/locales // 1. Gets the user locale. // 2. Converts unsupported sub-languages to its primary (e.g. "en-GB" -> "en"). // Note that the primary itself may or may not be a supported language // (up to clients to verify against SUPPORTED_LANGUAGES). const langCode = app.getLocale(); if (langCode.length === SUB_LANG_CODE_LEN && !SUPPORTED_SUB_LANGUAGE_CODES.includes(langCode)) { - return langCode.slice(0, 2); + return SUPPORTED_BROWSER_LANGUAGES[langCode.slice(0, 2)]; } - return langCode; + return SUPPORTED_BROWSER_LANGUAGES[langCode]; } export default appState => { diff --git a/ui/component/app/view.jsx b/ui/component/app/view.jsx index 8908c9f0f..9a8a17d74 100644 --- a/ui/component/app/view.jsx +++ b/ui/component/app/view.jsx @@ -36,6 +36,7 @@ import { STATUS_FAILING, STATUS_DOWN, } from 'web/effects/use-degraded-performance'; +import LANGUAGE_MIGRATIONS from 'constants/language-migrations'; // @endif export const MAIN_WRAPPER_CLASS = 'main-wrapper'; export const IS_MAC = navigator.userAgent.indexOf('Mac OS X') !== -1; @@ -134,6 +135,8 @@ function App(props: Props) { const userId = user && user.id; const useCustomScrollbar = !IS_MAC; + const shouldMigrateLanguage = LANGUAGE_MIGRATIONS[language]; + let uri; try { const newpath = buildURI(parseURI(pathname.slice(1).replace(/:/g, '#'))); @@ -232,6 +235,13 @@ function App(props: Props) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [language, languages]); + useEffect(() => { + if (shouldMigrateLanguage) { + setLanguage(shouldMigrateLanguage); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [shouldMigrateLanguage]); + useEffect(() => { // Check that previousHasVerifiedEmail was not undefined instead of just not truthy // This ensures we don't fire the emailVerified event on the initial user fetch diff --git a/ui/component/homepageSelector/view.jsx b/ui/component/homepageSelector/view.jsx index d58524f66..514cb2f94 100644 --- a/ui/component/homepageSelector/view.jsx +++ b/ui/component/homepageSelector/view.jsx @@ -4,7 +4,7 @@ import React from 'react'; import homepages from 'homepages'; import LANGUAGES from 'constants/languages'; import { FormField } from 'component/common/form'; -import { getDefaultHomepage } from 'util/default-languages'; +import { getDefaultHomepageKey } from 'util/default-languages'; type Props = { homepage: string, @@ -28,7 +28,7 @@ function SelectHomepage(props: Props) { type="select" label={__('Homepage')} onChange={handleSetHomepage} - value={homepage || getDefaultHomepage()} + value={homepage || getDefaultHomepageKey()} helper={__('Tailor your experience.')} > {Object.keys(homepages).map(hp => ( diff --git a/ui/component/publishAdditionalOptions/view.jsx b/ui/component/publishAdditionalOptions/view.jsx index 220042582..b4ae97105 100644 --- a/ui/component/publishAdditionalOptions/view.jsx +++ b/ui/component/publishAdditionalOptions/view.jsx @@ -6,6 +6,8 @@ import { FormField } from 'component/common/form'; import Button from 'component/button'; import LicenseType from './license-type'; import Card from 'component/common/card'; +import SUPPORTED_LANGUAGES from 'constants/supported_languages'; + // @if TARGET='app' // import ErrorText from 'component/common/error-text'; // import { LbryFirst } from 'lbry-redux'; @@ -156,34 +158,12 @@ function PublishAdditionalOptions(props: Props) { value={language} onChange={event => updatePublishForm({ language: event.target.value })} > - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {Object.entries(SUPPORTED_LANGUAGES).map(([langkey, langName]) => ( + // $FlowFixMe + + ))} { let languageCode; - if (code === window.navigator.language.slice(0, 2)) { + if (code === getDefaultLanguage()) { languageCode = null; } else { languageCode = code; @@ -311,7 +312,7 @@ export function doSetLanguage(language) { const { share_usage_data: shareSetting } = daemonSettings; const isSharingData = shareSetting || IS_WEB; let languageSetting; - if (language === window.navigator.language.slice(0, 2)) { + if (language === getDefaultLanguage()) { languageSetting = null; } else { languageSetting = language; diff --git a/ui/redux/actions/user.js b/ui/redux/actions/user.js index 7bcf46cf8..9c85074fc 100644 --- a/ui/redux/actions/user.js +++ b/ui/redux/actions/user.js @@ -6,6 +6,7 @@ import { doToast } from 'redux/actions/notifications'; import rewards from 'rewards'; import { Lbryio } from 'lbryinc'; import { DOMAIN } from 'config'; +import { getDefaultLanguage } from 'util/default-languages'; const AUTH_IN_PROGRESS = 'authInProgress'; export let sessionStorageAvailable = false; @@ -131,7 +132,7 @@ export function doAuthenticate( }); checkAuthBusy() .then(() => { - return Lbryio.authenticate(DOMAIN, window.navigator.language.slice(0, 2) || 'en'); + return Lbryio.authenticate(DOMAIN, getDefaultLanguage()); }) .then(user => { if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS); diff --git a/ui/redux/reducers/settings.js b/ui/redux/reducers/settings.js index bd6dd11b5..9a1f11d11 100644 --- a/ui/redux/reducers/settings.js +++ b/ui/redux/reducers/settings.js @@ -2,6 +2,7 @@ import * as ACTIONS from 'constants/action_types'; import moment from 'moment'; import { ACTIONS as LBRY_REDUX_ACTIONS, SETTINGS, SHARED_PREFERENCES } from 'lbry-redux'; import { getSubsetFromKeysArray } from 'util/sync-settings'; +import { getDefaultLanguage } from 'util/default-languages'; import { UNSYNCED_SETTINGS } from 'config'; const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES; @@ -16,7 +17,7 @@ try { let appLanguage = window.localStorage.getItem(SETTINGS.LANGUAGE); settingLanguage.push(appLanguage); } catch (e) {} -settingLanguage.push(window.navigator.language.slice(0, 2)); +settingLanguage.push(getDefaultLanguage()); settingLanguage.push('en'); const defaultState = { diff --git a/ui/redux/selectors/settings.js b/ui/redux/selectors/settings.js index fe9657048..1febe623a 100644 --- a/ui/redux/selectors/settings.js +++ b/ui/redux/selectors/settings.js @@ -1,7 +1,7 @@ import { SETTINGS, DAEMON_SETTINGS } from 'lbry-redux'; import { createSelector } from 'reselect'; import homepages from 'homepages'; -import { getDefaultHomepage, getDefaultLanguage } from 'util/default-languages'; +import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages'; const selectState = state => state.settings || {}; @@ -55,7 +55,7 @@ export const selectThemePath = createSelector( ); export const selectHomepageCode = createSelector(makeSelectClientSetting(SETTINGS.HOMEPAGE), setting => { - return homepages[setting] ? setting : getDefaultHomepage(); + return homepages[setting] ? setting : getDefaultHomepageKey(); }); export const selectLanguage = createSelector(makeSelectClientSetting(SETTINGS.LANGUAGE), setting => { diff --git a/ui/util/default-languages.js b/ui/util/default-languages.js index d840b2f81..fd5cd4b6b 100644 --- a/ui/util/default-languages.js +++ b/ui/util/default-languages.js @@ -1,13 +1,14 @@ import homepages from 'homepages'; -import SUPPORTED_LANGUAGES from 'constants/supported_languages'; +import SUPPORTED_BROWSER_LANGUAGES from 'constants/supported_browser_languages'; const DEFAULT_LANG = 'en'; -export const getDefaultHomepage = () => { - return homepages[window.navigator.language.slice(0, 2)] ? window.navigator.language.slice(0, 2) : DEFAULT_LANG; +export const getDefaultLanguage = () => { + const browserLanguage = window.navigator.language; + return SUPPORTED_BROWSER_LANGUAGES[browserLanguage] || DEFAULT_LANG; }; -export const getDefaultLanguage = () => { - return SUPPORTED_LANGUAGES[window.navigator.language.slice(0, 2)] - ? window.navigator.language.slice(0, 2) - : DEFAULT_LANG; +// If homepages has a key "zh-Hant" return that, otherwise return "zh", otherwise "en" +export const getDefaultHomepageKey = () => { + const language = getDefaultLanguage(); + return (homepages[language] && language) || (homepages[language.slice(0, 2)] && language.slice(0, 2)) || DEFAULT_LANG; }; -- 2.45.2 From 72945b45c5303700dd861e8064da01127785eee3 Mon Sep 17 00:00:00 2001 From: zeppi Date: Fri, 8 Jan 2021 11:28:52 -0500 Subject: [PATCH 2/7] cleaner --- ui/component/app/view.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/component/app/view.jsx b/ui/component/app/view.jsx index 9a8a17d74..b8032dc93 100644 --- a/ui/component/app/view.jsx +++ b/ui/component/app/view.jsx @@ -239,8 +239,7 @@ function App(props: Props) { if (shouldMigrateLanguage) { setLanguage(shouldMigrateLanguage); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [shouldMigrateLanguage]); + }, [shouldMigrateLanguage, setLanguage]); useEffect(() => { // Check that previousHasVerifiedEmail was not undefined instead of just not truthy -- 2.45.2 From 4f1bd2344261dde953e672b379b2d65c66bea8ce Mon Sep 17 00:00:00 2001 From: Franco Montenegro Date: Fri, 8 Jan 2021 19:02:40 -0300 Subject: [PATCH 3/7] Fix nsfw parameter in search page --- ui/page/search/view.jsx | 5 ++--- ui/redux/selectors/search.js | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ui/page/search/view.jsx b/ui/page/search/view.jsx index b833eb8af..c34280899 100644 --- a/ui/page/search/view.jsx +++ b/ui/page/search/view.jsx @@ -46,9 +46,8 @@ export default function SearchPage(props: Props) { const urlParams = new URLSearchParams(location.search); const urlQuery = urlParams.get('q') || ''; const additionalOptions: AdditionalOptions = { isBackgroundSearch: false }; - if (!showNsfw) { - additionalOptions['nsfw'] = false; - } + + additionalOptions['nsfw'] = showNsfw; const modifiedUrlQuery = urlQuery .trim() diff --git a/ui/redux/selectors/search.js b/ui/redux/selectors/search.js index b29e19939..6b1d81de8 100644 --- a/ui/redux/selectors/search.js +++ b/ui/redux/selectors/search.js @@ -77,9 +77,7 @@ export const makeSelectRecommendedContentForUri = (uri: string) => isBackgroundSearch?: boolean, } = { related_to: claim.claim_id, isBackgroundSearch: true }; - if (!isMature) { - options['nsfw'] = false; - } + options['nsfw'] = isMature; const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options); let searchUris = searchUrisByQuery[searchQuery]; -- 2.45.2 From 148fa4f4cdfdd3c88a0c2657bbb38bbe14b811d8 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 11 Jan 2021 14:19:54 -0500 Subject: [PATCH 4/7] call user/signout on signout fixes sync issues for users with multiple accounts signed in to multiple tabs --- ui/redux/actions/app.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index f4f67b265..f490b5f19 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -22,6 +22,7 @@ import { DAEMON_SETTINGS, SETTINGS, } from 'lbry-redux'; +import { Lbryio } from 'lbryinc'; import { selectFollowedTagsList } from 'redux/selectors/tags'; import { doToast, doError, doNotificationList } from 'redux/actions/notifications'; @@ -554,8 +555,9 @@ export function doSignIn() { } export function doSignOut() { - return dispatch => { - doSignOutCleanup() + return () => { + Lbryio.call('user', 'signout') + .then(doSignOutCleanup) .then(() => { // @if TARGET='web' window.persistor.purge(); -- 2.45.2 From 65709e113990b97ae43d06655bfe7cc3a3faa25c Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 11 Jan 2021 15:01:14 -0500 Subject: [PATCH 5/7] Revert "Fix nsfw parameter in search page" This reverts commit 4f1bd2344261dde953e672b379b2d65c66bea8ce. --- ui/page/search/view.jsx | 5 +++-- ui/redux/selectors/search.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/page/search/view.jsx b/ui/page/search/view.jsx index c34280899..b833eb8af 100644 --- a/ui/page/search/view.jsx +++ b/ui/page/search/view.jsx @@ -46,8 +46,9 @@ export default function SearchPage(props: Props) { const urlParams = new URLSearchParams(location.search); const urlQuery = urlParams.get('q') || ''; const additionalOptions: AdditionalOptions = { isBackgroundSearch: false }; - - additionalOptions['nsfw'] = showNsfw; + if (!showNsfw) { + additionalOptions['nsfw'] = false; + } const modifiedUrlQuery = urlQuery .trim() diff --git a/ui/redux/selectors/search.js b/ui/redux/selectors/search.js index 6b1d81de8..b29e19939 100644 --- a/ui/redux/selectors/search.js +++ b/ui/redux/selectors/search.js @@ -77,7 +77,9 @@ export const makeSelectRecommendedContentForUri = (uri: string) => isBackgroundSearch?: boolean, } = { related_to: claim.claim_id, isBackgroundSearch: true }; - options['nsfw'] = isMature; + if (!isMature) { + options['nsfw'] = false; + } const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options); let searchUris = searchUrisByQuery[searchQuery]; -- 2.45.2 From 29a332175a1f21712a5c37d60a88df853a227c97 Mon Sep 17 00:00:00 2001 From: zeppi Date: Mon, 11 Jan 2021 16:46:32 -0500 Subject: [PATCH 6/7] repost ui --- ui/component/claimPreview/view.jsx | 43 ++++++++++++++----------- ui/component/claimRepostAuthor/view.jsx | 23 +++++++++---- ui/redux/selectors/search.js | 4 ++- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/ui/component/claimPreview/view.jsx b/ui/component/claimPreview/view.jsx index c0de60576..f7647e326 100644 --- a/ui/component/claimPreview/view.jsx +++ b/ui/component/claimPreview/view.jsx @@ -131,9 +131,10 @@ const ClaimPreview = forwardRef((props: Props, ref: any) => { isValid = false; } } + const isRepost = claim && claim.repost_url; - const contentUri = hideRepostLabel && claim && claim.repost_url ? claim.canonical_url || claim.permanent_url : uri; - const isChannel = isValid ? parseURI(contentUri).isChannel : false; + const contentUri = claim && isRepost ? claim && (claim.canonical_url || claim.permanent_url) : uri; + const isChannelUri = isValid ? parseURI(contentUri).isChannel : false; const signingChannel = claim && claim.signing_channel; const navigateUrl = formatLbryUrlForWeb((claim && claim.canonical_url) || uri || '/'); const navLinkProps = { @@ -170,7 +171,7 @@ const ClaimPreview = forwardRef((props: Props, ref: any) => { } // block channel claims if we can't control for them in claim search // e.g. fetchRecommendedSubscriptions - if (claim && isChannel && !shouldHide && !showUserBlocked && blockedChannelUris.length) { + if (claim && isChannelUri && !shouldHide && !showUserBlocked && blockedChannelUris.length) { shouldHide = blockedChannelUris.some(blockedUri => blockedUri === claim.permanent_url); } @@ -216,21 +217,25 @@ const ClaimPreview = forwardRef((props: Props, ref: any) => { } if (placeholder === 'loading' || (uri && !claim && isResolvingUri)) { - return ; + return ; } if (claim && showNullPlaceholder && shouldHide && nsfw) { return ( -