Add pinning in Category Pages's Trending Tab (#399)

Closes https://github.com/OdyseeTeam/odysee-homepages/issues/427
This commit is contained in:
infinite-persistence 2021-12-01 07:18:57 -08:00 committed by GitHub
parent 6d3ec149b3
commit 7e9e213974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View file

@ -21,6 +21,7 @@ import { useIsLargeScreen } from 'effects/use-screensize';
type Props = { type Props = {
uris: Array<string>, uris: Array<string>,
prefixUris?: Array<string>, prefixUris?: Array<string>,
pins?: { urls: Array<string>, onlyPinForOrder?: string },
name?: string, name?: string,
type: string, type: string,
pageSize?: number, pageSize?: number,
@ -139,6 +140,7 @@ function ClaimListDiscover(props: Props) {
feeAmount, feeAmount,
uris, uris,
prefixUris, prefixUris,
pins,
tileLayout, tileLayout,
hideFilters = false, hideFilters = false,
claimIds, claimIds,
@ -466,6 +468,7 @@ function ClaimListDiscover(props: Props) {
); );
const renderUris = uris || claimSearchResult; const renderUris = uris || claimSearchResult;
injectPinUrls(renderUris, orderParam, pins);
// ************************************************************************** // **************************************************************************
// Helpers // Helpers
@ -527,6 +530,25 @@ function ClaimListDiscover(props: Props) {
return order_by; return order_by;
} }
function injectPinUrls(uris, order, pins) {
if (!pins || !pins.urls || (pins.onlyPinForOrder && pins.onlyPinForOrder !== order)) {
return;
}
const pinUrls = pins.urls;
if (pinUrls && uris && uris.length > 2) {
pinUrls.forEach((pin) => {
if (uris.includes(pin)) {
uris.splice(uris.indexOf(pin), 1);
} else {
uris.pop();
}
});
uris.splice(2, 0, ...pinUrls);
}
}
// ************************************************************************** // **************************************************************************
// ************************************************************************** // **************************************************************************

View file

@ -28,6 +28,8 @@ const SECTION = {
}; };
type Props = { type Props = {
dynamicRouteProps: RowDataItem,
// --- redux ---
location: { search: string }, location: { search: string },
followedTags: Array<Tag>, followedTags: Array<Tag>,
repostedUri: string, repostedUri: string,
@ -35,7 +37,6 @@ type Props = {
doToggleTagFollowDesktop: (string) => void, doToggleTagFollowDesktop: (string) => void,
doResolveUri: (string) => void, doResolveUri: (string) => void,
isAuthenticated: boolean, isAuthenticated: boolean,
dynamicRouteProps: RowDataItem,
tileLayout: boolean, tileLayout: boolean,
activeLivestreams: ?LivestreamInfo, activeLivestreams: ?LivestreamInfo,
doFetchActiveLivestreams: (orderBy?: Array<string>, pageSize?: number, forceFetch?: boolean) => void, doFetchActiveLivestreams: (orderBy?: Array<string>, pageSize?: number, forceFetch?: boolean) => void,
@ -130,6 +131,15 @@ function DiscoverPage(props: Props) {
return isLargeScreen ? originalSize * (3 / 2) : originalSize; return isLargeScreen ? originalSize * (3 / 2) : originalSize;
} }
function getPins(routeProps) {
if (routeProps && routeProps.pinnedUrls) {
return {
urls: routeProps.pinnedUrls,
onlyPinForOrder: CS.ORDER_BY_TRENDING,
};
}
}
React.useEffect(() => { React.useEffect(() => {
if (repostedUri && !repostedClaimIsResolved) { if (repostedUri && !repostedClaimIsResolved) {
doResolveUri(repostedUri); doResolveUri(repostedUri);
@ -222,6 +232,7 @@ function DiscoverPage(props: Props) {
<ClaimListDiscover <ClaimListDiscover
prefixUris={useDualList ? undefined : livestreamUris} prefixUris={useDualList ? undefined : livestreamUris}
pins={useDualList ? undefined : getPins(dynamicRouteProps)}
hideAdvancedFilter={SIMPLE_SITE} hideAdvancedFilter={SIMPLE_SITE}
hideFilters={SIMPLE_SITE ? !dynamicRouteProps : undefined} hideFilters={SIMPLE_SITE ? !dynamicRouteProps : undefined}
header={useDualList ? <span /> : repostedUri ? <span /> : undefined} header={useDualList ? <span /> : repostedUri ? <span /> : undefined}