Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './App.css';
import { Ingester } from './components/Ingester';
import { Chat } from './components/Chat';
import { clearSession } from './api';
import { Toaster, toast } from 'react-hot-toast';

function App() {

Expand All @@ -11,12 +12,19 @@ function App() {
}, []);

const handleManualClear = async () => {
await clearSession();
window.location.reload();
try {
await clearSession();
toast.success('Session cleared successfully');
setTimeout(() => window.location.reload(), 1000);
} catch (error) {
console.error(error);
toast.error('Failed to clear session');
}
}

return (
<div className="app-container">
<Toaster position="top-right" />
<header className="header glass">
<div className="brand">
🔍 SearchlyAI
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useRef, useEffect } from 'react';
import { toast } from 'react-hot-toast';
import { querySearch } from '../api';

interface Message {
Expand Down Expand Up @@ -36,6 +37,7 @@ export const Chat = () => {
setHistory((prev) => [...prev, aiMsg]);
} catch (err) {
console.error(err);
toast.error('Failed to get answer');
setHistory((prev) => [...prev, { role: 'ai', content: 'Sorry, something went wrong.' }]);
} finally {
setLoading(false);
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/Ingester.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { toast } from 'react-hot-toast';
import { ingestDocument, ingestWeb } from '../api';

interface IngesterProps {
Expand All @@ -14,12 +15,15 @@ export const Ingester = ({ onIngestComplete }: IngesterProps) => {
if (!e.target.files?.[0]) return;
setLoading(true);
setError('');
const toastId = toast.loading('Uploading document...');
try {
const res = await ingestDocument(e.target.files[0]);
onIngestComplete(res.data.chunks_added);
toast.success('Document uploaded successfully!', { id: toastId });
} catch (err) {
console.error(err);
setError('Failed to upload file.');
toast.error('Failed to upload file.', { id: toastId });
} finally {
setLoading(false);
}
Expand All @@ -29,13 +33,16 @@ export const Ingester = ({ onIngestComplete }: IngesterProps) => {
if (!url) return;
setLoading(true);
setError('');
const toastId = toast.loading('Ingesting URL...');
try {
const res = await ingestWeb(url);
onIngestComplete(res.data.chunks_added);
setUrl('');
toast.success('URL ingested successfully!', { id: toastId });
} catch (err) {
console.error(err);
setError('Failed to ingest URL.');
toast.error('Failed to ingest URL.', { id: toastId });
} finally {
setLoading(false);
}
Expand Down