Skip to content

Commit

Permalink
feat: auto filter keywords if they already exist instead of throwing …
Browse files Browse the repository at this point in the history
…error.

closes #244
  • Loading branch information
towfiqi committed Nov 7, 2024
1 parent 42a00da commit a09eb62
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/keywords/AddKeywords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ const AddKeywords = ({ closeModal, domain, keywords, scraperName = '', allowsCit
const keywordExist = keywordsArray.filter((k) => currentKeywords.includes(
`${k}-${newKeywordsData.device}-${newKeywordsData.country}${newKeywordsData.city ? `-${newKeywordsData.city}` : ''}`,
));
if (keywordExist.length > 0) {
if ((keywordsArray.length === 1 || currentKeywords.length === keywordExist.length) && keywordExist.length > 0) {
setError(`Keywords ${keywordExist.join(',')} already Exist`);
setTimeout(() => { setError(''); }, 3000);
} else {
const filteredKeywords = keywordsArray.filter((k) => !currentKeywords.includes(
`${k}-${newKeywordsData.device}-${newKeywordsData.country}${newKeywordsData.city ? `-${newKeywordsData.city}` : ''}`,
));
const { device, country, domain: kDomain, tags, city } = newKeywordsData;
const newKeywordsArray = keywordsArray.map((nItem) => ({ keyword: nItem, device, country, domain: kDomain, tags, city }));
const newKeywordsArray = filteredKeywords.map((nItem) => ({ keyword: nItem, device, country, domain: kDomain, tags, city }));
addMutate(newKeywordsArray);
}
} else {
Expand Down

0 comments on commit a09eb62

Please sign in to comment.