Skip to content

Commit

Permalink
Prevent duplicate URL additions in NewGuru component
Browse files Browse the repository at this point in the history
Enhance URL input handling by filtering out duplicate URLs before adding them to the editor. Ensure only unique URLs are appended to the existing list, improving the user experience and preventing redundant entries.
  • Loading branch information
aralyekta committed Feb 20, 2025
1 parent 2a62842 commit 677bfd0
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/gurubase-frontend/src/components/NewGuru.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,26 @@ export default function NewGuru({ guruData, isProcessing }) {
.split("\n")
.filter((url) => url.trim());

// Add new URLs line by line
const updatedContent =
currentContent +
(currentContent && newUrls.length > 0 ? "\n" : "") +
newUrls.join("\n");

// Update editor content
setUrlEditorContent(updatedContent);

// Update form value
const allUrls = [...existingUrls, ...newUrls];
form.setValue("websiteUrls", allUrls);
// Filter out URLs that already exist in the editor
const uniqueNewUrls = newUrls.filter(
(url) => !existingUrls.includes(url)
);

// Only proceed if there are new unique URLs to add
if (uniqueNewUrls.length > 0) {
// Add new URLs line by line
const updatedContent =
currentContent +
(currentContent ? "\n" : "") +
uniqueNewUrls.join("\n");

// Update editor content
setUrlEditorContent(updatedContent);

// Update form value with all unique URLs
const allUrls = [...existingUrls, ...uniqueNewUrls];
form.setValue("websiteUrls", allUrls);
}
}
);

Expand Down

0 comments on commit 677bfd0

Please sign in to comment.