Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sites list: Display only site icons as site thumbnails #90585

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function ItemPreviewPaneHeader( {
<div className="item-preview__header-content">
<SiteFavicon
blogId={ itemData.blogId }
isDotcomSite={ itemData.isDotcomSite }
fallback={ itemData.isDotcomSite ? 'wordpress-logo' : 'color' }
color={ itemData.color }
className="item-preview__header-favicon"
size={ size }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
import { WordPressLogo } from '@automattic/components';
import { useI18n } from '@wordpress/react-i18n';
import classNames from 'classnames';
import SiteIcon from 'calypso/blocks/site-icon';
import { getFirstGrapheme } from 'calypso/lib/string';
import { useSelector } from 'calypso/state';
import { getSite } from 'calypso/state/sites/selectors';

import './style.scss';

interface SiteFaviconProps {
blogId?: number;
isDotcomSite?: boolean;
color?: string;
size?: number;
className?: string;
fallback?: 'color' | 'wordpress-logo' | 'first-grapheme';
}

const SiteFavicon = ( {
blogId,
color,
isDotcomSite = false,
size = 40,
className = '',
fallback = 'color',
}: SiteFaviconProps ) => {
const { __ } = useI18n();
const siteColor = color ?? 'linear-gradient(45deg, #ff0056, #ff8a78, #57b7ff, #9c00d4)';
const site = useSelector( ( state ) => getSite( state, blogId ) );

const defaultFavicon = isDotcomSite ? (
<WordPressLogo className="wpcom-favicon" size={ size * 0.8 } />
) : (
<div className="no-favicon" style={ { background: siteColor } } />
);
let defaultFavicon;
switch ( fallback ) {
case 'wordpress-logo':
defaultFavicon = <WordPressLogo className="wpcom-favicon" size={ size * 0.8 } />;
break;
case 'first-grapheme':
defaultFavicon = (
<div role="img" aria-label={ __( 'Site Icon' ) }>
{ getFirstGrapheme( site?.title ?? '' ) }
</div>
);
break;
case 'color':
default:
defaultFavicon = <div className="no-favicon" style={ { background: siteColor } } />;
break;
}

return (
<div className={ classNames( 'site-favicon', className ) }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const SiteDataField = ( { isLoading, site, onSiteTitleClick }: SiteDataFieldProp

return (
<Button className="sites-dataviews__site" onClick={ () => onSiteTitleClick( site ) } borderless>
<SiteFavicon blogId={ site.blog_id } isDotcomSite={ site.is_atomic } />
<SiteFavicon
blogId={ site.blog_id }
fallback={ site.is_atomic ? 'wordpress-logo' : 'color' }
/>
<div className="sites-dataviews__site-name">
{ site.blogname }
<div className="sites-dataviews__site-url">{ site.url }</div>
Expand Down
17 changes: 16 additions & 1 deletion client/lib/string/index.js → client/lib/string/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {string} a the first string
* @param {string} b the second string
*/
export function areEqualIgnoringWhitespaceAndCase( a, b ) {
export function areEqualIgnoringWhitespaceAndCase( a: string, b: string ) {
// Are they equal without any manipulation?
if ( a === b ) {
return true;
Expand All @@ -18,3 +18,18 @@ export function areEqualIgnoringWhitespaceAndCase( a, b ) {
b = b.replace( /[\s'.\-_"]/g, '' );
return a.toLowerCase() === b.toLowerCase();
}

export function getFirstGrapheme( input: string ) {
if ( 'Segmenter' in Intl ) {
const segmenter = new Intl.Segmenter();
const [ firstSegmentData ] = segmenter.segment( input );

return firstSegmentData?.segment ?? '';
}

const codePoint = input.codePointAt( 0 );
if ( codePoint ) {
return String.fromCodePoint( codePoint );
}
return '';
}
Comment on lines +22 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice move!

21 changes: 10 additions & 11 deletions client/sites-dashboard-v2/dotcom-style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -336,26 +336,25 @@
}
}

.sites-site-thumbnail {
display: flex;
}

.sites-site-favicon {
display: none;
margin-right: 0;

.is-blank {
font-size: xx-large !important;
text-transform: uppercase;
background-color: #f5f7f7;
border: 1px solid rgb(238, 238, 238);
border-radius: 4px;
box-sizing: border-box;
}
}
}

.sites-dashboard:not(.preview-hidden) {
.sites-site-favicon {
display: flex;
margin-right: 0;
}

.a4a-layout__header {
align-items: center !important;
}

.sites-site-thumbnail,
.sites-manage-all-domains-button,
.a4a-layout__header-subtitle {
display: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as React from 'react';
import SiteFavicon from 'calypso/a8c-for-agencies/components/items-dashboard/site-favicon';
import SitesMigrationTrialBadge from 'calypso/sites-dashboard/components/sites-migration-trial-badge';
import SitesP2Badge from 'calypso/sites-dashboard/components/sites-p2-badge';
import { SiteItemThumbnail } from 'calypso/sites-dashboard/components/sites-site-item-thumbnail';
import { SiteName } from 'calypso/sites-dashboard/components/sites-site-name';
import { Truncated } from 'calypso/sites-dashboard/components/sites-site-url';
import SitesStagingBadge from 'calypso/sites-dashboard/components/sites-staging-badge';
Expand Down Expand Up @@ -88,16 +87,11 @@ const SiteField = ( { site, openSitePreviewPane }: Props ) => {
leading={
<Button className="sites-dataviews__preview-trigger" onClick={ onSiteClick } borderless>
<ListTileLeading title={ title }>
<SiteItemThumbnail
className="sites-site-thumbnail"
displayMode="list"
showPlaceholder={ false }
site={ site }
/>
<SiteFavicon
className="sites-site-favicon"
blogId={ site.ID }
isDotcomSite={ site.is_wpcom_atomic }
fallback="first-grapheme"
size={ 56 }
/>
</ListTileLeading>
</Button>
Expand Down
16 changes: 1 addition & 15 deletions client/sites-dashboard/components/sites-site-item-thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { addQueryArgs } from '@wordpress/url';
import classNames from 'classnames';
import { ComponentProps } from 'react';
import Image from 'calypso/components/image';
import { getFirstGrapheme } from 'calypso/lib/string';
import { P2Thumbnail } from './p2-thumbnail';
import { SiteComingSoon } from './sites-site-coming-soon';
import type { SitesDisplayMode } from './sites-display-mode-switcher';
Expand Down Expand Up @@ -131,18 +132,3 @@ export const SiteItemThumbnail = ( {
</SiteThumbnail>
);
};

function getFirstGrapheme( input: string ) {
if ( 'Segmenter' in Intl ) {
const segmenter = new Intl.Segmenter();
const [ firstSegmentData ] = segmenter.segment( input );

return firstSegmentData?.segment ?? '';
}

const codePoint = input.codePointAt( 0 );
if ( codePoint ) {
return String.fromCodePoint( codePoint );
}
return '';
}
Loading