Skip to content
Closed
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
Expand Up @@ -19,7 +19,10 @@ import {
} from "@/hooks/useWorkspaces";
import { readBuilderSession, clearBuilderSession } from "@/lib/chatbox-session";
import { ChatboxIndexPage, type ChatboxOpenOptions } from "./ChatboxIndexPage";
import { ChatboxBuilderView } from "./ChatboxBuilderView";
import {
ChatboxBuilderView,
type SavedDraftNavigationOptions,
} from "./ChatboxBuilderView";
import { ChatboxLauncher } from "./ChatboxLauncher";
import { getDefaultHostedModelId } from "./drafts";
import type { ChatboxDraftConfig, ChatboxStarterDefinition } from "./types";
Expand Down Expand Up @@ -65,6 +68,8 @@ export default function ChatboxBuilderExperience({
const [restoredViewMode, setRestoredViewMode] = useState<
"setup" | "preview" | "usage" | "insights" | undefined
>();
const [restoredFocusedSetupSection, setRestoredFocusedSetupSection] =
useState<SavedDraftNavigationOptions["initialFocusedSetupSection"]>();
const [starterLauncherOpen, setStarterLauncherOpen] = useState(false);
const [deletingChatboxId, setDeletingChatboxId] = useState<string | null>(
null,
Expand Down Expand Up @@ -94,6 +99,7 @@ export default function ChatboxBuilderExperience({
startTransition(() => {
setSelectedChatboxId(session.chatboxId);
setDraft((session.draft as ChatboxDraftConfig | null) ?? null);
setRestoredFocusedSetupSection(undefined);
const vm = session.viewMode;
if (vm === "builder") {
setRestoredViewMode("setup");
Expand All @@ -116,6 +122,7 @@ export default function ChatboxBuilderExperience({
setSelectedChatboxId(null);
setDraft(starter.createDraft(getDefaultHostedModelId()));
setRestoredViewMode(undefined);
setRestoredFocusedSetupSection(undefined);
setStarterLauncherOpen(false);
});
},
Expand All @@ -133,13 +140,19 @@ export default function ChatboxBuilderExperience({
[applyStarterDraft],
);

const handleSavedDraft = useCallback((chatbox: ChatboxSettings) => {
startTransition(() => {
setDraft(null);
setSelectedChatboxId(chatbox.chatboxId);
setRestoredViewMode(undefined);
});
}, []);
const handleSavedDraft = useCallback(
(chatbox: ChatboxSettings, options?: SavedDraftNavigationOptions) => {
startTransition(() => {
setDraft(null);
setSelectedChatboxId(chatbox.chatboxId);
setRestoredViewMode(options?.initialViewMode);
setRestoredFocusedSetupSection(
options?.initialFocusedSetupSection,
);
});
},
[],
);

const handleDeleteChatbox = useCallback(
async (chatbox: ChatboxListItem) => {
Expand Down Expand Up @@ -177,6 +190,7 @@ export default function ChatboxBuilderExperience({
startTransition(() => {
setSelectedChatboxId(newId);
setRestoredViewMode(undefined);
setRestoredFocusedSetupSection(undefined);
});
}
} catch (error) {
Expand Down Expand Up @@ -220,13 +234,15 @@ export default function ChatboxBuilderExperience({
chatboxId={selectedChatboxId}
draft={draft}
initialViewMode={restoredViewMode}
initialFocusedSetupSection={restoredFocusedSetupSection}
onSavedDraft={handleSavedDraft}
onBack={() => {
clearBuilderSession();
startTransition(() => {
setSelectedChatboxId(null);
setDraft(null);
setRestoredViewMode(undefined);
setRestoredFocusedSetupSection(undefined);
});
}}
/>
Expand All @@ -238,6 +254,7 @@ export default function ChatboxBuilderExperience({
startTransition(() => {
setSelectedChatboxId(chatboxId);
setRestoredViewMode(options?.initialViewMode);
setRestoredFocusedSetupSection(undefined);
});
}}
onDuplicateChatbox={handleDuplicateChatbox}
Expand Down
Loading
Loading