mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Improve sidebar experience for not logged in state
This commit is contained in:
@@ -883,13 +883,9 @@ const fetchChatHistory = async (url: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useChatSessionsFetchRequest = (url: string) => {
|
export const useChatSessionsFetchRequest = (url: string) => {
|
||||||
const { data, error } = useSWR<ChatHistory[]>(url, fetchChatHistory);
|
const { data, isLoading, error } = useSWR<ChatHistory[]>(url, fetchChatHistory);
|
||||||
|
|
||||||
return {
|
return { data, isLoading, error };
|
||||||
data,
|
|
||||||
isLoading: !error && !data,
|
|
||||||
isError: error,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
interface SidePanelProps {
|
interface SidePanelProps {
|
||||||
@@ -965,10 +961,12 @@ export default function AllConversations(props: SidePanelProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupLabel className="!p-0 m-0 px-0">Conversations</SidebarGroupLabel>
|
|
||||||
<div className={`flex justify-between flex-col`}>
|
<div className={`flex justify-between flex-col`}>
|
||||||
{authenticatedData && (
|
{authenticatedData && (
|
||||||
<>
|
<>
|
||||||
|
<SidebarGroupLabel className="!p-0 m-0 px-0">
|
||||||
|
Conversations
|
||||||
|
</SidebarGroupLabel>
|
||||||
<div
|
<div
|
||||||
className={`${props.sideBarOpen ? "border-l-2 border-light-blue-500 border-opacity-25 " : ""}`}
|
className={`${props.sideBarOpen ? "border-l-2 border-light-blue-500 border-opacity-25 " : ""}`}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ import { Gear } from "@phosphor-icons/react/dist/ssr";
|
|||||||
import { Plus } from "@phosphor-icons/react";
|
import { Plus } from "@phosphor-icons/react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import AllConversations from "../allConversations/allConversations";
|
import AllConversations from "../allConversations/allConversations";
|
||||||
import NavMenu from "../navMenu/navMenu";
|
import FooterMenu from "../navMenu/navMenu";
|
||||||
import { useSidebar } from "@/components/ui/sidebar";
|
import { useSidebar } from "@/components/ui/sidebar";
|
||||||
import { useIsMobileWidth } from "@/app/common/utils";
|
import { useIsMobileWidth } from "@/app/common/utils";
|
||||||
|
import { UserPlusIcon } from "lucide-react";
|
||||||
|
import { useAuthenticatedData } from "@/app/common/auth";
|
||||||
|
import LoginPrompt from "../loginPrompt/loginPrompt";
|
||||||
|
|
||||||
// Menu items.
|
// Menu items.
|
||||||
const items = [
|
const items = [
|
||||||
@@ -63,10 +66,19 @@ interface AppSidebarProps {
|
|||||||
|
|
||||||
export function AppSidebar(props: AppSidebarProps) {
|
export function AppSidebar(props: AppSidebarProps) {
|
||||||
const isMobileWidth = useIsMobileWidth();
|
const isMobileWidth = useIsMobileWidth();
|
||||||
|
const { data, isLoading, error } = useAuthenticatedData();
|
||||||
|
|
||||||
const { state, open, setOpen, openMobile, setOpenMobile, isMobile, toggleSidebar } =
|
const { state, open, setOpen, openMobile, setOpenMobile, isMobile, toggleSidebar } =
|
||||||
useSidebar();
|
useSidebar();
|
||||||
|
|
||||||
|
const [showLoginPrompt, setShowLoginPrompt] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading && !data) {
|
||||||
|
setShowLoginPrompt(true);
|
||||||
|
}
|
||||||
|
}, [isLoading, data]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar collapsible={"icon"} variant="sidebar" className="md:py-2">
|
<Sidebar collapsible={"icon"} variant="sidebar" className="md:py-2">
|
||||||
<SidebarHeader>
|
<SidebarHeader>
|
||||||
@@ -89,9 +101,29 @@ export function AppSidebar(props: AppSidebarProps) {
|
|||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
<SidebarContent>
|
<SidebarContent>
|
||||||
|
{showLoginPrompt && (
|
||||||
|
<LoginPrompt
|
||||||
|
onOpenChange={(isOpen) => setShowLoginPrompt(isOpen)}
|
||||||
|
isMobileWidth={isMobileWidth}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu className="p-0 m-0">
|
<SidebarMenu className="p-0 m-0">
|
||||||
|
{!isLoading && !data && (
|
||||||
|
<SidebarMenuItem className="p-0 m-0 list-none">
|
||||||
|
<SidebarMenuButton
|
||||||
|
asChild
|
||||||
|
variant={"default"}
|
||||||
|
onClick={() => setShowLoginPrompt(true)}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<UserPlusIcon />
|
||||||
|
<span>Sign up to get started</span>
|
||||||
|
</div>
|
||||||
|
</SidebarMenuButton>
|
||||||
|
</SidebarMenuItem>
|
||||||
|
)}
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<SidebarMenuItem key={item.title} className="p-0 list-none m-0">
|
<SidebarMenuItem key={item.title} className="p-0 list-none m-0">
|
||||||
<SidebarMenuButton asChild>
|
<SidebarMenuButton asChild>
|
||||||
@@ -116,7 +148,7 @@ export function AppSidebar(props: AppSidebarProps) {
|
|||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
<SidebarFooter>
|
<SidebarFooter>
|
||||||
<NavMenu sideBarIsOpen={open} />
|
<FooterMenu sideBarIsOpen={open} />
|
||||||
</SidebarFooter>
|
</SidebarFooter>
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ interface NavMenuProps {
|
|||||||
sideBarIsOpen: boolean;
|
sideBarIsOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function NavMenu({ sideBarIsOpen }: NavMenuProps) {
|
export default function FooterMenu({ sideBarIsOpen }: NavMenuProps) {
|
||||||
const {
|
const {
|
||||||
data: userData,
|
data: userData,
|
||||||
error: authenticationError,
|
error: authenticationError,
|
||||||
|
|||||||
Reference in New Issue
Block a user