-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Replace design screenshots with mShots in New Onboarding #43428
Merged
lsl
merged 17 commits into
trunk
from
update/gutenboarding-to-use-mshots-for-design-thumbnails
Jan 22, 2021
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
244ba19
Try using mshots for fetching vertically oriented screenshots in the …
andrewserong 48fce1d
Add spinner and fade when image is loaded
andrewserong 7888faa
Add gutenboarding/mshot-preview feature check for MshotsImage component
andrewserong 5d449c0
Set no-cache in request
andrewserong f25fa2d
Emphasize/clarify image size parameters (props @simison)
22c678a
Use the design name in the preview (rather than the parent)
7cbd0b7
Set mshots preview in development environment, add crossOrigin to pre…
andrewserong ed673ec
Replace spinner with pulsing grey box
andrewserong 15bfa8a
Update getDesignImageUrl to use locale, tweak fetch logic
andrewserong 53436f8
Remove mshots flag from development.json environment
andrewserong dd1496c
Switch to useLocale - I18nLocale no longer available?
lsl e61aab1
Re-instate prefetching in intent aquisition
lsl baad55b
Prefetch with locale
lsl 5401689
Keep prefetch behind config flag
lsl ac346dd
Try new method of loading images from mshots to avoid default image d…
lsl 14305af
Tidy up, remove prefetch while we work on a CORS fix
lsl 900d933
Only refresh up to 10 times
lsl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
client/landing/gutenboarding/components/mshots-image/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { useState } from 'react'; | ||
import classnames from 'classnames'; | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Style dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
interface MShotsImageProps { | ||
url: string; | ||
alt: string; | ||
'aria-labelledby': string; | ||
} | ||
|
||
const mShotsParams = { | ||
// viewport size (how much of the source page to capture) | ||
vpw: 1200, | ||
vph: 3072, | ||
// size of the resulting image | ||
w: 700, | ||
h: 1800, | ||
}; | ||
|
||
export function mshotsUrl( url: string, count = 0 ): string { | ||
const mshotsUrl = 'https://s0.wp.com/mshots/v1/'; | ||
const mshotsRequest = addQueryArgs( mshotsUrl + encodeURIComponent( url ), { | ||
...mShotsParams, | ||
// this doesn't seem to work: | ||
lsl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// requeue: true, // Uncomment this line to force the screenshots to be regenerated | ||
count, | ||
} ); | ||
return mshotsRequest; | ||
} | ||
|
||
const MShotsImage = ( { | ||
url, | ||
'aria-labelledby': labelledby, | ||
alt, | ||
}: MShotsImageProps ): JSX.Element => { | ||
const [ count, setCount ] = React.useState( 0 ); | ||
const [ visible, setVisible ] = useState( false ); | ||
return ( | ||
<div className="mshots-image__container"> | ||
{ ! visible && <div className="mshots-image__loader"></div> } | ||
<img | ||
className={ classnames( 'mshots-image' ) } | ||
style={ { opacity: visible ? 1 : 0 } } | ||
alt={ alt } | ||
aria-labelledby={ labelledby } | ||
src={ mshotsUrl( url, count ) } | ||
onLoad={ ( e ) => { | ||
// Test against mshots h value | ||
if ( e.currentTarget.naturalHeight !== mShotsParams.h ) { | ||
// Only refresh 10 times. | ||
if ( count < 10 ) { | ||
// Triggers a target.src change | ||
setTimeout( () => setCount( count + 1 ), 1000 ); | ||
} | ||
} else { | ||
setVisible( true ); | ||
} | ||
} } | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default MShotsImage; |
19 changes: 19 additions & 0 deletions
19
client/landing/gutenboarding/components/mshots-image/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import '../../mixins.scss'; | ||
|
||
.mshots-image { | ||
opacity: 0; | ||
transition: 0.3s opacity; | ||
} | ||
|
||
.mshots-image__loader { | ||
@include onboarding-placeholder(); | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.mshots-image-visible { | ||
opacity: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we exclude
site_title
, we'd more often have previews generated already instead of needing to generate for each customer separately.That said, if it works, would be really cool to include it in thumbnails. 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually the theme title (maybe it wasn't previously?) I think I'll try using users title tomorrow, see how it goes, prefetching seems to work decently well at the moment.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, gotcha! Users title would be awesome of course — it'll just potentially generate a whole lot more mshots images once this is live to more people, so might be good to give systems heads up?
Also just slower since every image needs to be generated for each user, but good to test how that tradeoff looks like? My preference is on speed.