Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Shared options for the three task-list queries (tasks, summaries,
* slack tasks). Force a refetch on return-to-focus regardless of
* staleness — the global `staleTime` is 5 min, so
* `refetchOnWindowFocus: true` would silently skip the refetch in the
* exact window we care about (laptop opened after a short walk).
*/
export const TASK_LIST_QUERY_OPTIONS = {
refetchOnWindowFocus: "always" as const,
};
9 changes: 4 additions & 5 deletions apps/code/src/renderer/features/tasks/hooks/useTasks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pinnedTasksApi } from "@features/sidebar/hooks/usePinnedTasks";
import { TASK_LIST_QUERY_OPTIONS } from "@features/tasks/hooks/taskListQueryOptions";
import { workspaceApi } from "@features/workspace/hooks/useWorkspace";
import { useAuthenticatedMutation } from "@hooks/useAuthenticatedMutation";
import { useAuthenticatedQuery } from "@hooks/useAuthenticatedQuery";
Expand All @@ -14,8 +15,6 @@ import { useCallback } from "react";

const log = logger.scope("tasks");

const TASK_LIST_POLL_INTERVAL_MS = 30_000;

const taskKeys = {
all: ["tasks"] as const,
lists: () => [...taskKeys.all, "list"] as const,
Expand Down Expand Up @@ -53,7 +52,7 @@ export function useTasks(
}) as unknown as Promise<Task[]>,
{
enabled: (options?.enabled ?? true) && !!currentUser?.id,
refetchInterval: TASK_LIST_POLL_INTERVAL_MS,
...TASK_LIST_QUERY_OPTIONS,
},
);
}
Expand All @@ -67,7 +66,7 @@ export function useTaskSummaries(
(client) => client.getTaskSummaries(ids),
{
enabled: (options?.enabled ?? true) && ids.length > 0,
refetchInterval: TASK_LIST_POLL_INTERVAL_MS,
...TASK_LIST_QUERY_OPTIONS,
placeholderData: keepPreviousData,
},
);
Expand All @@ -91,7 +90,7 @@ export function useSlackTasks(options?: {
}) as unknown as Promise<Task[]>,
{
enabled: options?.enabled ?? true,
refetchInterval: TASK_LIST_POLL_INTERVAL_MS,
...TASK_LIST_QUERY_OPTIONS,
},
);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/code/src/renderer/stores/rendererWindowFocusStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { create } from "zustand";

/**
* True when the renderer document is visible and the window has OS focus.
* Used to pause inbox polling when the Electron window is in the background.
* Used to pause polling-style queries (inbox, task list, etc.) when the
* Electron window is in the background.
*/
function computeWindowFocused(): boolean {
if (typeof document === "undefined") {
Expand Down
Loading