Skip to content

Commit

Permalink
Step 15: Prettifying Your Web3 App
Browse files Browse the repository at this point in the history
  • Loading branch information
avasisht23 committed Nov 2, 2022
1 parent ec70d66 commit 68bb071
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions app/pages/index.tsx
Expand Up @@ -13,6 +13,7 @@ export default function Home() {
const [messageAuthor, setMessageAuthor] = useState("");
const [messageTime, setMessageTime] = useState(0);
const [inputtedMessage, setInputtedMessage] = useState("");
const [loading, setLoading] = useState(false);

const wallet = useAnchorWallet();
const mounted = useIsMounted();
Expand All @@ -39,6 +40,7 @@ export default function Home() {
className={styles.message_button}
disabled={!inputtedMessage}
onClick={async () => {
setLoading(true);
const deployedMessage = message
? await updateMessage(inputtedMessage, wallet, messageAccount)
: await createMessage(
Expand All @@ -53,23 +55,32 @@ export default function Home() {
setMessageTime(deployedMessage.timestamp.toNumber() * 1000);
setInputtedMessage("");
}
setLoading(false);
}}
>
{message ? "Update the Message!" : "Create a Message!"}
</button>
</div>
)}

{wallet && message && (
<div className={styles.card}>
<h2>Current Message: {message}</h2>
<h2>
Message Author: {messageAuthor.substring(0, 4)}
...
{messageAuthor.slice(-4)}
</h2>
<h2>Time Published: {new Date(messageTime).toLocaleString()}</h2>
{loading ? (
<div className={styles.loader_bar}>
<h2> Loading</h2>
<div className={styles.loader} />
</div>
) : (
wallet &&
message && (
<div className={styles.card}>
<h2>Current Message: {message}</h2>
<h2>
Message Author: {messageAuthor.substring(0, 4)}
...
{messageAuthor.slice(-4)}
</h2>
<h2>Time Published: {new Date(messageTime).toLocaleString()}</h2>
</div>
)
)}
</div>
</div>
Expand Down

0 comments on commit 68bb071

Please sign in to comment.