From bea0aa5445a775755693574380f387bbf4b82875 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Thu, 11 Jul 2024 20:11:21 +0530 Subject: [PATCH] Improve the logged out share experience --- .../chatInputArea/chatInputArea.tsx | 29 +++++++++++- .../app/components/loading/loading.module.css | 24 ---------- .../web/app/components/loading/loading.tsx | 7 +-- .../components/loginPrompt/loginPrompt.tsx | 42 +++++++++++++++++ .../sidePanel/chatHistorySidePanel.tsx | 46 ++++++++++--------- .../web/app/share/chat/[slug]/page.tsx | 5 +- 6 files changed, 102 insertions(+), 51 deletions(-) delete mode 100644 src/interface/web/app/components/loading/loading.module.css create mode 100644 src/interface/web/app/components/loginPrompt/loginPrompt.tsx diff --git a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx index c624a961..760301d9 100644 --- a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx +++ b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx @@ -39,11 +39,15 @@ import { AlertDialogAction, AlertDialogContent, AlertDialogDescription, + AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/components/ui/alert-dialog'; import { Popover, PopoverContent } from '@/components/ui/popover'; import { PopoverTrigger } from '@radix-ui/react-popover'; +import Link from 'next/link'; +import { AlertDialogCancel } from '@radix-ui/react-alert-dialog'; +import LoginPrompt from '../loginPrompt/loginPrompt'; export interface ChatOptions { [key: string]: string @@ -66,6 +70,8 @@ export default function ChatInputArea(props: ChatInputProps) { const [warning, setWarning] = useState(null); const [error, setError] = useState(null); const [uploading, setUploading] = useState(false); + const [loginRedirectMessage, setLoginRedirectMessage] = useState(null); + const [showLoginPrompt, setShowLoginPrompt] = useState(false); const [progressValue, setProgressValue] = useState(0); @@ -87,7 +93,15 @@ export default function ChatInputArea(props: ChatInputProps) { }, [uploading]); function onSendMessage() { - props.sendMessage(message); + if (!message.trim()) return; + + if (!props.isLoggedIn) { + setLoginRedirectMessage('Hey there, you need to be signed in to send messages to Khoj AI'); + setShowLoginPrompt(true); + return; + } + + props.sendMessage(message.trim()); setMessage(''); } @@ -103,6 +117,12 @@ export default function ChatInputArea(props: ChatInputProps) { function handleFileChange(event: React.ChangeEvent) { if (!event.target.files) return; + if (!props.isLoggedIn) { + setLoginRedirectMessage('Whoa! You need to login to upload files'); + setShowLoginPrompt(true); + return; + } + uploadDataForIndexing( event.target.files, setWarning, @@ -153,6 +173,13 @@ export default function ChatInputArea(props: ChatInputProps) { return ( <> + { + showLoginPrompt && loginRedirectMessage && ( + + ) + } { uploading && ( */ -.loader { - --c: conic-gradient(from -90deg, hsla(var(--secondary)) 90deg, #0000 0); - background: var(--c), var(--c); - background-size: 40% 40%; - animation: l19 1s infinite alternate; -} - -@keyframes l19 { - - 0%, - 10% { - background-position: 0 0, 0 calc(100%/3) - } - - 50% { - background-position: 0 0, calc(100%/3) calc(100%/3) - } - - 90%, - 100% { - background-position: 0 0, calc(100%/3) 0 - } -} diff --git a/src/interface/web/app/components/loading/loading.tsx b/src/interface/web/app/components/loading/loading.tsx index a45377a5..97f8ade3 100644 --- a/src/interface/web/app/components/loading/loading.tsx +++ b/src/interface/web/app/components/loading/loading.tsx @@ -1,10 +1,11 @@ -import styles from './loading.module.css'; - import { CircleNotch } from '@phosphor-icons/react'; export default function Loading() { return ( -
+ // NOTE: We can display usage tips here for casual learning moments. +
+
Loading
+
); } diff --git a/src/interface/web/app/components/loginPrompt/loginPrompt.tsx b/src/interface/web/app/components/loginPrompt/loginPrompt.tsx new file mode 100644 index 00000000..3ec4f2f3 --- /dev/null +++ b/src/interface/web/app/components/loginPrompt/loginPrompt.tsx @@ -0,0 +1,42 @@ +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle +} from '@/components/ui/alert-dialog'; +import Link from 'next/link'; + +export interface LoginPromptProps { + loginRedirectMessage: string; + onOpenChange: (open: boolean) => void; +} + +export default function LoginPrompt(props: LoginPromptProps) { + return ( + + + + Sign in to Khoj to continue + + {props.loginRedirectMessage}. By logging in, you agree to our Terms of Service. + + Dismiss + { + window.location.href = `/login?next=${encodeURIComponent(window.location.pathname)}`; + }}> + {/* Redirect to login page */} + Login + + + + + + ) +} diff --git a/src/interface/web/app/components/sidePanel/chatHistorySidePanel.tsx b/src/interface/web/app/components/sidePanel/chatHistorySidePanel.tsx index 382a45ee..351a77aa 100644 --- a/src/interface/web/app/components/sidePanel/chatHistorySidePanel.tsx +++ b/src/interface/web/app/components/sidePanel/chatHistorySidePanel.tsx @@ -4,7 +4,7 @@ import styles from "./sidePanel.module.css"; import { Suspense, useEffect, useState } from "react"; -import { UserProfile } from "@/app/common/auth"; +import { UserProfile, useAuthenticatedData } from "@/app/common/auth"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; import Link from "next/link"; import useSWR from "swr"; @@ -45,7 +45,7 @@ import { import { ScrollArea } from "@/components/ui/scroll-area"; -import { ArrowRight, ArrowLeft, ArrowDown, Spinner, Check, FolderPlus, DotsThreeVertical } from "@phosphor-icons/react"; +import { ArrowRight, ArrowLeft, ArrowDown, Spinner, Check, FolderPlus, DotsThreeVertical, House, StackPlus, UserCirclePlus } from "@phosphor-icons/react"; interface ChatHistory { conversation_id: string; @@ -496,7 +496,7 @@ function ChatSessionActionMenu(props: ChatSessionActionMenuProps) { setIsOpen(open)} open={isOpen}> - + + + + + + {/* Redirect to login page */} + + + + } ); } diff --git a/src/interface/web/app/share/chat/[slug]/page.tsx b/src/interface/web/app/share/chat/[slug]/page.tsx index 8681535e..d16b4478 100644 --- a/src/interface/web/app/share/chat/[slug]/page.tsx +++ b/src/interface/web/app/share/chat/[slug]/page.tsx @@ -76,7 +76,7 @@ function ChatBodyData(props: ChatBodyDataProps) { setMessage(message)} - sendDisabled={!props.isLoggedIn || processingMessage} + sendDisabled={processingMessage} chatOptionsData={props.chatOptionsData} conversationId={props.conversationId} isMobileWidth={props.isMobileWidth} @@ -280,7 +280,7 @@ export default function SharedChat({ params }: { params: { slug: string } }) { return ( -
+
{title} @@ -290,6 +290,7 @@ export default function SharedChat({ params }: { params: { slug: string } }) { conversationId={conversationId ?? null} uploadedFiles={uploadedFiles} />
+