Skip to content

Commit 94b1eea

Browse files
committed
peerlist hacks
1 parent 9b9b358 commit 94b1eea

31 files changed

+703
-533
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [SkidGod4444]

app/(routes)/chat/[slug]/page.tsx

Lines changed: 48 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,59 @@
11
"use client";
22

3-
import { useState } from 'react';
4-
import { ChevronLeft, ChevronRight, PaperclipIcon, ArrowUpIcon } from 'lucide-react';
5-
import { ScrollArea } from "@/components/ui/scroll-area";
6-
import { Button } from "@/components/ui/button";
7-
import { CustomTextArea } from "@/components/custom/text.area";
3+
import { useEffect, useState } from "react";
84
import { SideBar } from "@/components/custom/sidebar/sidebar";
95
import useLocalStorage from "@/lib/use.local";
10-
import { LibSelector } from '@/components/custom/lib.selector';
6+
import { Message } from "ai/react";
7+
import { ChatComp } from "@/components/custom/chat/comp";
8+
import LoadingScreen from "@/components/custom/loading.screen";
119

12-
export default function Component() {
13-
const [isCodeCollapsed, setIsCodeCollapsed] = useState(false);
14-
const [isSidebarExpanded, setIsSidebarExpanded] = useLocalStorage("acter-isCollapsed", false);
15-
16-
const toggleCodePanel = () => {
17-
setIsCodeCollapsed(!isCodeCollapsed);
10+
interface PageProps {
11+
params: {
12+
slug: string;
1813
};
14+
}
1915

20-
const messages = [
21-
{ id: 1, text: "Hello! How can I help you today?" },
22-
{ id: 2, text: "Can you explain how to use React hooks?" },
23-
{ id: 3, text: "React hooks are functions that let you use state and other React features in functional components..." },
24-
];
16+
export default function ChatPage({ params }: PageProps) {
17+
const [loading, setLoading] = useState(true);
18+
const [isSidebarExpanded, setIsSidebarExpanded] = useLocalStorage(
19+
"acter-isCollapsed",
20+
false,
21+
);
22+
const [history, setHistory] = useState<Message[]>([]);
2523

26-
const codeExample = `
27-
import React, { useState } from 'react';
24+
const chatID = params.slug.replace(/^\//, "");
2825

29-
function Counter() {
30-
const [count, setCount] = useState(0);
26+
useEffect(() => {
27+
async function handleSlug() {
28+
setLoading(true);
29+
try {
30+
const response = await fetch("/api/ai/history", {
31+
method: "POST",
32+
headers: {
33+
"Content-Type": "application/json",
34+
},
35+
body: JSON.stringify({ chatID }),
36+
});
3137

32-
return (
33-
<div>
34-
<p>You clicked {count} times</p>
35-
<button onClick={() => setCount(count + 1)}>
36-
Click me
37-
</button>
38-
</div>
39-
);
40-
}
41-
`.trim();
38+
if (response.ok) {
39+
const chatHistory = await response.json();
40+
setHistory(chatHistory);
41+
} else {
42+
console.error("Failed to fetch chat history");
43+
}
44+
} catch (error) {
45+
console.error("Error fetching chat history:", error);
46+
} finally {
47+
setLoading(false);
48+
}
49+
}
50+
51+
handleSlug();
52+
}, [params.slug, chatID]);
53+
54+
if (loading) {
55+
return <LoadingScreen />;
56+
}
4257

