diff --git a/src/activitys/MainApplication.tsx b/src/activitys/MainApplication.tsx index 8a8b2b4c..4b80ed6e 100644 --- a/src/activitys/MainApplication.tsx +++ b/src/activitys/MainApplication.tsx @@ -76,7 +76,12 @@ const MainApplication = () => { return [ { content: ( - } /> + } + /> ), tab: , }, diff --git a/src/activitys/fragments/ModuleFragment.tsx b/src/activitys/fragments/ModuleFragment.tsx index a300ebed..06fa83f7 100644 --- a/src/activitys/fragments/ModuleFragment.tsx +++ b/src/activitys/fragments/ModuleFragment.tsx @@ -36,6 +36,7 @@ export interface ModuleFragmentProps { modules: Array; group?: FlatListProps["group"]; disableNoInternet?: boolean; + searchBy?: string[]; renderItem: renderFunc; renderFixed?: RenderFunction; } @@ -118,7 +119,7 @@ const ModuleFragment = React.memo((props) => { sortBy={filter} search={{ term: search, - by: ["id", "name", "author"], + by: props.searchBy || ["id", "name", "author"], //onEveryWord: true, caseInsensitive: true, }} diff --git a/src/components/module/ExploreModule.tsx b/src/components/module/ExploreModule.tsx index bffbe617..0cbab747 100644 --- a/src/components/module/ExploreModule.tsx +++ b/src/components/module/ExploreModule.tsx @@ -13,7 +13,7 @@ import Typography from "@mui/material/Typography"; import { SuFile } from "@Native/SuFile"; import { useModFS } from "@Hooks/useModFS"; import { useModuleInfo } from "@Hooks/useModuleInfo"; -import { Verified, Tag, PersonOutline, CalendarMonth } from "@mui/icons-material"; +import { Verified, Tag, PersonOutline, CalendarMonth, Source } from "@mui/icons-material"; import { useBlacklist } from "@Hooks/useBlacklist"; import Box from "@mui/material/Box"; @@ -22,7 +22,7 @@ interface Props { } const ExploreModule = React.memo((props) => { - const { id, name, author, description, track, timestamp, version, versions, versionCode, features } = props.module; + const { id, name, author, description, track, timestamp, version, versions, versionCode, features, __mmrl_repo_source } = props.module; const { cover, verified } = useModuleInfo(props.module); const { context } = useActivity(); @@ -106,11 +106,24 @@ const ExploreModule = React.memo((props) => { {description} - - - - {strings("last_updated", { date: formatLastUpdate })} - + + + + + {strings("last_updated", { date: formatLastUpdate })} + + + + {__mmrl_repo_source && __mmrl_repo_source.join(", ")} + + {versionCode} diff --git a/src/hooks/useRepos.tsx b/src/hooks/useRepos.tsx index 825df0ba..0445899e 100644 --- a/src/hooks/useRepos.tsx +++ b/src/hooks/useRepos.tsx @@ -105,7 +105,7 @@ export const RepoProvider = (props: React.PropsWithChildren) => { os.toast("You can't add more than 5 repos", Toast.LENGTH_SHORT); } } else { - os.toast("This repo alredy exist", Toast.LENGTH_SHORT); + os.toast("This repo already exists", Toast.LENGTH_SHORT); } }; @@ -134,26 +134,38 @@ export const RepoProvider = (props: React.PropsWithChildren) => { ); React.useEffect(() => { - // Needs an another solution setModules([]); const fetchData = async () => { + const combinedModulesMap = new Map(); + for (const repo of repos) { if (disabledRepos.includes(repo.base_url)) continue; - fetch(`${repo.base_url}json/modules.json`) - .then((res) => { - if (!res.ok) throw new Error(res.statusText); - return res.json(); - }) - .then((json: Repo) => { - setModules((prev) => { - // Preventing duplicates - var ids = new Set(prev.map((d) => d.id)); - var merged = [...prev, ...json.modules.filter((d) => !ids.has(d.id))]; - return merged; - }); + try { + const res = await fetch(`${repo.base_url.slice(-1) !== "/" ? repo.base_url + "/" : repo.base_url}json/modules.json`); + if (!res.ok) throw new Error(res.statusText); + + const json: Repo = await res.json(); + + json.modules.forEach((mod) => { + if (!combinedModulesMap.has(mod.id)) { + // Add module with repo source if not already in map + combinedModulesMap.set(mod.id, { ...mod, __mmrl_repo_source: [repo.name] }); + } else { + // If already in map, append source repo name + const existingModule = combinedModulesMap.get(mod.id); + if (!existingModule.__mmrl_repo_source.includes(repo.name)) { + existingModule.__mmrl_repo_source.push(repo.name); + } + } }); + } catch (error) { + log.e((error as Error).message); + } } + + // Convert map to array for final combined list + setModules(Array.from(combinedModulesMap.values())); }; void fetchData(); diff --git a/src/typings/global.d.ts b/src/typings/global.d.ts index 8d77bc07..eebb1d14 100644 --- a/src/typings/global.d.ts +++ b/src/typings/global.d.ts @@ -224,6 +224,7 @@ declare global { * Local modules only */ __mmrl__local__module__?: boolean; + __mmrl_repo_source?: string[]; } export interface BaseTrack {