MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / loadMods

Function loadMods

frontend/src/widgets/instance/mod-manager/useLocalMods.ts:50–115  ·  view source on GitHub ↗
(folder?: string)

Source from the content-addressed store, hash-verified

48 });
49
50 const loadMods = async (folder?: string) => {
51 loading.value = true;
52 currentFolder.value = folder;
53 try {
54 const { execute } = modListApi();
55 const res = await execute({
56 params: {
57 uuid: instanceId,
58 daemonId: daemonId,
59 page: tablePagination.current,
60 pageSize: tablePagination.pageSize,
61 folder
62 }
63 });
64 const newMods = res.value?.mods || [];
65 folders.value = res.value?.folders || [];
66 fileStatus.value = res.value || {};
67 totalMods.value = res.value?.total || 0;
68 tablePagination.total = res.value?.total || 0;
69
70 // Keep existing extraInfo to avoid UI flickering
71 const oldModsMap = new Map();
72 mods.value.forEach((m) => {
73 if (m.file) oldModsMap.set(m.file, m);
74 if (m.hash) oldModsMap.set(m.hash, m);
75 });
76
77 newMods.forEach((newMod) => {
78 const oldMod = oldModsMap.get(newMod.file) || oldModsMap.get(newMod.hash);
79 if (oldMod && oldMod.extraInfo) {
80 newMod.extraInfo = oldMod.extraInfo;
81 }
82 });
83 mods.value = newMods;
84 loading.value = false;
85
86 // Fetch extra info for current page mods in batch (Background)
87 const hashes = mods.value
88 .filter((m) => !m.extraInfo)
89 .map((m) => m.hash)
90 .filter((h) => !!h);
91 if (hashes.length > 0) {
92 loadingExtra.value = true;
93 try {
94 const { execute: fetchBatchInfo } = getModBatchInfoApi();
95 const batchRes = await fetchBatchInfo({
96 data: { hashes }
97 });
98 if (batchRes.value) {
99 mods.value.forEach((mod) => {
100 if (mod.hash && batchRes.value![mod.hash]) {
101 mod.extraInfo = batchRes.value![mod.hash];
102 }
103 });
104 }
105 } catch (e) {
106 console.error("Fetch batch info error:", e);
107 } finally {

Callers 4

immediateFnFunction · 0.85
useModUploadFunction · 0.85
useLocalModsFunction · 0.85
startPollingFunction · 0.85

Calls 4

executeFunction · 0.85
errorMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected