mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
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:
@@ -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;
|
||||
Reference in New Issue
Block a user