Skip to content

Commit

Permalink
Page title use the conversation title
Browse files Browse the repository at this point in the history
  • Loading branch information
spolu committed Oct 12, 2023
1 parent 9bcde02 commit ce6e4fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
24 changes: 7 additions & 17 deletions front/components/assistant/conversation/ConversationTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import React, { MouseEvent, useRef, useState } from "react";
import { useSWRConfig } from "swr";

import { ConversationParticipants } from "@app/components/assistant/conversation/ConversationParticipants";
import { useConversation } from "@app/lib/swr";
import { classNames } from "@app/lib/utils";
import { ConversationType } from "@app/types/assistant/conversation";
import { WorkspaceType } from "@app/types/user";

export function ConversationTitle({
owner,
conversationId,
conversation,
shareLink,
onDelete,
}: {
owner: WorkspaceType;
conversationId: string;
conversation: ConversationType;
shareLink: string;
onDelete?: () => void;
}) {
Expand All @@ -46,16 +46,10 @@ export function ConversationTitle({
}, 1000);
};

const { conversation, isConversationError, isConversationLoading } =
useConversation({
conversationId,
workspaceId: owner.sId,
});

const onTitleChange = async (title: string) => {
try {
const res = await fetch(
`/api/w/${owner.sId}/assistant/conversations/${conversationId}`,
`/api/w/${owner.sId}/assistant/conversations/${conversation.sId}`,
{
method: "PATCH",
headers: {
Expand All @@ -68,7 +62,7 @@ export function ConversationTitle({
}
);
await mutate(
`/api/w/${owner.sId}/assistant/conversations/${conversationId}`
`/api/w/${owner.sId}/assistant/conversations/${conversation.sId}`
);
void mutate(`/api/w/${owner.sId}/assistant/conversations`);
if (!res.ok) {
Expand All @@ -81,16 +75,12 @@ export function ConversationTitle({
}
};

if (isConversationLoading || isConversationError || !conversation) {
return null;
}

return (
<div className="grid h-full min-w-0 max-w-full grid-cols-[1fr,auto] items-center gap-4">
<div className="flex min-w-0 flex-row items-center gap-4">
{!isEditingTitle ? (
<div className="min-w-0 overflow-hidden truncate">
<span className="font-bold">{conversation?.title || ""}</span>
<span className="font-bold">{conversation.title || ""}</span>
</div>
) : (
<div className="w-[84%]">
Expand Down Expand Up @@ -158,7 +148,7 @@ export function ConversationTitle({
<IconButton
icon={PencilSquareIcon}
onClick={() => {
setEditedTitle(conversation?.title || "");
setEditedTitle(conversation.title || "");
setIsEditingTitle(true);
}}
size="sm"
Expand Down
4 changes: 3 additions & 1 deletion front/components/sparkle/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default function AppLayout({
hideSidebar = false,
topNavigationCurrent,
subNavigation,
pageTitle,
gaTrackingId,
navChildren,
titleChildren,
Expand All @@ -174,6 +175,7 @@ export default function AppLayout({
hideSidebar?: boolean;
topNavigationCurrent: TopNavigationId;
subNavigation?: SidebarNavigation[] | null;
pageTitle?: string;
gaTrackingId: string;
navChildren?: React.ReactNode;
titleChildren?: React.ReactNode;
Expand All @@ -184,7 +186,7 @@ export default function AppLayout({
return (
<>
<Head>
<title>{`Dust - ${owner.name}`}</title>
<title>{pageTitle ? pageTitle : `Dust - ${owner.name}`}</title>
<link rel="shortcut icon" href="/static/favicon.png" />

<meta name="apple-mobile-web-app-title" content="Dust" />
Expand Down
45 changes: 29 additions & 16 deletions front/pages/w/[wId]/assistant/[cId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FixedAssistantInputBar } from "@app/components/assistant/conversation/I
import { AssistantSidebarMenu } from "@app/components/assistant/conversation/SidebarMenu";
import AppLayout from "@app/components/sparkle/AppLayout";
import { Authenticator, getSession, getUserFromSession } from "@app/lib/auth";
import { useConversation } from "@app/lib/swr";
import { AgentMention, MentionType } from "@app/types/assistant/conversation";
import { UserType, WorkspaceType } from "@app/types/user";

Expand Down Expand Up @@ -60,19 +61,24 @@ export default function AssistantConversation({
const [stickyMentions, setStickyMentions] = useState<AgentMention[]>([]);

useEffect(() => {
function handleNewConvoShortcut(event: KeyboardEvent) {
// Check for Command on Mac or Ctrl on others
const isModifier = event.metaKey || event.ctrlKey;
if (isModifier && event.key === "/") {
void router.push(`/w/${owner.sId}/assistant/new`);
}
}

window.addEventListener("keydown", handleNewConvoShortcut);
return () => {
window.removeEventListener("keydown", handleNewConvoShortcut);
};
}, []);
}, [owner.sId, router]);

function handleNewConvoShortcut(event: KeyboardEvent) {
// Check for Command on Mac or Ctrl on others
const isModifier = event.metaKey || event.ctrlKey;
if (isModifier && event.key === "/") {
void router.push(`/w/${owner.sId}/assistant/new`);
}
}
const { conversation } = useConversation({
conversationId,
workspaceId: owner.sId,
});

const handleSubmit = async (input: string, mentions: MentionType[]) => {
// Create a new user message.
Expand Down Expand Up @@ -124,17 +130,24 @@ export default function AssistantConversation({
user={user}
owner={owner}
isWideMode={true}
pageTitle={
conversation?.title
? `Dust - ${conversation?.title}`
: `Dust - New Conversation`
}
gaTrackingId={gaTrackingId}
topNavigationCurrent="assistant"
titleChildren={
<ConversationTitle
owner={owner}
conversationId={conversationId}
shareLink={`${baseUrl}/w/${owner.sId}/assistant/${conversationId}`}
onDelete={() => {
void handdleDeleteConversation();
}}
/>
conversation && (
<ConversationTitle
owner={owner}
conversation={conversation}
shareLink={`${baseUrl}/w/${owner.sId}/assistant/${conversationId}`}
onDelete={() => {
void handdleDeleteConversation();
}}
/>
)
}
navChildren={
<AssistantSidebarMenu owner={owner} triggerInputAnimation={null} />
Expand Down
3 changes: 2 additions & 1 deletion front/pages/w/[wId]/assistant/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ export default function AssistantNew({
user={user}
owner={owner}
isWideMode={conversation ? true : false}
pageTitle={"Dust - New Conversation"}
gaTrackingId={gaTrackingId}
topNavigationCurrent="assistant"
titleChildren={
conversation && (
<ConversationTitle
owner={owner}
conversationId={conversation.sId}
conversation={conversation}
shareLink={`${baseUrl}/w/${owner.sId}/assistant/${conversation.sId}`}
/>
)
Expand Down

0 comments on commit ce6e4fd

Please sign in to comment.