Skip to content

Commit e3558a8

Browse files
add chats page
1 parent 1e21db8 commit e3558a8

13 files changed

Lines changed: 636 additions & 193 deletions

File tree

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { authenticatedPage } from "@/middleware/authenticatedPage";
12
import { SettingsSidebar } from "../../../components/settingsSidebar";
23

3-
export default async function Page() {
4+
export default authenticatedPage(async () => {
45
return <SettingsSidebar />;
5-
}
6+
});
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { authenticatedPage } from "@/middleware/authenticatedPage";
12
import { SettingsSidebar } from "../../components/settingsSidebar";
23

3-
export default async function Page() {
4+
export default authenticatedPage(async () => {
45
return <SettingsSidebar />;
5-
}
6+
});

packages/web/src/app/(app)/@sidebar/components/defaultSidebar/chatHistory.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { deleteChat, duplicateChat, updateChatName } from "@/features/chat/actions";
1818
import { captureEvent } from "@/hooks/useCaptureEvent";
1919
import { isServiceError } from "@/lib/utils";
20-
import { EllipsisIcon } from "lucide-react";
20+
import { EllipsisIcon, MessagesSquareIcon } from "lucide-react";
2121
import Link from "next/link";
2222
import { usePathname, useRouter } from "next/navigation";
2323
import { useCallback, useState } from "react";
@@ -30,9 +30,10 @@ export interface ChatHistoryItem {
3030

3131
interface ChatHistoryProps {
3232
chatHistory: ChatHistoryItem[];
33+
hasMore?: boolean;
3334
}
3435

35-
export function ChatHistory({ chatHistory }: ChatHistoryProps) {
36+
export function ChatHistory({ chatHistory, hasMore }: ChatHistoryProps) {
3637
const pathname = usePathname();
3738
const router = useRouter();
3839
const { toast } = useToast();
@@ -122,6 +123,16 @@ export function ChatHistory({ chatHistory }: ChatHistoryProps) {
122123
</ChatActionsDropdown>
123124
</SidebarMenuItem>
124125
))}
126+
{hasMore && (
127+
<SidebarMenuItem>
128+
<SidebarMenuButton asChild>
129+
<Link href="/chats">
130+
<MessagesSquareIcon className="h-4 w-4" />
131+
<span>All chats</span>
132+
</Link>
133+
</SidebarMenuButton>
134+
</SidebarMenuItem>
135+
)}
125136
</SidebarMenu>
126137
</SidebarGroupContent>
127138
</SidebarGroup>

packages/web/src/app/(app)/@sidebar/components/defaultSidebar/index.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { auth } from "@/auth";
2-
import { getUserChatHistory } from "@/features/chat/actions";
32
import { getConnectionStats, getOrgAccountRequests } from "@/actions";
43
import { isServiceError } from "@/lib/utils";
54
import { ServiceErrorException } from "@/lib/serviceError";
@@ -9,6 +8,10 @@ import { OrgRole } from "@prisma/client";
98
import { SidebarBase } from "@/app/(app)/@sidebar/components/sidebarBase";
109
import { Nav } from "./nav";
1110
import { ChatHistory } from "./chatHistory";
11+
import { withAuth } from "@/middleware/withAuth";
12+
import { sew } from "@/middleware/sew";
13+
14+
const SIDEBAR_CHAT_LIMIT = 30;
1215

1316
export async function DefaultSidebar() {
1417
const session = await auth();
@@ -40,9 +43,34 @@ export async function DefaultSidebar() {
4043
<SidebarBase
4144
session={session}
4245
collapsible="icon"
43-
headerContent={<Nav isSettingsNotificationVisible={isSettingsNotificationVisible} />}
46+
headerContent={<Nav isSettingsNotificationVisible={isSettingsNotificationVisible} isSignedIn={!!session} />}
4447
>
45-
<ChatHistory chatHistory={chatHistory} />
48+
<ChatHistory
49+
chatHistory={chatHistory.slice(0, SIDEBAR_CHAT_LIMIT)}
50+
hasMore={chatHistory.length > SIDEBAR_CHAT_LIMIT}
51+
/>
4652
</SidebarBase>
4753
);
4854
}
55+
56+
const getUserChatHistory = async () => sew(() =>
57+
withAuth(async ({ org, user, prisma }) => {
58+
const chats = await prisma.chat.findMany({
59+
where: {
60+
orgId: org.id,
61+
createdById: user.id,
62+
},
63+
orderBy: {
64+
updatedAt: 'desc',
65+
},
66+
take: SIDEBAR_CHAT_LIMIT + 1,
67+
});
68+
69+
return chats.map((chat) => ({
70+
id: chat.id,
71+
createdAt: chat.createdAt,
72+
name: chat.name,
73+
visibility: chat.visibility,
74+
}))
75+
})
76+
);

packages/web/src/app/(app)/@sidebar/components/defaultSidebar/nav.tsx

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,59 @@ import {
55
SidebarMenuButton,
66
SidebarMenuItem,
77
} from "@/components/ui/sidebar";
8-
import { BookMarkedIcon, MessageCircleIcon, MessagesSquareIcon, SearchIcon, SettingsIcon } from "lucide-react";
8+
import { BookMarkedIcon, type LucideIcon, MessageCircleIcon, MessagesSquareIcon, SearchIcon, SettingsIcon } from "lucide-react";
99
import { usePathname } from "next/navigation";
1010
import { NotificationDot } from "../../../components/notificationDot";
1111

12-
const baseItems = [
13-
{ title: "Code Search", href: "/search", icon: SearchIcon, key: "search" },
14-
{ title: "Ask", href: "/chat", icon: MessageCircleIcon, key: "chat" },
15-
{ title: "Chats", href: "/chats", icon: MessagesSquareIcon, key: "chats" },
16-
{ title: "Repositories", href: "/repos", icon: BookMarkedIcon, key: "repos" },
17-
{ title: "Settings", href: "/settings", icon: SettingsIcon, key: "settings" },
12+
interface NavItem {
13+
title: string;
14+
href: string;
15+
icon: LucideIcon;
16+
key: string;
17+
requiresAuth?: boolean;
18+
}
19+
20+
const baseItems: NavItem[] = [
21+
{
22+
title: "Code Search",
23+
href: "/search",
24+
icon: SearchIcon,
25+
key: "search",
26+
},
27+
{
28+
title: "Ask",
29+
href: "/chat",
30+
icon: MessageCircleIcon,
31+
key: "chat"
32+
},
33+
{
34+
title: "Chats",
35+
href: "/chats",
36+
icon: MessagesSquareIcon,
37+
key: "chats",
38+
requiresAuth: true,
39+
},
40+
{
41+
title: "Repositories",
42+
href: "/repos",
43+
icon: BookMarkedIcon,
44+
key: "repos"
45+
},
46+
{
47+
title: "Settings",
48+
href: "/settings",
49+
icon: SettingsIcon,
50+
key: "settings",
51+
requiresAuth: true
52+
},
1853
];
1954

2055
interface NavProps {
2156
isSettingsNotificationVisible?: boolean;
57+
isSignedIn?: boolean;
2258
}
2359

24-
export function Nav({ isSettingsNotificationVisible }: NavProps) {
60+
export function Nav({ isSettingsNotificationVisible, isSignedIn }: NavProps) {
2561
const pathname = usePathname();
2662

2763
const isActive = (href: string) => {
@@ -36,7 +72,7 @@ export function Nav({ isSettingsNotificationVisible }: NavProps) {
3672

3773
return (
3874
<SidebarMenu>
39-
{baseItems.map((item) => {
75+
{baseItems.filter((item) => !item.requiresAuth || isSignedIn).map((item) => {
4076
const showNotification =
4177
(item.key === "settings" && isSettingsNotificationVisible);
4278
return (

0 commit comments

Comments
 (0)