From 34283f7be6a65f413c4158141758e557490ed2c2 Mon Sep 17 00:00:00 2001 From: jessopb <36554050+jessopb@users.noreply.github.com> Date: Tue, 4 Jan 2022 15:40:42 -0500 Subject: [PATCH] fix 7188 window.location.pathname (#7401) --- ui/analytics.js | 39 ++--------------------- ui/component/claimListDiscover/view.jsx | 16 ---------- ui/component/claimPreviewTile/view.jsx | 5 +-- ui/component/claimTilesDiscover/view.jsx | 24 +++++++------- ui/component/fileViewCountInline/view.jsx | 6 +++- ui/component/sideNavigation/view.jsx | 22 +++++++------ 6 files changed, 35 insertions(+), 77 deletions(-) diff --git a/ui/analytics.js b/ui/analytics.js index d93dd82e3..7152300df 100644 --- a/ui/analytics.js +++ b/ui/analytics.js @@ -29,13 +29,11 @@ const SHARE_THIRD_PARTY = 'shareThirdParty'; const WATCHMAN_BACKEND_ENDPOINT = 'https://watchman.na-backend.odysee.com/reports/playback'; const SEND_DATA_TO_WATCHMAN_INTERVAL = 10; // in seconds -// @if TARGET='app' if (isProduction) { ElectronCookies.enable({ origin: 'https://lbry.tv', }); } -// @endif type Analytics = { error: (string) => Promise, @@ -83,11 +81,7 @@ type LogPublishParams = { }; let internalAnalyticsEnabled: boolean = IS_WEB || false; -// let thirdPartyAnalyticsEnabled: boolean = IS_WEB || false; -// @if TARGET='app' if (window.localStorage.getItem(SHARE_INTERNAL) === 'true') internalAnalyticsEnabled = true; -// if (window.localStorage.getItem(SHARE_THIRD_PARTY) === 'true') thirdPartyAnalyticsEnabled = true; -// @endif /** * Determine the mobile device type viewing the data @@ -96,26 +90,7 @@ if (window.localStorage.getItem(SHARE_INTERNAL) === 'true') internalAnalyticsEna * @returns {String} */ function getDeviceType() { - // We may not care what the device is if it's in a web browser. Commenting out for now. - // if (!IS_WEB) { - // return 'elt'; - // } - // const userAgent = navigator.userAgent || navigator.vendor || window.opera; - // - // if (/android/i.test(userAgent)) { - // return 'adr'; - // } - // - // // iOS detection from: http://stackoverflow.com/a/9039885/177710 - // if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { - // return 'ios'; - // } - - // default as web, this can be optimized - if (!IS_WEB) { - return 'dsk'; - } - return 'web'; + return 'dsk'; } // variables initialized for watchman let amountOfBufferEvents = 0; @@ -449,17 +424,7 @@ const MatomoInstance = new MatomoTracker({ // linkTracking: false // optional, default value: true }); -// Manually call the first page view -// React Router doesn't include this on `history.listen` -// @if TARGET='web' -analytics.pageView(window.location.pathname + window.location.search, window.location.search); -// @endif - -// @if TARGET='app' -analytics.pageView( - window.location.pathname.split('.html')[1] + window.location.search || generateInitialUrl(window.location.hash) -); -// @endif; +analytics.pageView(generateInitialUrl(window.location.hash)); // Listen for url changes and report // This will include search queries diff --git a/ui/component/claimListDiscover/view.jsx b/ui/component/claimListDiscover/view.jsx index 3ec749c97..7f3e03065 100644 --- a/ui/component/claimListDiscover/view.jsx +++ b/ui/component/claimListDiscover/view.jsx @@ -384,22 +384,6 @@ function ClaimListDiscover(props: Props) { const claimSearchResult = claimSearchByQuery[searchKey]; const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[searchKey]; - // uncomment to fix an item on a page - // const fixUri = 'lbry://@corbettreport#0/lbryodysee#5'; - // if ( - // orderParam === CS.ORDER_BY_NEW && - // claimSearchResult && - // claimSearchResult.length > 2 && - // window.location.pathname === '/$/rabbithole' - // ) { - // if (claimSearchResult.indexOf(fixUri) !== -1) { - // claimSearchResult.splice(claimSearchResult.indexOf(fixUri), 1); - // } else { - // claimSearchResult.pop(); - // } - // claimSearchResult.splice(2, 0, fixUri); - // } - const [prevOptions, setPrevOptions] = React.useState(null); if (!isJustScrollingToNewPage(prevOptions, options)) { diff --git a/ui/component/claimPreviewTile/view.jsx b/ui/component/claimPreviewTile/view.jsx index f68fc1c22..908ec5f1b 100644 --- a/ui/component/claimPreviewTile/view.jsx +++ b/ui/component/claimPreviewTile/view.jsx @@ -29,7 +29,7 @@ type Props = { mediaDuration?: string, resolveUri: (string) => void, isResolvingUri: boolean, - history: { push: (string) => void }, + history: { push: (string) => void, location: { pathname: string } }, thumbnail: string, title: string, placeholder: boolean, @@ -91,6 +91,7 @@ function ClaimPreviewTile(props: Props) { to: navigateUrl, onClick: (e) => e.stopPropagation(), }; + const { location } = history; let isValid = false; if (uri) { @@ -138,7 +139,7 @@ function ClaimPreviewTile(props: Props) { return null; } - const isChannelPage = window.location.pathname.startsWith('/@'); + const isChannelPage = location.pathname.startsWith('/@'); const shouldShowViewCount = !(!viewCount || (claim && claim.repost_url) || !isChannelPage); diff --git a/ui/component/claimTilesDiscover/view.jsx b/ui/component/claimTilesDiscover/view.jsx index 359800565..f43d7a7d1 100644 --- a/ui/component/claimTilesDiscover/view.jsx +++ b/ui/component/claimTilesDiscover/view.jsx @@ -88,7 +88,7 @@ function ClaimTilesDiscover(props: Props) { fetchingClaimSearchByQuery, hasNoSource, renderProperties, - pinUrls, + // pinUrls, prefixUris, showNoSourceClaims, doFetchViewCount, @@ -106,17 +106,17 @@ function ClaimTilesDiscover(props: Props) { const shouldPerformSearch = !fetchingClaimSearch && claimSearchUris.length === 0; const uris = (prefixUris || []).concat(claimSearchUris); - - if (pinUrls && uris && uris.length > 2 && window.location.pathname === '/') { - pinUrls.forEach((pin) => { - if (uris.indexOf(pin) !== -1) { - uris.splice(uris.indexOf(pin), 1); - } else { - uris.pop(); - } - }); - uris.splice(2, 0, ...pinUrls); - } + // Not sure what to do with pinUrls + // if (pinUrls && uris && uris.length > 2 && window.location.pathname === '/') { + // pinUrls.forEach((pin) => { + // if (uris.indexOf(pin) !== -1) { + // uris.splice(uris.indexOf(pin), 1); + // } else { + // uris.pop(); + // } + // }); + // uris.splice(2, 0, ...pinUrls); + // } if (uris.length > 0 && uris.length < pageSize && shouldPerformSearch) { // prefixUri and pinUrls might already be present while waiting for the diff --git a/ui/component/fileViewCountInline/view.jsx b/ui/component/fileViewCountInline/view.jsx index fd1f366cb..efd0b6bbf 100644 --- a/ui/component/fileViewCountInline/view.jsx +++ b/ui/component/fileViewCountInline/view.jsx @@ -1,6 +1,7 @@ // @flow import React from 'react'; import 'scss/component/_view_count.scss'; +import { useHistory } from 'react-router'; type Props = { uri: string, @@ -12,6 +13,9 @@ type Props = { export default function FileViewCountInline(props: Props) { const { claim, viewCount, lang } = props; + const { + location: { pathname }, + } = useHistory(); let formattedViewCount; try { @@ -27,7 +31,7 @@ export default function FileViewCountInline(props: Props) { // Limit the view-count visibility to Channel Pages for now. I believe we'll // eventually show it everywhere, so this band-aid would be the easiest to // clean up (only one place edit/remove). - const isChannelPage = window.location.pathname.startsWith('/@'); + const isChannelPage = pathname.startsWith('/@'); // dont show if no view count, if it's a repost or isn't a channel page if (!viewCount || (claim && claim.repost_url) || !isChannelPage) { diff --git a/ui/component/sideNavigation/view.jsx b/ui/component/sideNavigation/view.jsx index b2c10b8c4..51d9c95ef 100644 --- a/ui/component/sideNavigation/view.jsx +++ b/ui/component/sideNavigation/view.jsx @@ -12,15 +12,7 @@ import I18nMessage from 'component/i18nMessage'; import ChannelThumbnail from 'component/channelThumbnail'; import { DOMAIN, ENABLE_UI_NOTIFICATIONS } from 'config'; import { IS_MAC } from 'component/app/view'; - -const HOME = { - title: 'Home', - link: `/`, - icon: ICONS.HOME, - onClick: () => { - if (window.location.pathname === '/') window.location.reload(); - }, -}; +import { useHistory } from 'react-router'; const RECENT_FROM_FOLLOWING = { title: 'Following --[sidebar button]--', @@ -71,6 +63,18 @@ function SideNavigation(props: Props) { followedTags, } = props; + const { + location: { pathname }, + } = useHistory(); + + const HOME = { + title: 'Home', + link: `/`, + icon: ICONS.HOME, + onClick: () => { + if (pathname === '/') window.location.reload(); + }, + }; const FULL_LINKS: Array = [ { title: 'Your Tags',