diff --git a/browser-extensions/chrome/src/components/AppContent.tsx b/browser-extensions/chrome/src/components/AppContent.tsx index a6f4eb9a5..b64a832ff 100644 --- a/browser-extensions/chrome/src/components/AppContent.tsx +++ b/browser-extensions/chrome/src/components/AppContent.tsx @@ -5,6 +5,7 @@ import { useDb } from '../context/DbContext'; import Unlock from './Unlock'; import Login from './Login'; import Settings from './Settings'; +import CredentialsList from './CredentialsList'; interface Credential { Id: string; @@ -39,49 +40,20 @@ function base64Encode(buffer: any): string | null { const AppContent: React.FC = () => { const { isLoggedIn, username, logout } = useAuth(); const dbContext = useDb(); - const [credentials, setCredentials] = useState([]); const [needsUnlock, setNeedsUnlock] = useState(false); const [showSettings, setShowSettings] = useState(false); useEffect(() => { if (isLoggedIn) { - console.log('isLoggedIn is true'); if (!dbContext.isInitialized) { - console.log('Database is not initialized, setting needsUnlock to true'); setNeedsUnlock(true); } else { - console.log('Database is initialized, setting needsUnlock to false'); setNeedsUnlock(false); - loadCredentials(); } } }, [isLoggedIn, dbContext.isInitialized]); - const loadCredentials = () => { - if (!dbContext?.sqliteClient) return; - - try { - const results = dbContext.sqliteClient.executeQuery( - `SELECT - c.Id, - c.Username as Username, - s.Name as ServiceName, - s.Logo as Logo - FROM Credentials c - JOIN Services s ON s.Id = c.ServiceId - WHERE c.IsDeleted = 0` - ); - setCredentials(results); - - console.log(results); - } catch (err) { - console.error('Error loading credentials:', err); - } - }; - const handleLogout = () => { - setCredentials([]); - setNeedsUnlock(true); logout(); }; @@ -134,32 +106,7 @@ const AppContent: React.FC = () => { ) : (
-
-

Your Credentials

- {credentials.length === 0 ? ( -

No credentials found

- ) : ( -
    - {credentials.map(cred => ( -
  • - {cred.ServiceName} { - const target = e.target as HTMLImageElement; - target.src = '/images/service-placeholder.webp'; - }} - /> -
    -

    {cred.ServiceName}

    -

    {cred.Username}

    -
    -
  • - ))} -
- )} -
+
)} diff --git a/browser-extensions/chrome/src/components/CredentialsList.tsx b/browser-extensions/chrome/src/components/CredentialsList.tsx new file mode 100644 index 000000000..b7ad038a9 --- /dev/null +++ b/browser-extensions/chrome/src/components/CredentialsList.tsx @@ -0,0 +1,73 @@ +import React, { useState, useEffect } from 'react'; +import { useDb } from '../context/DbContext'; + +interface Credential { + Id: string; + ServiceName: string; + Username: string; + Logo?: any; +} + +interface CredentialsListProps { + base64Encode: (buffer: any) => string | null; +} + +const CredentialsList: React.FC = ({ base64Encode }) => { + const dbContext = useDb(); + const [credentials, setCredentials] = useState([]); + + useEffect(() => { + loadCredentials(); + }, [dbContext.sqliteClient]); + + const loadCredentials = () => { + if (!dbContext?.sqliteClient) return; + + try { + const results = dbContext.sqliteClient.executeQuery( + `SELECT + c.Id, + c.Username as Username, + s.Name as ServiceName, + s.Logo as Logo + FROM Credentials c + JOIN Services s ON s.Id = c.ServiceId + WHERE c.IsDeleted = 0` + ); + setCredentials(results); + } catch (err) { + console.error('Error loading credentials:', err); + } + }; + + return ( +
+

Your Credentials

+ {credentials.length === 0 ? ( +

No credentials found

+ ) : ( +
    + {credentials.map(cred => ( +
  • + {cred.ServiceName} { + const target = e.target as HTMLImageElement; + target.src = '/images/service-placeholder.webp'; + }} + /> +
    +

    {cred.ServiceName}

    +

    {cred.Username}

    +
    +
  • + ))} +
+ )} +
+ ); +}; + +export default CredentialsList; \ No newline at end of file