fix 7188 window.location.pathname #7401

Merged
jessopb merged 1 commit from issue-7188 into master 2022-01-04 21:40:42 +01:00
6 changed files with 35 additions and 77 deletions

View file

@ -29,13 +29,11 @@ const SHARE_THIRD_PARTY = 'shareThirdParty';
const WATCHMAN_BACKEND_ENDPOINT = 'https://watchman.na-backend.odysee.com/reports/playback'; const WATCHMAN_BACKEND_ENDPOINT = 'https://watchman.na-backend.odysee.com/reports/playback';
const SEND_DATA_TO_WATCHMAN_INTERVAL = 10; // in seconds const SEND_DATA_TO_WATCHMAN_INTERVAL = 10; // in seconds
// @if TARGET='app'
if (isProduction) { if (isProduction) {
ElectronCookies.enable({ ElectronCookies.enable({
origin: 'https://lbry.tv', origin: 'https://lbry.tv',
}); });
} }
// @endif
type Analytics = { type Analytics = {
error: (string) => Promise<any>, error: (string) => Promise<any>,
@ -83,11 +81,7 @@ type LogPublishParams = {
}; };
let internalAnalyticsEnabled: boolean = IS_WEB || false; 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_INTERNAL) === 'true') internalAnalyticsEnabled = true;
// if (window.localStorage.getItem(SHARE_THIRD_PARTY) === 'true') thirdPartyAnalyticsEnabled = true;
// @endif
/** /**
* Determine the mobile device type viewing the data * Determine the mobile device type viewing the data
@ -96,26 +90,7 @@ if (window.localStorage.getItem(SHARE_INTERNAL) === 'true') internalAnalyticsEna
* @returns {String} * @returns {String}
*/ */
function getDeviceType() { function getDeviceType() {
// We may not care what the device is if it's in a web browser. Commenting out for now. return 'dsk';
// 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';
} }
// variables initialized for watchman // variables initialized for watchman
let amountOfBufferEvents = 0; let amountOfBufferEvents = 0;
@ -449,17 +424,7 @@ const MatomoInstance = new MatomoTracker({
// linkTracking: false // optional, default value: true // linkTracking: false // optional, default value: true
}); });
// Manually call the first page view analytics.pageView(generateInitialUrl(window.location.hash));
// 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;
// Listen for url changes and report // Listen for url changes and report
// This will include search queries // This will include search queries

View file

