Skip to content
Draft
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
27 changes: 4 additions & 23 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ import {
togglePendingUserInputOptionSelection,
type PendingUserInputDraftAnswer,
} from "../pendingUserInput";
import { useUiStateStore } from "../uiStateStore";
import {
buildPlanImplementationThreadTitle,
buildPlanImplementationPrompt,
Expand All @@ -109,6 +108,7 @@ import {
type Thread,
type TurnDiffSummary,
} from "../types";
import { useMarkActiveThreadVisited } from "../hooks/useMarkActiveThreadVisited";
import { useTheme } from "../hooks/useTheme";
import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
import { isCommandPaletteOpen } from "../commandPaletteContext";
Expand Down Expand Up @@ -1036,9 +1036,9 @@ function ChatViewContent(props: ChatViewProps) {
const composerDraftTarget: ScopedThreadRef | DraftId =
routeKind === "server" ? routeThreadRef : props.draftId;
const serverThread = useThread(routeKind === "server" ? routeThreadRef : null);
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);
const activeThreadLastVisitedAt = useUiStateStore((store) =>
routeKind === "server" ? store.threadLastVisitedAtById[routeThreadKey] : undefined,
useMarkActiveThreadVisited(
routeKind === "server" ? routeThreadKey : null,
serverThread?.latestTurn?.completedAt ?? null,
);
const settings = useEnvironmentSettings(environmentId);
const setStickyComposerModelSelection = useComposerDraftStore(
Expand Down Expand Up @@ -1599,25 +1599,6 @@ function ChatViewContent(props: ChatViewProps) {
[openOrReuseProjectDraftThread],
);

useEffect(() => {
if (!serverThread?.id) return;
const threadUpdatedAt = Date.parse(serverThread.updatedAt);
if (Number.isNaN(threadUpdatedAt)) return;
const lastVisitedAt = activeThreadLastVisitedAt ? Date.parse(activeThreadLastVisitedAt) : NaN;
if (!Number.isNaN(lastVisitedAt) && lastVisitedAt >= threadUpdatedAt) return;

markThreadVisited(
scopedThreadKey(scopeThreadRef(serverThread.environmentId, serverThread.id)),
serverThread.updatedAt,
);
}, [
activeThreadLastVisitedAt,
markThreadVisited,
serverThread?.environmentId,
serverThread?.id,
serverThread?.updatedAt,
]);

const selectedProviderByThreadId = composerActiveProvider ?? null;
const threadProvider =
activeThread?.modelSelection.instanceId ??
Expand Down
17 changes: 17 additions & 0 deletions apps/web/src/hooks/useMarkActiveThreadVisited.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect } from "react";

import { useUiStateStore } from "../uiStateStore";

export function useMarkActiveThreadVisited(
threadKey: string | null,
latestTurnCompletedAt: string | null,
): void {
const markThreadVisited = useUiStateStore((store) => store.markThreadVisited);

useEffect(() => {
if (threadKey === null || latestTurnCompletedAt === null) {
return;
}
markThreadVisited(threadKey, latestTurnCompletedAt);
}, [latestTurnCompletedAt, markThreadVisited, threadKey]);
}
Loading