From f6c0968139881e0ef0861a0d899f5d5aceb05f62 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 4 Feb 2024 20:51:17 -0500 Subject: Link to markdown guide; changed placeholder text; regex --- src/components/GuestbookForm.jsx | 19 ++++++++++++------- src/layouts/Default.astro | 1 + src/styles/GuestbookForm.css | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/components/GuestbookForm.jsx b/src/components/GuestbookForm.jsx index 26e32b1..e2283f0 100644 --- a/src/components/GuestbookForm.jsx +++ b/src/components/GuestbookForm.jsx @@ -7,7 +7,6 @@ import DOMPurify from 'dompurify'; class GuestbookForm extends Component { state = { name: '', - email: '', website: '', message: '', isMessageSent: false, @@ -24,13 +23,22 @@ class GuestbookForm extends Component { return; } + const urlRegex = /(https?:\/\/\S+)/g; + const imageRegex = /!\[.*]\(.*\)/g; + + if (urlRegex.test(this.state.message) || imageRegex.test(this.state.message)) { + this.setState({ + errorMessage: 'Links and images are not allowed.', + }); + return; + } + try { const messageHtml = marked(DOMPurify.sanitize(this.state.message)); await createMessage({ ...this.state, message: messageHtml }); this.setState({ name: '', - email: '', website: '', message: '', isMessageSent: true, @@ -56,14 +64,11 @@ class GuestbookForm extends Component { - - - - diff --git a/src/layouts/Default.astro b/src/layouts/Default.astro index 72851a4..c0eb569 100644 --- a/src/layouts/Default.astro +++ b/src/layouts/Default.astro @@ -88,6 +88,7 @@ const date = new Date(); a { text-decoration: none; color: #d7fcc9; + transition: ease-in-out 0.2s; } a:hover { diff --git a/src/styles/GuestbookForm.css b/src/styles/GuestbookForm.css index 42a5f8f..0ad343c 100644 --- a/src/styles/GuestbookForm.css +++ b/src/styles/GuestbookForm.css @@ -25,6 +25,7 @@ background-color: #609460; color: white; cursor: pointer; + transition: ease-in-out 0.2s; } .card form button:hover { -- cgit v1.2.3