Prompt to login when authenticated, click on suggestion card

- Improve styling for the side panel when not logged in
This commit is contained in:
sabaimran 2024-08-02 20:12:18 +05:30 committed by Debanjum Singh Solanky
parent 9c5ff1699a
commit f188396395
2 changed files with 20 additions and 6 deletions

View file

@ -742,10 +742,8 @@ export default function SidePanel(props: SidePanelProps) {
{ {
!authenticatedData && enabled && !authenticatedData && enabled &&
<div className={`${styles.panelWrapper}`}> <div className={`${styles.panelWrapper}`}>
<Link href="/"> <Link href="/" className="flex flex-col content-start items-start no-underline">
<Button variant="ghost"><House className="h-4 w-4 mr-1" />Home</Button> <Button variant="ghost"><House className="h-4 w-4 mr-1" />Home</Button>
</Link>
<Link href="/">
<Button variant="ghost"><StackPlus className="h-4 w-4 mr-1" />New Conversation</Button> <Button variant="ghost"><StackPlus className="h-4 w-4 mr-1" />New Conversation</Button>
</Link> </Link>
<Link href={`/login?next=${encodeURIComponent(window.location.pathname)}`}> {/* Redirect to login page */} <Link href={`/login?next=${encodeURIComponent(window.location.pathname)}`}> {/* Redirect to login page */}

View file

@ -14,6 +14,7 @@ import SidePanel from '@/app/components/sidePanel/chatHistorySidePanel';
import Loading from '@/app/components/loading/loading'; import Loading from '@/app/components/loading/loading';
import ChatInputArea, { ChatOptions } from '@/app/components/chatInputArea/chatInputArea'; import ChatInputArea, { ChatOptions } from '@/app/components/chatInputArea/chatInputArea';
import { Suggestion, suggestionsData } from '@/app/components/suggestions/suggestionsData'; import { Suggestion, suggestionsData } from '@/app/components/suggestions/suggestionsData';
import LoginPrompt from '@/app/components/loginPrompt/loginPrompt';
import { useAuthenticatedData, UserConfig, useUserConfig } from '@/app/common/auth'; import { useAuthenticatedData, UserConfig, useUserConfig } from '@/app/common/auth';
import { convertColorToBorderClass } from '@/app/common/colorUtils'; import { convertColorToBorderClass } from '@/app/common/colorUtils';
@ -53,6 +54,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
const [selectedAgent, setSelectedAgent] = useState<string | null>("khoj"); const [selectedAgent, setSelectedAgent] = useState<string | null>("khoj");
const [agentIcons, setAgentIcons] = useState<JSX.Element[]>([]); const [agentIcons, setAgentIcons] = useState<JSX.Element[]>([]);
const [agents, setAgents] = useState<AgentData[]>([]); const [agents, setAgents] = useState<AgentData[]>([]);
const [showLoginPrompt, setShowLoginPrompt] = useState(false);
const agentsFetcher = () => window.fetch('/api/agents').then(res => res.json()).catch(err => console.log(err)); const agentsFetcher = () => window.fetch('/api/agents').then(res => res.json()).catch(err => console.log(err));
const { data: agentsData, error } = useSWR<AgentData[]>('agents', agentsFetcher, { revalidateOnFocus: false }); const { data: agentsData, error } = useSWR<AgentData[]>('agents', agentsFetcher, { revalidateOnFocus: false });
@ -163,6 +165,13 @@ function ChatBodyData(props: ChatBodyDataProps) {
return ( return (
<div className={`${styles.homeGreetings}`}> <div className={`${styles.homeGreetings}`}>
{
showLoginPrompt && (
<LoginPrompt
onOpenChange={setShowLoginPrompt}
loginRedirectMessage={"Login to start extending your second brain"} />
)
}
<div className={`w-full text-center justify-end content-end`}> <div className={`w-full text-center justify-end content-end`}>
<div className="items-center"> <div className="items-center">
<h1 className="text-center w-fit pb-6 px-4 mx-auto">{greeting}</h1> <h1 className="text-center w-fit pb-6 px-4 mx-auto">{greeting}</h1>
@ -208,7 +217,15 @@ function ChatBodyData(props: ChatBodyDataProps) {
{shuffledOptions.map((suggestion, index) => ( {shuffledOptions.map((suggestion, index) => (
<div <div
key={`${suggestion.type} ${suggestion.description}`} key={`${suggestion.type} ${suggestion.description}`}
onClick={() => fillArea(suggestion.link, suggestion.type, suggestion.description)}> onClick={(event) => {
if (props.isLoggedIn) {
fillArea(suggestion.link, suggestion.type, suggestion.description);
} else {
event.preventDefault();
event.stopPropagation();
setShowLoginPrompt(true);
}
}}>
<SuggestionCard <SuggestionCard
key={suggestion.type + Math.random()} key={suggestion.type + Math.random()}
title={suggestion.type} title={suggestion.type}
@ -265,7 +282,6 @@ function ChatBodyData(props: ChatBodyDataProps) {
export default function Home() { export default function Home() {
const [chatOptionsData, setChatOptionsData] = useState<ChatOptions | null>(null); const [chatOptionsData, setChatOptionsData] = useState<ChatOptions | null>(null);
const [isLoading, setLoading] = useState(true); const [isLoading, setLoading] = useState(true);
const [title, setTitle] = useState('');
const [conversationId, setConversationID] = useState<string | null>(null); const [conversationId, setConversationID] = useState<string | null>(null);
const [uploadedFiles, setUploadedFiles] = useState<string[]>([]); const [uploadedFiles, setUploadedFiles] = useState<string[]>([]);
const [isMobileWidth, setIsMobileWidth] = useState(false); const [isMobileWidth, setIsMobileWidth] = useState(false);
@ -312,7 +328,7 @@ export default function Home() {
return ( return (
<div className={`${styles.main} ${styles.chatLayout}`}> <div className={`${styles.main} ${styles.chatLayout}`}>
<title> <title>
{title} Khoj AI - Your Second Brain
</title> </title>
<div className={`${styles.sidePanel}`}> <div className={`${styles.sidePanel}`}>
<SidePanel <SidePanel