diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2024-02-04 17:33:39 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2024-02-04 17:33:39 -0500 |
| commit | 8aeaf9ab9884ed6f669633b1ab67c1ae219f7916 (patch) | |
| tree | 7153b7ec4ddc4a301d0ba4d09b4e359a36fd6e63 /src/components/Guestbook.jsx | |
| parent | 6cd9fb7c8964f8f1b3cc8137bbda45a633e62587 (diff) | |
| download | personal-website-8aeaf9ab9884ed6f669633b1ab67c1ae219f7916.tar.gz personal-website-8aeaf9ab9884ed6f669633b1ab67c1ae219f7916.tar.bz2 personal-website-8aeaf9ab9884ed6f669633b1ab67c1ae219f7916.zip | |
Guestbook refreshes once submitting a message
Diffstat (limited to 'src/components/Guestbook.jsx')
| -rw-r--r-- | src/components/Guestbook.jsx | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/src/components/Guestbook.jsx b/src/components/Guestbook.jsx index 498bbbe..41d0271 100644 --- a/src/components/Guestbook.jsx +++ b/src/components/Guestbook.jsx @@ -2,6 +2,7 @@ import { h, Component } from 'preact'; import { pb } from '../services/pocketbase'; import { formatDate } from "../util"; import sanitizeHtml from 'sanitize-html'; +import GuestbookForm from "./GuestbookForm.jsx"; class Guestbook extends Component { state = { @@ -25,29 +26,32 @@ class Guestbook extends Component { await this.fetchMessages(); } + refresh = async () => { + await this.fetchMessages(); + } + render() { const { message, error } = this.state; - if (error) { - return <p>{error}</p>; - } - - if (!message) { - return <p>Loading messages...</p>; - } - return ( <div> - <div class="grid"> - {message.map((g) => ( - <article class="card"> - <h1>Message from: {g.name}</h1> - <small>{formatDate(g.created)}</small> - <div dangerouslySetInnerHTML={{__html: sanitizeHtml(g.message)}}/> - {g.website && <a href={g.website}>Website</a>} - </article> - ))} - </div> + <GuestbookForm onMessageSent={this.refresh} /> + {error ? ( + <p>{error}</p> + ) : !message ? ( + <p>Loading messages...</p> + ) : ( + <div class="grid"> + {message.map((g) => ( + <article class="card"> + <h1>Message from: {g.name}</h1> + <small>{formatDate(g.created)}</small> + <div dangerouslySetInnerHTML={{__html: sanitizeHtml(g.message)}}/> + {g.website && <a href={g.website}>Website</a>} + </article> + ))} + </div> + )} </div> ); } |
