MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / refreshMatch

Function refreshMatch

src/pages/components/ScriptSetting/Match.tsx:43–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41 };
42
43 const refreshMatch = () => {
44 if (script) {
45 // 从数据库中获取是简单处理数据一致性的问题
46 scriptDAO.get(script.uuid).then((res) => {
47 if (!res) {
48 return;
49 }
50 const matchArr = res.selfMetadata?.match || res.metadata.match || [];
51 const matchMap = new Map<string, boolean>();
52 res.metadata.match?.forEach((m) => {
53 matchMap.set(m, true);
54 });
55 const v: MatchItem[] = [];
56 matchArr.forEach((value, index) => {
57 v.push({
58 id: index,
59 match: value,
60 byUser: !matchMap.has(value),
61 hasMatch: false,
62 isExclude: false,
63 });
64 });
65 setMatch(v);
66
67 const excludeArr = res.selfMetadata?.exclude || res.metadata.exclude || [];
68 const excludeMap = new Map<string, boolean>();
69 res.metadata.exclude?.forEach((m) => {
70 excludeMap.set(m, true);
71 });
72 const e: MatchItem[] = [];
73 excludeArr.forEach((value, index) => {
74 const hasMatch = matchMap.has(value);
75 e.push({
76 id: index,
77 match: value,
78 byUser: !excludeMap.has(value),
79 hasMatch,
80 isExclude: true,
81 });
82 });
83 setExclude(e);
84 });
85 }
86 };
87
88 useEffect(() => {
89 refreshMatch();

Callers 3

updateMatchAndRefreshFunction · 0.85
updateExcludeAndRefreshFunction · 0.85
MatchFunction · 0.85

Calls 5

forEachMethod · 0.80
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected