Skip to content

Commit 193078e

Browse files
Update buildspace#2
Gif submit added
1 parent de17d46 commit 193078e

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/App.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const App = () => {
2323
*/
2424

2525
const [walletAddress, setWalletAddress] = useState(null);
26+
const [inputValue, setInputValue] = useState('');
27+
const [gifList, setGifList] = useState([]);
2628

2729
const checkIfWalletIsConnected = async () => {
2830
// We're using optional chaining (question mark) to check if the object is null
@@ -52,6 +54,21 @@ const App = () => {
5254
}
5355
};
5456

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+
5572
const renderNotConnectedContainer = () => {
5673
return <button
5774
className="cta-button connect-wallet-button"
@@ -62,15 +79,30 @@ const App = () => {
6279

6380
const renderConnectedContainer = () => (
6481
<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>
6597
<div className="gif-grid">
66-
{TEST_GIFS.map(gif => (
98+
{gifList.map((gif) => (
6799
<div className="gif-item" key={gif}>
68100
<img src={gif} alt={gif}/>
69101
</div>
70102
))}
71103
</div>
72104
</div>
73-
)
105+
);
74106

75107
/*
76108
* When our component first mounts, let's check to see if we have a connected
@@ -84,6 +116,14 @@ const App = () => {
84116
return () => window.removeEventListener('load', onLoad);
85117
}, []);
86118

119+
useEffect(() => {
120+
if (walletAddress) {
121+
console.log('Fetching GIF list....');
122+
123+
setGifList(TEST_GIFS);
124+
}
125+
}, [walletAddress]);
126+
87127
return (
88128
<div className="App">
89129

0 commit comments

Comments
 (0)