Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Chat: move the version arrows into their own file

luishron12366416b6e79e2
diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx
index c1242a1ab2..a45019dc47 100644
--- a/src/components/ChatView.tsx
+++ b/src/components/ChatView.tsx
@@ -3,12 +3,13 @@ import { useAdvancedMode } from "@/lib/interface-mode";
import { PHONE_LAYOUT, useMediaQuery } from "@/lib/use-media-query";
import { ThreadLinkContext } from "@/components/ThreadLinkMenu";
import { useShowThreads } from "@/lib/thread-preferences";
-import { AlertTriangle, ChevronLeft, ChevronRight, Monitor, RefreshCw, Square, Webhook } from "lucide-react";
+import { AlertTriangle, ChevronRight, Monitor, RefreshCw, Square, Webhook } from "lucide-react";
import { WorkingDots } from "@/components/WorkingIndicator";
import { ChatBusyContext, CopyButton, MESSAGE_ROW, MessageActions, messageActionClass, ReplyAction } from "@/components/MessageActions";
import { ReactAction, ReactionChips } from "@/components/Reactions";
import { replyAndCopy, useBotMessageMenu, userMessageMenu } from "@/components/message-menu";
import { forkMessageItem, ForkLinks, useForkedMessages } from "@/components/ForkMessage";
+import { VersionSwitch } from "@/components/VersionSwitch";
import { savesToTeamMemory, TEAM_MEMORY_ITEM, TeamMemorySavesContext } from "@/components/conversation-share/conversation-share";
import { useSpeech } from "@/lib/tts/useSpeech";
import { localSystemVoiceActive } from "@/lib/local-voice";
@@ -259,34 +260,6 @@ export function FailedTurnRow({ tool, engine, onRetry, botId, threadId, messageA
export { MessageBoundary };
-function VersionSwitch({ versions, index, onSwitch }: { versions: readonly Message[]; index: number; onSwitch: (version: Message) => void }) {
- const busy = use(ChatBusyContext);
- const go = (version: Message | undefined) => { if (version && !busy) onSwitch(version); };
- return (
- <div className="mt-1 flex items-center gap-0.5 pr-1 text-[12px] text-ink-secondary">
- <button
- onClick={() => go(versions[index - 1])}
- disabled={index <= 0 || busy}
- className="rounded p-0.5 hover:bg-raised hover:text-ink disabled:opacity-30 disabled:hover:bg-transparent"
- title={t("chat.previousVersion")}
- >
- <ChevronLeft size={14} />
- </button>
- <span className="tabular-nums">
- {index + 1}/{versions.length}
- </span>
- <button
- onClick={() => go(versions[index + 1])}
- disabled={index >= versions.length - 1 || busy}
- className="rounded p-0.5 hover:bg-raised hover:text-ink disabled:opacity-30 disabled:hover:bg-transparent"
- title={t("chat.nextVersion")}
- >
- <ChevronRight size={14} />
- </button>
- </div>
- );
-}
-
const Bubble = memo(function Bubble({
message: row,
emerging = false,
diff --git a/src/components/VersionSwitch.tsx b/src/components/VersionSwitch.tsx
new file mode 100644
index 0000000000..304bb3c101
--- /dev/null
+++ b/src/components/VersionSwitch.tsx
@@ -0,0 +1,34 @@
+import { use } from "react";
+import { ChevronLeft, ChevronRight } from "lucide-react";
+import { ChatBusyContext } from "@/components/MessageActions";
+import { t } from "@/lib/i18n";
+import type { Message } from "@/state/store";
+
+/** The arrows between versions of a message; it alone reads whether the turn runs, so a bubble does not redraw when that changes. */
+export function VersionSwitch({ versions, index, onSwitch }: { versions: readonly Message[]; index: number; onSwitch: (version: Message) => void }) {
+ const busy = use(ChatBusyContext);
+ const go = (version: Message | undefined) => { if (version && !busy) onSwitch(version); };
+ return (
+ <div className="mt-1 flex items-center gap-0.5 pr-1 text-[12px] text-ink-secondary">
+ <button
+ onClick={() => go(versions[index - 1])}
+ disabled={index <= 0 || busy}
+ className="rounded p-0.5 hover:bg-raised hover:text-ink disabled:opacity-30 disabled:hover:bg-transparent"
+ title={t("chat.previousVersion")}
+ >
+ <ChevronLeft size={14} />
+ </button>
+ <span className="tabular-nums">
+ {index + 1}/{versions.length}
+ </span>
+ <button
+ onClick={() => go(versions[index + 1])}
+ disabled={index >= versions.length - 1 || busy}
+ className="rounded p-0.5 hover:bg-raised hover:text-ink disabled:opacity-30 disabled:hover:bg-transparent"
+ title={t("chat.nextVersion")}
+ >
+ <ChevronRight size={14} />
+ </button>
+ </div>
+ );
+}