mirror of
https://github.com/towfiqi/serpbear
synced 2025-06-26 18:15:54 +00:00
feat: auto filter keywords if they already exist instead of throwing error.
closes #244
This commit is contained in:
parent
42a00dafad
commit
a09eb62f5a
@ -42,12 +42,15 @@ const AddKeywords = ({ closeModal, domain, keywords, scraperName = '', allowsCit
|
|||||||
const keywordExist = keywordsArray.filter((k) => currentKeywords.includes(
|
const keywordExist = keywordsArray.filter((k) => currentKeywords.includes(
|
||||||
`${k}-${newKeywordsData.device}-${newKeywordsData.country}${newKeywordsData.city ? `-${newKeywordsData.city}` : ''}`,
|
`${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`);
|
setError(`Keywords ${keywordExist.join(',')} already Exist`);
|
||||||
setTimeout(() => { setError(''); }, 3000);
|
setTimeout(() => { setError(''); }, 3000);
|
||||||
} else {
|
} 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 { 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);
|
addMutate(newKeywordsArray);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user