fix(thread-page): make thread auto updates opt-in (#1115)

* fix(thread-page): make thread auto updates opt-in

Wire `Auto` and `Update` to the same manual refresh path and cover the thread flow with an e2e harness.

* fix(thread-page): address PR review findings
This commit is contained in:
Tommaso Casaburi
2026-03-20 16:48:57 +08:00
committed by GitHub
parent ce2ad82c8c
commit 816281c607
13 changed files with 630 additions and 49 deletions
@@ -0,0 +1,40 @@
import { create } from 'zustand';
interface ThreadLiveUpdatesState {
enabled: boolean;
isUpdating: boolean;
updateRequestId: number;
repliesResetRequestId: number;
setEnabled: (enabled: boolean) => void;
toggleEnabled: () => void;
requestUpdate: () => void;
startUpdate: () => void;
finishUpdate: (requestId: number, shouldResetReplies?: boolean) => void;
resetState: () => void;
}
const defaultState = {
enabled: false,
isUpdating: false,
updateRequestId: 0,
repliesResetRequestId: 0,
};
const useThreadLiveUpdatesStore = create<ThreadLiveUpdatesState>((set) => ({
...defaultState,
setEnabled: (enabled) => set({ enabled }),
toggleEnabled: () => set((state) => ({ enabled: !state.enabled })),
requestUpdate: () =>
set((state) => ({
updateRequestId: state.updateRequestId + 1,
})),
startUpdate: () => set({ isUpdating: true }),
finishUpdate: (requestId, shouldResetReplies = true) =>
set((state) => ({
isUpdating: state.updateRequestId === requestId ? false : state.isUpdating,
repliesResetRequestId: shouldResetReplies ? Math.max(state.repliesResetRequestId, requestId) : state.repliesResetRequestId,
})),
resetState: () => set(defaultState),
}));
export default useThreadLiveUpdatesStore;