79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from pathlib import Path
|
|
import re
|
|
|
|
p = Path(r"c:\Users\admin\Desktop\douyinWEB\frontend\src\app\shorts\page.tsx")
|
|
t = p.read_text(encoding="utf-8")
|
|
|
|
t = t.replace(
|
|
"const [pending, setPending] = useState<Record<string, true>>({});",
|
|
"const [actionPending, setActionPending] = useState<Record<string, true>>({});",
|
|
1,
|
|
)
|
|
t = t.replace(
|
|
"const isPending = useCallback((key: string) => Boolean(pending[key]), [pending]);",
|
|
"const isPending = useCallback((key: string) => Boolean(actionPending[key]), [actionPending]);",
|
|
1,
|
|
)
|
|
old_wp = """ const withPending = useCallback(async (key: string, fn: () => Promise<void>) => {
|
|
setPending((p) => (p[key] ? p : { ...p, [key]: true }));
|
|
try {
|
|
await fn();
|
|
} finally {
|
|
setPending((p) => {
|
|
const n = { ...p };
|
|
delete n[key];
|
|
return n;
|
|
});
|
|
}
|
|
}, []);"""
|
|
new_wp = """ const withPending = useCallback(async (key: string, fn: () => Promise<void>) => {
|
|
setActionPending((p) => (p[key] ? p : { ...p, [key]: true }));
|
|
try {
|
|
await fn();
|
|
} finally {
|
|
setActionPending((p) => {
|
|
const n = { ...p };
|
|
delete n[key];
|
|
return n;
|
|
});
|
|
}
|
|
}, []);"""
|
|
if old_wp not in t:
|
|
raise SystemExit("withPending block missing")
|
|
t = t.replace(old_wp, new_wp, 1)
|
|
|
|
t = t.replace('busy={busy}', 'busy={isPending("quota")}')
|
|
t = t.replace(
|
|
"{busy ? <Loader2 className=\"h-3.5 w-3.5 animate-spin\" /> : <KeyRound className=\"h-3.5 w-3.5\" />}",
|
|
'{isPending("saveChannel") ? <Loader2 className="h-3.5 w-3.5 animate-spin" /> : <KeyRound className="h-3.5 w-3.5" />}',
|
|
)
|
|
|
|
# Wrap DailyQuota onSave/onApply to mark quota pending? optional — busy prop already isPending quota
|
|
# but nothing sets it. Change busy={false} for quota card or wire withPending in callbacks.
|
|
t = t.replace('busy={isPending("quota")}', "busy={false}")
|
|
|
|
# Find remaining bare `busy` identifiers
|
|
print("--- leftover busy ---")
|
|
for i, line in enumerate(t.splitlines(), 1):
|
|
if "busy" not in line:
|
|
continue
|
|
if any(
|
|
x in line
|
|
for x in (
|
|
"uploadBusy",
|
|
"status?.busy",
|
|
"busy={uploadBusy}",
|
|
"busy={togglingId",
|
|
"busy={false}",
|
|
"busy={isPending",
|
|
"· 忙碌",
|
|
)
|
|
):
|
|
continue
|
|
if re.search(r"(?<![\w.])busy(?![\w])", line):
|
|
print(i, line.strip()[:160])
|
|
|
|
p.write_text(t, encoding="utf-8")
|
|
print("ok")
|