4358
return (
4459
<div className="flex h-screen">
@@ -49,64 +64,9 @@ function Counter() {
4964
/>
5065

5166
{/* Left Panel */}
52-
<div className="flex-1 flex flex-col p-4 border-r">
53-
<nav className="flex items-center justify-between border-b pb-2 mb-4">
54-
<h2 className="text-2xl font-bold">Messages</h2>
55-
<Button
56-
variant="ghost"
57-
size="icon"
58-
onClick={toggleCodePanel}
59-
>
60-
{isCodeCollapsed ? <ChevronLeft className="h-6 w-6" /> : <ChevronRight className="h-6 w-6" />}
61-
</Button>
62-
</nav>
63-
<ScrollArea className="flex-1 mb-4 p-4 bg-gray-50 rounded-lg">
64-
{messages.map((message) => (
65-
<div key={message.id} className="mb-4 p-3 bg-white rounded-lg shadow-sm">
66-
{message.text}
67-
</div>
68-
))}
69-
</ScrollArea>
70-
67+
<div className="flex-1 flex flex-col p-4 border-r overflow-hidden">
7168
{/* Input Area */}
72-
<form
73-
// onSubmit={handleFormSubmit}
74-
className="flex flex-col gap-2 bg-background border dark:bg-black rounded-xl dark:border-white p-2 min-h-[60px]"
75-
>
76-
<CustomTextArea
77-
placeholder="Acter, make me a glowing button component..."
78-
className="flex-1 bg-transparent focus:outline-none shadow-none"
79-
/>
80-
<div className="flex items-center justify-between">
81-
<div className="flex items-center gap-2">
82-
<Button variant="outline" size="icon" disabled>
83-
<PaperclipIcon className="w-4 h-4" />
84-
</Button>
85-
<LibSelector />
86-
</div>
87-
<Button size="icon">
88-
<ArrowUpIcon className="w-4 h-4" />
89-
</Button>
90-
</div>
91-
</form>
92-
</div>
93-
94-
{/* Right Panel - Code Viewer */}
95-
<div
96-
className={`flex transition-all duration-300 ease-in-out ${
97-
isCodeCollapsed ? 'w-12' : 'w-1/2'
98-
}`}
99-
>
100-
{!isCodeCollapsed && (
101-
<div className="flex-1 p-4 border-l">
102-
<h2 className="text-2xl font-bold mb-4">Code</h2>
103-
<ScrollArea className="h-[calc(100vh-8rem)]">
104-
<pre className="p-4 bg-gray-100 rounded-lg overflow-x-auto">
105-
<code>{codeExample}</code>
106-
</pre>
107-
</ScrollArea>
108-
</div>
109-
)}
69+
<ChatComp chatId={chatID} history={history} />
11070
</div>
11171
</div>
11272
);

app/(routes)/chat/page.tsx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,73 @@
11
"use client";
22

33
import { Badge } from "@/components/ui/badge";
4-
import { MoveUpRight } from "lucide-react";
54
import useLocalStorage from "@/lib/use.local";
65
import { useUser } from "@/context/user.context";
7-
import { OfcLinks } from "@/db/defaults";
86
import { SideBar } from "@/components/custom/sidebar/sidebar";
9-
import { useEffect, useState } from "react";
7+
import { useEffect, useState, useRef } from "react";
108
import { ChatComp } from "@/components/custom/chat/comp";
9+
import LoadingScreen from "@/components/custom/loading.screen";
10+
import { useRouter } from "next/navigation";
1111

1212
export default function ChatPage() {
1313
const { user } = useUser();
14-
const [chatID, setChatID] = useState<string | number>("null");
14+
const router = useRouter();
15+
const [chatID, setChatID] = useState<string | null>(null);
1516
const [isMsg, setMsg] = useState(false);
17+
const chatInitialized = useRef(false);
1618

19+
const [isSidebarExpanded, setIsSidebarExpanded] = useLocalStorage(
20+
"acter-isCollapsed",
21+
false,
22+
);
23+
24+
// Generate chat ID once the user is available
1725
useEffect(() => {
18-
const fetchChatID = async () => {
26+
if (user && !chatInitialized.current) {
1927
const id = Math.floor(Math.random() * 900000) + 100000;
2028
setChatID(id.toString());
21-
};
22-
23-
if (user) {
24-
fetchChatID();
29+
chatInitialized.current = true;
2530
}
26-
}, [user, chatID]);
31+
}, [user]);
2732

33+
// Navigate to chat page when ready
2834
useEffect(() => {
2935
if (chatID && isMsg) {
30-
window.location.href = `/chat/${chatID}`;
36+
window.history.replaceState(null, "", `/chat/${chatID}`);
3137
}
32-
}, [chatID, isMsg]);
38+
}, [chatID, isMsg, router]);
3339

