| 1 |
import { flushChatStorage } from '@agent/state/chat'; |
| 2 |
import { useStatusStore } from '@agent/state/status'; |
| 3 |
|
| 4 |
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); |
| 5 |
|
| 6 |
// Components navigate through this so the pending chat save always lands first. |
| 7 |
export const doReload = async (url) => { |
| 8 |
const flush = flushChatStorage(); |
| 9 |
// Quick saves skip the overlay; once shown it holds 1s so it never flashes. |
| 10 |
const saveIsSlow = await Promise.race([ |
| 11 |
flush.then(() => false), |
| 12 |
wait(2000).then(() => true), |
| 13 |
]); |
| 14 |
if (saveIsSlow) { |
| 15 |
useStatusStore.getState().setLeavingPage(true); |
| 16 |
await Promise.all([flush, wait(1000)]); |
| 17 |
} |
| 18 |
if (url) return window.location.assign(url); |
| 19 |
window.location.reload(); |
| 20 |
}; |
| 21 |
|