@@ -23,6 +23,8 @@ const App = () => {
23
23
*/
24
24
25
25
const [ walletAddress , setWalletAddress ] = useState ( null ) ;
26
+ const [ inputValue , setInputValue ] = useState ( '' ) ;
27
+ const [ gifList , setGifList ] = useState ( [ ] ) ;
26
28
27
29
const checkIfWalletIsConnected = async ( ) => {
28
30
// We're using optional chaining (question mark) to check if the object is null
@@ -52,6 +54,21 @@ const App = () => {
52
54
}
53
55
} ;
54
56
57
+ const sendGif = async ( ) => {
58
+ if ( inputValue . length > 0 ) {
59
+ console . log ( 'Gif link' , inputValue ) ;
60
+ setGifList ( [ ...gifList , inputValue ] ) ;
61
+ setInputValue ( '' ) ;
62
+ } else {
63
+ console . log ( 'Empty input. Try again.' ) ;
64
+ }
65
+ } ;
66
+
67
+ const onInputChange = ( event ) => {
68
+ const { value } = event . target ;
69
+ setInputValue ( value ) ;
70
+ } ;
71
+
55
72
const renderNotConnectedContainer = ( ) => {
56
73
return < button
57
74
className = "cta-button connect-wallet-button"
@@ -62,15 +79,30 @@ const App = () => {
62
79
63
80
const renderConnectedContainer = ( ) => (
64
81
< div className = "connected-container" >
82
+ < form
83
+ onSubmit = { ( event ) => {
84
+ event . preventDefault ( ) ;
85
+ sendGif ( ) ;
86
+ } } >
87
+ < input
88
+ type = "text"
89
+ placeholder = "Enter gif link!"
90
+ value = { inputValue }
91
+ onChange = { onInputChange }
92
+ />
93
+ < button type = "submit" className = "cta-button submit-gif-button" >
94
+ Submit
95
+ </ button >
96
+ </ form >
65
97
< div className = "gif-grid" >
66
- { TEST_GIFS . map ( gif => (
98
+ { gifList . map ( ( gif ) => (
67
99
< div className = "gif-item" key = { gif } >
68
100
< img src = { gif } alt = { gif } />
69
101
</ div >
70
102
) ) }
71
103
</ div >
72
104
</ div >
73
- )
105
+ ) ;
74
106
75
107
/*
76
108
* When our component first mounts, let's check to see if we have a connected
@@ -84,6 +116,14 @@ const App = () => {
84
116
return ( ) => window . removeEventListener ( 'load' , onLoad ) ;
85
117
} , [ ] ) ;
86
118
119
+ useEffect ( ( ) => {
120
+ if ( walletAddress ) {
121
+ console . log ( 'Fetching GIF list....' ) ;
122
+
123
+ setGifList ( TEST_GIFS ) ;
124
+ }
125
+ } , [ walletAddress ] ) ;
126
+
87
127
return (
88
128
< div className = "App" >
89
129
0 commit comments