fix: force paint before API call so status feedback is visible
- requestAnimationFrame flush lets React paint the "Stopping..." message before the async API call begins - Lists never go empty thanks to fallbackData on all SWR hooks - State synced on success to keep summary counts in sync Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -36,6 +36,8 @@ export default function Dashboard() {
|
|||||||
const label = action.charAt(0).toUpperCase() + action.slice(1);
|
const label = action.charAt(0).toUpperCase() + action.slice(1);
|
||||||
const kind = type === 'qemu' ? 'VM' : 'LXC';
|
const kind = type === 'qemu' ? 'VM' : 'LXC';
|
||||||
setPowerActionStatus({ text: `${label}ing ${kind} ${vmid}...`, type: 'pending' });
|
setPowerActionStatus({ text: `${label}ing ${kind} ${vmid}...`, type: 'pending' });
|
||||||
|
// Flush the pending status so it paints before the API call
|
||||||
|
await new Promise((r) => requestAnimationFrame(r));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post('/api/power', { node, vmid, type, action });
|
await axios.post('/api/power', { node, vmid, type, action });
|
||||||
@@ -47,7 +49,6 @@ export default function Dashboard() {
|
|||||||
axios.get('/api/status'),
|
axios.get('/api/status'),
|
||||||
]);
|
]);
|
||||||
setPowerActionStatus({ text: `${label} successful`, type: 'success' });
|
setPowerActionStatus({ text: `${label} successful`, type: 'success' });
|
||||||
// Update local state so summary counts stay in sync until poll
|
|
||||||
setNodes(nodesRes.data.data);
|
setNodes(nodesRes.data.data);
|
||||||
setVms(vmsRes.data.data);
|
setVms(vmsRes.data.data);
|
||||||
setLxc(lxcRes.data.data);
|
setLxc(lxcRes.data.data);
|
||||||
|
|||||||
Reference in New Issue
Block a user