From 3366fdb5c460bc558a443036b31991854e2f7d15 Mon Sep 17 00:00:00 2001 From: Bhargav K Date: Thu, 4 Jun 2026 07:12:22 +0530 Subject: [PATCH] fix(links): prevent spam link submissions and handle React keys correctly --- src/components/LinksComponent.jsx | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/components/LinksComponent.jsx b/src/components/LinksComponent.jsx index 4291675..20be064 100644 --- a/src/components/LinksComponent.jsx +++ b/src/components/LinksComponent.jsx @@ -36,6 +36,14 @@ function ContributeModal({ isOpen, onClose, onSubmit }) { return } + if ( + title.trim().toLowerCase() === 'q' || + title.trim().toLowerCase() === 'test' + ) { + setSubmitError('Please enter a valid, descriptive title') + return + } + const validLinks = links.filter( (link) => link.url.trim() && link.description.trim() ) @@ -173,7 +181,17 @@ export function LinksComponent() { .orderBy('createdate', 'desc') .get() console.log(response) - const data = response.docs.map((doc) => doc.data()) + const data = response.docs + .map((doc) => ({ + id: doc.id, + ...doc.data(), + })) + .filter( + (item) => + item.title && + item.title.trim().toLowerCase() !== 'q' && + item.title.trim().toLowerCase() !== 'test' + ) setOtherlinks(data) setLoading(false) } catch (error) { @@ -251,7 +269,17 @@ export function LinksComponent() { .collection('otherlinks') .orderBy('createdate', 'desc') .get() - const newData = response.docs.map((doc) => doc.data()) + const newData = response.docs + .map((doc) => ({ + id: doc.id, + ...doc.data(), + })) + .filter( + (item) => + item.title && + item.title.trim().toLowerCase() !== 'q' && + item.title.trim().toLowerCase() !== 'test' + ) setOtherlinks(newData) } catch (err) { console.error('Error submitting links:', err)