From 6711a5daddd8012fe0490a371d0cd52e46ae07eb Mon Sep 17 00:00:00 2001 From: rathi Date: Sun, 8 Dec 2024 23:12:11 -0500 Subject: [PATCH] settings update --- src/pages/dashboard/Settings.tsx | 71 ++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/src/pages/dashboard/Settings.tsx b/src/pages/dashboard/Settings.tsx index 117812e..55a1895 100644 --- a/src/pages/dashboard/Settings.tsx +++ b/src/pages/dashboard/Settings.tsx @@ -1,15 +1,48 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { Card } from '../../components/ui/card'; import { Label } from '../../components/ui/label'; import { Switch } from '../../components/ui/Switch'; import { useTheme } from '../../contexts/ThemeContext'; import { Button } from '../../components/ui/Button'; import { supabase } from '../../lib/supabase'; -import { Trash2 } from 'lucide-react'; +import { Trash2, FileText } from 'lucide-react'; + +interface Document { + id: number; + content: string; + metadata: { + lines: { + to: number; + from: number; + }[]; + source: string; + }; +} function Settings() { const { isDarkMode, toggleDarkMode } = useTheme(); const [isDeleting, setIsDeleting] = useState(false); + const [documents, setDocuments] = useState([]); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + fetchDocuments(); + }, []); + + const fetchDocuments = async () => { + try { + const { data, error } = await supabase + .from('documents') + .select('id, content, metadata'); + + if (error) throw error; + setDocuments(data || []); + } catch (error) { + console.error('Error fetching documents:', error); + } finally { + setIsLoading(false); + } + }; const handleDeleteResources = async () => { // Add confirmation dialog @@ -38,6 +71,7 @@ function Settings() { if (chatHistoryError) throw chatHistoryError; + setDocuments([]); // Clear the documents list alert('All resources have been deleted successfully'); } catch (error) { console.error('Error deleting resources:', error); @@ -58,7 +92,7 @@ function Settings() {

Enable dark color theme

- {isDeleting ? 'Deleting...' : 'Delete All Resources'} + +
+ +
+ {isLoading ? ( +

Loading documents...

+ ) : documents.length === 0 ? ( +

No documents found

+ ) : ( +
+ {documents.map((doc) => ( +
+ +
+

{doc.content}

+

+ Source: {doc.metadata?.source || 'Unknown'} +

+
+ + ID: {doc.id} + +
+ ))} +
+ )} +
+