34-
const [isSidebarExpanded, setIsSidebarExpanded] = useLocalStorage(
35-
"acter-isCollapsed",
36-
false
37-
);
40+
if (!chatID) {
41+
return <LoadingScreen />;
42+
}
3843

3944
return (
40-
<div className="relative h-screen flex z-50 flex-col dark:bg-black dark:text-white bg-background text-black font-[family-name:var(--font-geist-regular)] overflow-hidden">
45+
<div className="relative h-full flex z-50 flex-col dark:bg-black dark:text-white bg-background text-black font-[family-name:var(--font-geist-regular)] overflow-hidden">
4146
{/* Background */}
4247
<div className="fixed inset-0 z-20 h-full w-full bg-[linear-gradient(to_right,#f0f0f0_1px,transparent_1px),linear-gradient(to_bottom,#f0f0f0_1px,transparent_1px)] bg-[size:3rem_3rem] dark:bg-[linear-gradient(to_right,#333_1px,transparent_1px),linear-gradient(to_bottom,#333_1px,transparent_1px)] dark:bg-[size:3rem_3rem]" />
4348

4449
{/* Main Layout */}
4550
<div className="flex h-full w-full z-30">
4651
{/* Sidebar */}
4752
<SideBar
48-
isSidebarExpanded={isSidebarExpanded}
49-
setIsSidebarExpanded={(expanded) => setIsSidebarExpanded(expanded)}
50-
/>
53+
isSidebarExpanded={isSidebarExpanded}
54+
setIsSidebarExpanded={(expanded) => setIsSidebarExpanded(expanded)}
55+
/>
5156

5257
{/* Main Content */}
5358
<div className="flex flex-col flex-1 z-40">
54-
{/* Header at the top */}
59+
{/* Header */}
5560
<header className="flex justify-end items-center p-4 bg-transparent border-none">
5661
<Badge>Public Beta</Badge>
5762
</header>
5863

5964
<main className="flex-1 flex flex-col items-center justify-center p-4">
60-
<h2 className="text-4xl mb-4 font-[family-name:var(--font-geist-bold)] tracking-tighter select-none">
61-
Need awesome components to ship?
62-
</h2>
63-
<p className="text-sm mb-4 select-none dark:text-white text-muted-foreground">
64-
Am the one who supports Acternity UI, Magic UI and more libraries. Ask questions, modify component.
65-
</p>
66-
6765
{/* Input area */}
68-
<div className="w-full max-w-3xl mb-10">
66+
<div className="w-full max-w-3xl">
6967
<ChatComp chatId={chatID} onHasMessagesChange={setMsg} />
7068
</div>
7169

72-
<div className="flex flex-wrap justify-center gap-4">
70+
{/* <div className="flex flex-wrap justify-center gap-4">
7371
<Badge variant={"secondary"} className="cursor-pointer rounded-xl border border-muted-foreground">
7472
Generate a SaaS pricing calculator
7573
<MoveUpRight className="size-3 ml-1" />
@@ -82,11 +80,11 @@ export default function ChatPage() {
8280
Write code to implement a min heap
8381
<MoveUpRight className="size-3 ml-1" />
8482
</Badge>
85-
</div>
83+
</div> */}
8684
</main>
8785

88-
{/* Footer at the bottom */}
89-
<footer className="p-8">
86+
{/* Footer */}
87+
{/* <footer className="p-8">
9088
<div className="flex justify-center items-center text-xs text-gray-500">
9189
<div className="flex items-center">
9290
<a href="/legal/ai-policy" className="hover:underline">
@@ -106,7 +104,7 @@ export default function ChatPage() {
106104
By Saidev Dhal
107105
</a>
108106
</div>
109-
</footer>
107+
</footer> */}
110108
</div>
111109
</div>
112110
</div>

app/(routes)/page.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
import { useState } from "react";
44
import { Button } from "@/components/ui/button";
5-
import {
6-
PaperclipIcon,
7-
ArrowUpIcon,
8-
MoveUpRight,
9-
} from "lucide-react";
5+
import { PaperclipIcon, ArrowUpIcon, MoveUpRight } from "lucide-react";
106
import { CustomTextArea } from "@/components/custom/text.area";
117
import { Badge } from "@/components/ui/badge";
128
import { OsBtn } from "@/components/custom/os.button";
@@ -18,14 +14,13 @@ import { LibSelector } from "@/components/custom/lib.selector";
1814
export default function HomePage() {
1915
const [isOpen, setIsOpen] = useState(false);
2016

21-
const handleFormSubmit = async(event: React.FormEvent<HTMLFormElement>) => {
17+
const handleFormSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
2218
event.preventDefault();
2319
setIsOpen(!isOpen);
24-
}
20+
};
2521

2622
return (
2723
<div className="relative h-screen z-50 flex flex-col dark:bg-black dark:text-white bg-background text-black font-[family-name:var(--font-geist-regular)] overflow-hidden">
28-
2924
{/* Background */}
3025
<div className="fixed inset-0 z-20 h-full w-full bg-[linear-gradient(to_right,#f0f0f0_1px,transparent_1px),linear-gradient(to_bottom,#f0f0f0_1px,transparent_1px)] bg-[size:3rem_3rem] dark:bg-[linear-gradient(to_right,#333_1px,transparent_1px),linear-gradient(to_bottom,#333_1px,transparent_1px)] dark:bg-[size:3rem_3rem]" />
3126

@@ -36,7 +31,7 @@ export default function HomePage() {
3631
{/* Header at the top */}
3732
<header className="flex justify-end items-center p-4 bg-transparent border-none">
3833
{/* <Badge>Public Beta</Badge> */}
39-
<AuthDialog open={isOpen} onOpenChange={setIsOpen}/>
34+
<AuthDialog open={isOpen} onOpenChange={setIsOpen} />
4035
</header>
4136

4237
<div className="mt-28 md:mt-10">
@@ -47,23 +42,27 @@ export default function HomePage() {
4742
Need awesome components to ship?
4843
</h2>
4944
<p className="text-sm mb-4 select-none dark:text-white text-muted-foreground">
50-
Am the one who supports Acternity UI, Magic UI and more libraries. Ask questions, modify component.
45+
Am the one who supports Acternity UI, Magic UI and more libraries.
46+
Ask questions, modify component.
5147
</p>
5248

5349
{/* Input area */}
5450
<div className="w-full max-w-3xl mb-10">
55-
<form onSubmit={handleFormSubmit} className="flex flex-col gap-2 bg-background dark:bg-black rounded-xl border dark:border-white p-2 min-h-[60px]">
51+
<form
52+
onSubmit={handleFormSubmit}
53+
className="flex flex-col gap-2 bg-background dark:bg-black rounded-xl border dark:border-white p-2 min-h-[60px]"
54+
>
5655
<CustomTextArea
5756
placeholder="Acter make me a glowing button component..."
5857
className="flex-1 bg-transparent focus:outline-none shadow-none"
5958
/>
6059
<div className="flex items-center justify-between gap-2">
61-
<div className='flex items-center gap-2 flex-row'>
62-
<Button variant="outline" size="icon" disabled>
63-
<PaperclipIcon className="w-4 h-4" />
64-
</Button>
65-
<LibSelector />
66-
</div>
60+
<div className="flex items-center gap-2 flex-row">
61+
<Button variant="outline" size="icon" disabled>
62+
<PaperclipIcon className="w-4 h-4" />
63+
</Button>
64+
<LibSelector />
65+
</div>
6766
<Button size="icon">
6867
<ArrowUpIcon className="w-4 h-4" />
6968
</Button>

app/api/ai/history/route.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ragChat } from "@/lib/rag";
2+
import { NextRequest, NextResponse } from "next/server";
3+
4+
export const POST = async (req: NextRequest) => {
5+
try {
6+
const { chatID } = await req.json();
7+
const chatHistory = await ragChat.history.getMessages({
8+
amount: 100,
9+
sessionId: chatID,
10+
});
11+
12+
return NextResponse.json(chatHistory);
13+
} catch (error) {
14+
console.error("Error fetching chat history:", error);
15+
return new NextResponse("Failed to fetch chat history", { status: 500 });
16+
}
17+
};

0 commit comments

Comments
 (0)