# -*- 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>({});", "const [actionPending, setActionPending] = useState>({});", 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) => { 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) => { 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 ? : }", '{isPending("saveChannel") ? : }', ) # 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"(?