Comments, appointments adjustments, fixed some issues

This commit is contained in:
augmentedpotato
2026-04-20 19:19:30 -06:00
parent d3b9c51952
commit 2cb0a94bbb
34 changed files with 402 additions and 104 deletions

View File

@@ -8,10 +8,12 @@ import { createStompClient } from "@/lib/chatSocket";
const API_BASE = "";
//Checks if a filename looks like an image based on its extension
function isImageFilename(name) {
return /\.(jpe?g|png|gif|webp|bmp|svg)$/i.test(name || "");
}
//Shows an image inline or a download link for other file types
function AttachmentPreview({ url, name, token }) {
const [blobUrl, setBlobUrl] = useState(null);
const isImage = isImageFilename(name);
@@ -68,6 +70,7 @@ function AttachmentPreview({ url, name, token }) {
);
}
//Returns true when the screen width is below 640px
function useIsMobile() {
const [isMobile, setIsMobile] = useState(false);
useEffect(() => {
@@ -79,6 +82,7 @@ function useIsMobile() {
return isMobile;
}
//AI chat page with a conversation sidebar, supports switching to a human agent and sending file attachments
function AiChatPage() {
const { user, token, loading: authLoading } = useAuth();
const router = useRouter();
@@ -137,6 +141,7 @@ function AiChatPage() {
if (nearBottom) area.scrollTop = area.scrollHeight;
}, [botTyping]);
//Loads all messages for a conversation and scrolls to the bottom
const fetchMessages = useCallback(async (convId) => {
if (!token || !convId) return;
initialLoadDoneRef.current = false;
@@ -162,6 +167,7 @@ function AiChatPage() {
}
}, [token]);
//Fetches a single conversation's details and stores it
const fetchConversation = useCallback(async (convId) => {
if (!token || !convId) return null;
try {
@@ -194,6 +200,7 @@ function AiChatPage() {
}
}, [token]);
//Connects the WebSocket and subscribes to new messages and conversation updates
const connectStomp = useCallback((convId) => {
if (stompRef.current) {
stompRef.current.deactivate();
@@ -301,6 +308,7 @@ function AiChatPage() {
};
}, [token, authLoading, conversationIdParam, fetchConversation, fetchMessages, connectStomp, fetchConversations, router]);
//Decides whether to send a text message or an attachment
async function handleSend(e) {
e?.preventDefault();
const text = input.trim();
@@ -312,6 +320,7 @@ function AiChatPage() {
}
}
//Sends a plain text message and shows a bot typing indicator
async function handleSendText(text) {
setInput("");
setSending(true);
@@ -356,6 +365,7 @@ function AiChatPage() {
}
}
//Uploads a file as an attachment, with an optional caption
async function handleSendAttachment(optionalText) {
setSending(true);
setError(null);
@@ -416,6 +426,7 @@ function AiChatPage() {
}
}
//Creates a new AI conversation and navigates to it
async function handleNewConversation() {
if (stompRef.current) { stompRef.current.deactivate(); stompRef.current = null; }
setError(null);
@@ -455,6 +466,7 @@ function AiChatPage() {
router.replace(`/ai-chat?id=${convId}`, { scroll: false });
}
//Requests a human agent for the current conversation
async function handleSwitchToHuman() {
if (!conversation) return;
try {
@@ -468,6 +480,7 @@ function AiChatPage() {
}
}
//Closes the current conversation so no more messages can be sent
async function handleCloseConversation() {
if (!conversation || conversation.status === "CLOSED") return;
try {