Skip to content

Commit

Permalink
Update pattern rendering constants and receive URL params (#86900)
Browse files Browse the repository at this point in the history
  • Loading branch information
miksansegundo authored Jan 30, 2024
1 parent bf89388 commit 898a114
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,13 @@ export const ORDERED_PATTERN_PAGES_CATEGORIES = [
'posts',
'contact',
];

// From URL params for testing
const searchParams = new URLSearchParams( window.location.search );
const viewportWidth = searchParams.get( 'viewportWidth' );
const placeholderHeight = searchParams.get( 'placeholderHeight' );

// Pattern rendering
export const DEFAULT_VIEWPORT_HEIGHT = 500;
export const DEFAULT_VIEWPORT_WIDTH = Number( viewportWidth ) || 1200;
export const PLACEHOLDER_HEIGHT = Number( placeholderHeight ) || 150;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import classnames from 'classnames';
import { CSSProperties, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import useOutsideClickCallback from 'calypso/lib/use-outside-click-callback';
import { DEFAULT_VIEWPORT_WIDTH, DEFAULT_VIEWPORT_HEIGHT } from '../constants';
import { PATTERN_ASSEMBLER_EVENTS } from '../events';
import prependTitleBlockToPagePattern from '../html-transformers/prepend-title-block-to-page-pattern';
import PatternTooltipDeadClick from '../pattern-tooltip-dead-click';
Expand All @@ -30,9 +31,6 @@ interface PagePreviewProps extends BasePageProps {
onFullscreenLeave: () => void;
}

const PATTERN_PAGE_PREVIEW_ITEM_VIEWPORT_HEIGHT = 500;
const PATTERN_PAGE_PREVIEW_ITEM_VIEWPORT_WIDTH = 1080;

const Page = ( { className, style, patterns, transformPatternHtml }: PageProps ) => {
const pageTitle = useMemo( () => {
return patterns.find( isPagePattern )?.title ?? '';
Expand All @@ -56,8 +54,8 @@ const Page = ( { className, style, patterns, transformPatternHtml }: PageProps )
key={ pattern.ID }
maxHeight="none"
patternId={ encodePatternId( pattern.ID ) }
viewportWidth={ PATTERN_PAGE_PREVIEW_ITEM_VIEWPORT_WIDTH }
viewportHeight={ PATTERN_PAGE_PREVIEW_ITEM_VIEWPORT_HEIGHT }
viewportWidth={ DEFAULT_VIEWPORT_WIDTH }
viewportHeight={ DEFAULT_VIEWPORT_HEIGHT }
transformHtml={
isPagePattern( pattern ) ? transformPagePatternHtml : transformPatternHtml
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import classnames from 'classnames';
import { useTranslate } from 'i18n-calypso';
import React, { useRef, useEffect, useState, useMemo, CSSProperties, useCallback } from 'react';
import { useDebouncedCallback } from 'use-debounce';
import { DEFAULT_VIEWPORT_WIDTH } from './constants';
import { PATTERN_ASSEMBLER_EVENTS } from './events';
import { injectTitlesToPageListBlock } from './html-transformers';
import PatternActionBar from './pattern-action-bar';
Expand Down Expand Up @@ -167,6 +168,7 @@ const PatternLargePreview = ( {
key={ device }
patternId={ encodePatternId( pattern.ID ) }
viewportHeight={ viewportHeight }
viewportWidth={ DEFAULT_VIEWPORT_WIDTH }
// Disable default max-height
maxHeight="none"
transformHtml={ transformPatternHtml }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Tooltip, __unstableCompositeItem as CompositeItem } from '@wordpress/co
import classnames from 'classnames';
import { useEffect, useCallback, useRef } from 'react';
import { useInView } from 'react-intersection-observer';
import { DEFAULT_VIEWPORT_WIDTH, DEFAULT_VIEWPORT_HEIGHT, PLACEHOLDER_HEIGHT } from './constants';
import { encodePatternId, isPriorityPattern } from './utils';
import type { Pattern } from './types';
import './pattern-list-renderer.scss';
Expand Down Expand Up @@ -30,10 +31,6 @@ interface PatternListRendererProps {
isShowMorePatterns?: boolean;
}

const DEFAULT_VIEWPORT_WIDTH = 1060;
const DEFAULT_VIEWPORT_HEIGHT = 500;
const PLACEHOLDER_HEIGHT = 100;

const PatternListItem = ( {
pattern,
className,
Expand Down

0 comments on commit 898a114

Please sign in to comment.