perf: reduce repeated collection traversal
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
VideoCameraOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import type { ReactNode } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import "../../styles/pages/more.css";
|
||||
import type { WebImageWorkbenchTool, WebViewKey } from "../../types";
|
||||
|
||||
@@ -144,9 +144,12 @@ function MorePage({ onSelectView, onOpenImageTool }: MorePageProps) {
|
||||
return t.category === filter;
|
||||
});
|
||||
|
||||
const recentTools = recentIds
|
||||
.map((id) => tools.find((t) => t.id === id))
|
||||
.filter((t): t is MoreTool => Boolean(t) && (t?.ready ?? false));
|
||||
const toolById = useMemo(() => new Map(tools.map((tool) => [tool.id, tool])), []);
|
||||
const recentTools = recentIds.reduce<MoreTool[]>((acc, id) => {
|
||||
const tool = toolById.get(id);
|
||||
if (tool?.ready) acc.push(tool);
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
const groupedTools = filteredTools.reduce<Record<ToolCategory, MoreTool[]>>((acc, t) => {
|
||||
if (!acc[t.category]) acc[t.category] = [];
|
||||
|
||||
Reference in New Issue
Block a user