-
Notifications
You must be signed in to change notification settings - Fork 6
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
Added the ability to change player skin #60
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eef4009
Added the ability to change player skin
zamanq 5939a80
Minor CSS lint fix
zamanq c467388
Little spacing issue fix
zamanq 06ee4a4
Merge branch 'develop' of github.com:10up/retro-winamp-block into add/5
zamanq f144cb8
Refactoring
zamanq 88cabfa
fix linting errors
Sidsector9 ca8d2be
regenrate package-lock.json
Sidsector9 a2a3013
fix pipeline
Sidsector9 fb70116
fix css linting errors
Sidsector9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,15 @@ import { concat } from 'lodash'; | |
import { __ } from '@wordpress/i18n'; | ||
import { compose } from '@wordpress/compose'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
import { PanelBody, TextControl, withNotices } from '@wordpress/components'; | ||
import { PanelBody, TextControl, withNotices, ToggleControl } from '@wordpress/components'; | ||
import { | ||
useBlockProps, | ||
InspectorControls, | ||
store as blockEditorStore, | ||
MediaPlaceholder, | ||
} from '@wordpress/block-editor'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { Platform, useMemo } from '@wordpress/element'; | ||
import { Platform, useMemo, useState } from '@wordpress/element'; | ||
import { createBlobURL } from '@wordpress/blob'; | ||
|
||
/** | ||
|
@@ -77,6 +77,15 @@ function Edit( props ) { | |
[ clientId ] | ||
); | ||
|
||
const [ useCustomUrl, setUseCustomUrl ] = useState( false ); | ||
|
||
const defaultSkins = [ | ||
'https://skins.webamp.org/skin/5e4f10275dcb1fb211d4a8b4f1bda236/base-2.91.wsz/', | ||
'https://skins.webamp.org/skin/cd251187a5e6ff54ce938d26f1f2de02/Winamp3_Classified_v5.5.wsz/', | ||
'https://skins.webamp.org/skin/6856045909b0040283b43c53a002de69/Blue_Fade.wsz/', | ||
'https://skins.webamp.org/skin/a5b4d732f406dd30164ef88358044f03/Samsara-amp.wsz/', | ||
]; | ||
|
||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const audio = useMemo( | ||
() => | ||
|
@@ -201,20 +210,62 @@ function Edit( props ) { | |
return <div { ...blockProps }>{ mediaPlaceholder }</div>; | ||
} | ||
|
||
const skinPreviewUrl = ( skin ) => { | ||
if ( skin ) { | ||
const match = skin.match( | ||
/(?:https?:)?(?:\/\/)?skins\.webamp\.org\/skin\/(\w+)\/(?:.*)?/ | ||
); | ||
|
||
if ( match && match.length === 2 ) { | ||
return `https://cdn.webampskins.org/screenshots/${ match[ 1 ] }.png`; | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Winamp Player Skin', 'winamp-block' ) }> | ||
<TextControl | ||
label={ __( 'Skin URL', 'winamp-block' ) } | ||
help={ __( | ||
'The URL of the player skin to use. Find skins at https://skins.webamp.org/.', | ||
'winamp-block' | ||
) } | ||
value={ currentSkin } | ||
onChange={ ( skin ) => | ||
setAttributes( { currentSkin: skin } ) | ||
} | ||
{ useCustomUrl ? ( | ||
<TextControl | ||
label={ __( 'Skin URL', 'winamp-block' ) } | ||
help={ __( | ||
'The URL of the player skin to use. Find skins at https://skins.webamp.org/.', | ||
'winamp-block' | ||
) } | ||
value={ currentSkin } | ||
onChange={ ( skin ) => | ||
setAttributes( { currentSkin: skin } ) | ||
} | ||
/> | ||
) | ||
: | ||
( | ||
<div className="preview-wrapper"> | ||
{ defaultSkins.length && defaultSkins.map( ( skin, index ) => { | ||
return ( | ||
<label key={ index } className="winamp-radio-wrapper"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sidsector9 Done as well. |
||
<input | ||
type="radio" | ||
name="current-skin" | ||
value={ skin } | ||
checked={ currentSkin === skin } | ||
onChange={ ( e ) => | ||
setAttributes( { currentSkin: e.target.value } ) | ||
} | ||
/> | ||
<img src={ skinPreviewUrl( skin ) } width="100" alt="winamp-skin" /> | ||
</label> | ||
) | ||
} ) | ||
} | ||
</div> | ||
) | ||
} | ||
<ToggleControl | ||
label={ __( 'Use Custom Skin?', 'winamp-block' ) } | ||
checked={ useCustomUrl } | ||
onChange={ () => setUseCustomUrl( ! useCustomUrl ) } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
|
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.
Thanks for working on this!
Because the hook is called after a return, that makes it conditional and violates the usage rules of hooks.
Can you move
useState
to before line 58?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.
@Sidsector9 Makes sense. done. Thanks!