code refactor

This commit is contained in:
MaysWind
2023-08-13 15:03:31 +08:00
parent f6a2246aab
commit 66f0b38008
6 changed files with 50 additions and 76 deletions
+16
View File
@@ -0,0 +1,16 @@
export function getColorsInRows(allColorInfos, itemPerRow) {
const ret = [];
let rowCount = -1;
for (let i = 0; i < allColorInfos.length; i++) {
if (i % itemPerRow === 0) {
ret[++rowCount] = [];
}
ret[rowCount].push({
color: allColorInfos[i]
});
}
return ret;
}
+26
View File
@@ -0,0 +1,26 @@
export function getIconsInRows(allIconInfos, itemPerRow) {
const ret = [];
let rowCount = 0;
for (let iconInfoId in allIconInfos) {
if (!Object.prototype.hasOwnProperty.call(allIconInfos, iconInfoId)) {
continue;
}
const iconInfo = allIconInfos[iconInfoId];
if (!ret[rowCount]) {
ret[rowCount] = [];
} else if (ret[rowCount] && ret[rowCount].length >= itemPerRow) {
rowCount++;
ret[rowCount] = [];
}
ret[rowCount].push({
id: iconInfoId,
icon: iconInfo.icon
});
}
return ret;
}