@ -384,22 +384,6 @@ function ClaimListDiscover(props: Props) {
const claimSearchResult = claimSearchByQuery[searchKey]; const claimSearchResult = claimSearchByQuery[searchKey];
const claimSearchResultLastPageReached = claimSearchByQueryLastPageReached[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); const [prevOptions, setPrevOptions] = React.useState(null);
if (!isJustScrollingToNewPage(prevOptions, options)) { if (!isJustScrollingToNewPage(prevOptions, options)) {

View file

@ -29,7 +29,7 @@ type Props = {
mediaDuration?: string, mediaDuration?: string,
resolveUri: (string) => void, resolveUri: (string) => void,
isResolvingUri: boolean, isResolvingUri: boolean,
history: { push: (string) => void }, history: { push: (string) => void, location: { pathname: string } },
thumbnail: string, thumbnail: string,
title: string, title: string,
placeholder: boolean, placeholder: boolean,
@ -91,6 +91,7 @@ function ClaimPreviewTile(props: Props) {
to: navigateUrl, to: navigateUrl,
onClick: (e) => e.stopPropagation(), onClick: (e) => e.stopPropagation(),
}; };
const { location } = history;
let isValid = false; let isValid = false;
if (uri) { if (uri) {
@ -138,7 +139,7 @@ function ClaimPreviewTile(props: Props) {
return null; return null;
} }
const isChannelPage = window.location.pathname.startsWith('/@'); const isChannelPage = location.pathname.startsWith('/@');
const shouldShowViewCount = !(!viewCount || (claim && claim.repost_url) || !isChannelPage); const shouldShowViewCount = !(!viewCount || (claim && claim.repost_url) || !isChannelPage);

View file

@ -88,7 +88,7 @@ function ClaimTilesDiscover(props: Props) {
fetchingClaimSearchByQuery, fetchingClaimSearchByQuery,
hasNoSource, hasNoSource,
renderProperties, renderProperties,
pinUrls, // pinUrls,
prefixUris, prefixUris,
showNoSourceClaims, showNoSourceClaims,
doFetchViewCount, doFetchViewCount,
@ -106,17 +106,17 @@ function ClaimTilesDiscover(props: Props) {
const shouldPerformSearch = !fetchingClaimSearch && claimSearchUris.length === 0; const shouldPerformSearch = !fetchingClaimSearch && claimSearchUris.length === 0;
const uris = (prefixUris || []).concat(claimSearchUris); const uris = (prefixUris || []).concat(claimSearchUris);
// Not sure what to do with pinUrls
if (pinUrls && uris && uris.length > 2 && window.location.pathname === '/') { // if (pinUrls && uris && uris.length > 2 && window.location.pathname === '/') {
pinUrls.forEach((pin) => { // pinUrls.forEach((pin) => {
if (uris.indexOf(pin) !== -1) { // if (uris.indexOf(pin) !== -1) {
uris.splice(uris.indexOf(pin), 1); // uris.splice(uris.indexOf(pin), 1);
} else { // } else {
uris.pop(); // uris.pop();
} // }
}); // });
uris.splice(2, 0, ...pinUrls); // uris.splice(2, 0, ...pinUrls);
} // }
if (uris.length > 0 && uris.length < pageSize && shouldPerformSearch) { if (uris.length > 0 && uris.length < pageSize && shouldPerformSearch) {
// prefixUri and pinUrls might already be present while waiting for the // prefixUri and pinUrls might already be present while waiting for the

View file

@ -1,6 +1,7 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import 'scss/component/_view_count.scss'; import 'scss/component/_view_count.scss';
import { useHistory } from 'react-router';
type Props = { type Props = {
uri: string, uri: string,
@ -12,6 +13,9 @@ type Props = {
export default function FileViewCountInline(props: Props) { export default function FileViewCountInline(props: Props) {
const { claim, viewCount, lang } = props; const { claim, viewCount, lang } = props;
const {
location: { pathname },
} = useHistory();
let formattedViewCount; let formattedViewCount;
try { 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 // 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 // eventually show it everywhere, so this band-aid would be the easiest to
// clean up (only one place edit/remove). // 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 // dont show if no view count, if it's a repost or isn't a channel page
if (!viewCount || (claim && claim.repost_url) || !isChannelPage) { if (!viewCount || (claim && claim.repost_url) || !isChannelPage) {

View file

@ -12,15 +12,7 @@ import I18nMessage from 'component/i18nMessage';
import ChannelThumbnail from 'component/channelThumbnail'; import ChannelThumbnail from 'component/channelThumbnail';
import { DOMAIN, ENABLE_UI_NOTIFICATIONS } from 'config'; import { DOMAIN, ENABLE_UI_NOTIFICATIONS } from 'config';
import { IS_MAC } from 'component/app/view'; import { IS_MAC } from 'component/app/view';
import { useHistory } from 'react-router';
const HOME = {
title: 'Home',
link: `/`,
icon: ICONS.HOME,
onClick: () => {
if (window.location.pathname === '/') window.location.reload();
},
};
const RECENT_FROM_FOLLOWING = { const RECENT_FROM_FOLLOWING = {
title: 'Following --[sidebar button]--', title: 'Following --[sidebar button]--',
@ -71,6 +63,18 @@ function SideNavigation(props: Props) {
followedTags, followedTags,
} = props; } = props;
const {
location: { pathname },
} = useHistory();
const HOME = {
title: 'Home',
link: `/`,
icon: ICONS.HOME,
onClick: () => {
if (pathname === '/') window.location.reload();
},
};
const FULL_LINKS: Array<SideNavLink> = [ const FULL_LINKS: Array<SideNavLink> = [
{ {
title: 'Your Tags', title: 'Your Tags',