Added CurseForge mod support
Co-authored-by: felix-fx-top <253056634+felix-fx-top@users.noreply.github.com>
This commit is contained in:
parent
1b5a724f23
commit
c9f1569dc4
@ -30,20 +30,34 @@ const SearchPage = () => {
|
||||
: "";
|
||||
|
||||
const { data, isLoading } = useQuery({
|
||||
queryKey: ["search", initialQuery, translatedText, platform],
|
||||
queryKey: ["search", initialQuery, translatedText, platform, source],
|
||||
queryFn: async () => {
|
||||
const searchTerm = translatedText || initialQuery;
|
||||
const result = await searchMods(searchTerm, 0, 20, facets);
|
||||
|
||||
if (autoTranslate && !translatedText && result.total_hits === 0 && initialQuery) {
|
||||
const modrinthPromise = source !== "curseforge"
|
||||
? searchMods(searchTerm, 0, 20, facets)
|
||||
: Promise.resolve({ hits: [], total_hits: 0 });
|
||||
|
||||
const cfPromise = source !== "modrinth"
|
||||
? searchCurseForge(searchTerm, 0, 20)
|
||||
: Promise.resolve({ data: [], pagination: { totalCount: 0 } });
|
||||
|
||||
const [modrinthResult, cfResult] = await Promise.all([modrinthPromise, cfPromise]);
|
||||
|
||||
const totalHits = (modrinthResult.total_hits || 0) + (cfResult.pagination?.totalCount || 0);
|
||||
|
||||
if (autoTranslate && !translatedText && totalHits === 0 && initialQuery) {
|
||||
setIsTranslating(true);
|
||||
try {
|
||||
const { translated } = await translateQuery(initialQuery);
|
||||
if (translated !== initialQuery) {
|
||||
setTranslatedText(translated);
|
||||
const translatedResult = await searchMods(translated, 0, 20, facets);
|
||||
const [mr, cr] = await Promise.all([
|
||||
source !== "curseforge" ? searchMods(translated, 0, 20, facets) : Promise.resolve({ hits: [], total_hits: 0 }),
|
||||
source !== "modrinth" ? searchCurseForge(translated, 0, 20) : Promise.resolve({ data: [], pagination: { totalCount: 0 } }),
|
||||
]);
|
||||
setIsTranslating(false);
|
||||
return translatedResult;
|
||||
return { modrinth: mr, curseforge: cr };
|
||||
}
|
||||
} catch {
|
||||
toast.error("فشل في ترجمة البحث");
|
||||
@ -51,7 +65,7 @@ const SearchPage = () => {
|
||||
setIsTranslating(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
return { modrinth: modrinthResult, curseforge: cfResult };
|
||||
},
|
||||
enabled: !!initialQuery,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user