@@ -11,13 +11,22 @@ import { useEntityProp } from '@wordpress/core-data';
11
11
import { useEffect , useState } from '@wordpress/element' ;
12
12
import apiFetch from '@wordpress/api-fetch' ;
13
13
import { addQueryArgs } from '@wordpress/url' ;
14
+ import {
15
+ Button ,
16
+ ExternalLink ,
17
+ Placeholder ,
18
+ __experimentalHStack as HStack ,
19
+ __experimentalInputControl as InputControl ,
20
+ } from '@wordpress/components' ;
14
21
15
22
const Edit = ( {
16
23
attributes : { collection } ,
17
24
} ) => {
18
25
const [ apiKey , setApiKey ] = useEntityProp ( 'root' , 'site' , 'profile_blocks_lastfm_api_key' ) ;
19
26
const [ defaultProfile , setDefaultProfile ] = useEntityProp ( 'root' , 'site' , 'profile_blocks_lastfm_profile' ) ;
20
27
28
+ const [ showSetup , setShowSetup ] = useState ( ! ! apiKey ) ;
29
+
21
30
const [ items , setItems ] = useState ( [ ] ) ;
22
31
23
32
useEffect ( ( ) => {
@@ -48,6 +57,53 @@ const Edit = ( {
48
57
const blockProps = useBlockProps ( ) ;
49
58
const innerBlockProps = useInnerBlocksProps ( blockProps ) ;
50
59
60
+ if ( showSetup ) {
61
+ const onSubmit = ( event ) => {
62
+ event . preventDefault ( ) ;
63
+ setShowSetup ( false ) ;
64
+ } ;
65
+
66
+ return (
67
+ < div { ...blockProps } >
68
+ < Placeholder
69
+ label = { __ ( 'Profile Blocks for Last.FM' , 'profile-blocks-lastfm' ) }
70
+ icon = { null }
71
+ instructions = { __ ( 'Enter your Last.FM API key and default username. You can override the username for each block.' , 'profile-blocks-lastfm' ) }
72
+ >
73
+ < form onSubmit = { onSubmit } >
74
+ < HStack align = "end" >
75
+ < InputControl
76
+ __next40pxDefaultSize
77
+ value = { apiKey || '' }
78
+ className = "wp-block-profile-blocks-lastfm-top-charts__placeholder-input"
79
+ label = { __ ( 'API Key' , 'profile-blocks-lastfm' ) }
80
+ placeholder = { __ ( 'Enter your Last.fm API key' , 'profile-blocks-lastfm' ) }
81
+ onChange = { ( value ) => setApiKey ( value ) }
82
+ type = "password"
83
+ required
84
+ />
85
+ < InputControl
86
+ __next40pxDefaultSize
87
+ value = { defaultProfile || '' }
88
+ label = { __ ( 'Username' , 'profile-blocks-lastfm' ) }
89
+ placeholder = { __ ( 'Enter your Last.fm username' , 'profile-blocks-lastfm' ) }
90
+ onChange = { ( value ) => setDefaultProfile ( value ) }
91
+ required
92
+ />
93
+ < Button __next40pxDefaultSize variant = "primary" type = "submit" >
94
+ { __ ( 'Apply' , 'profile-blocks-lastfm' ) }
95
+ </ Button >
96
+ </ HStack >
97
+ </ form >
98
+
99
+ < ExternalLink href = "https://www.last.fm/api/authentication" rel = "noreferrer noopener" >
100
+ { __ ( 'Get your Last.fm API key' , 'profile-blocks-lastfm' ) }
101
+ </ ExternalLink >
102
+ </ Placeholder >
103
+ </ div >
104
+ ) ;
105
+ }
106
+
51
107
return (
52
108
< BlockContextProvider value = { { collection : items } } >
53
109
< div { ...innerBlockProps } />
0 commit comments