Skip to content

Commit

Permalink
Welcome page
Browse files Browse the repository at this point in the history
Signed-off-by: Supratick Mondal <[email protected]>
  • Loading branch information
sonustar committed Sep 14, 2024
1 parent 653c66d commit 8083e2e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/core/routes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class RequestConversation(BaseModel):
"How to ensure data privacy in Hyperledger Fabric?": "To ensure data privacy in Hyperledger Fabric:\n1. Use private data collections to restrict access to sensitive data.\n2. Implement access control policies and endorsement policies.\n3. Utilize encryption for data at rest and in transit.\n4. Regularly review and update security configurations and practices.",
}

@router.get("/response-keys", response_model=List[Dict[str, str]])
async def get_response_keys() -> List[Dict[str, str]]:
# Create a list of dictionaries with 'id' and 'name' keys
res = ([{"id": str(index+1), "name": key} for index, key in enumerate(responses.keys())])
return res


def get_hyperledger_fabric_answer(question):
return responses.get(question, "Question not found in the database.")
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/components/chat-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import React, { useState } from 'react';
import ChatHeader from './chat-header';
import { Message } from '@/lib/types';
import { Suspense } from 'react';
import WelcomeSection from './welcome-section';
import ChatBottomBar from './chat-bottom-bar';
import ChatSection from './chat-section';

Expand All @@ -27,6 +29,12 @@ const ChatPage = (props: Props) => {
<ChatHeader />
<main className="flex-1 overflow-y-auto">
<ChatSection messages={messages} />

{messages.length === 0 && (
<Suspense fallback={<p>Loading....</p>}>
<WelcomeSection />
</Suspense>
)}
</main>
<ChatBottomBar onSend={updateMessages} />
</div>
Expand Down
54 changes: 50 additions & 4 deletions src/frontend/components/welcome-section.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
import React from 'react';
'use-client';
import React, {
useState,
useEffect
} from 'react';
import { IconHyperledger } from './icons/IconHyperledger';
import { SERVER_BASE_URL } from '@/lib/const';
import { Suspense } from 'react';

type Props = {};

interface Message {
id: string;
name: string;
}

const WelcomeSection = (props: Props) => {
const [messages, setMessages] = useState<
Message[]
>([]);

useEffect(() => {
async function fetchData() {
const response = await fetch(
SERVER_BASE_URL + '/response-keys'
);
const data = await response.json();
setMessages(data);
}

fetchData();
}, []);

return (
<div className="flex h-full flex-col items-center justify-center text-primary space-y-2">
<IconHyperledger className="w-16 h-16 fill-primary shrink-0" />
</div>
<>
<div className="flex h-1/2 flex-col items-center justify-center text-primary space-y-2">
<IconHyperledger className="w-16 h-16 fill-primary shrink-0" />
</div>

<Suspense fallback={<p>Loading....</p>}>
<div className="grid grid-cols-2 gap-2 p-4">
{messages.map((user: Message) => (
<li
key={user.id}
className="flex flex-end items-center justify-between p-4 bg-white shadow rounded-lg text-gray-600"
>
<div className="flex flex-col space-y-1">
<h2 className="text-lg font-semibold">
{user.name}
</h2>
</div>
</li>
))}
</div>
</Suspense>
</>
);
};

Expand Down

0 comments on commit 8083e2e

Please sign in to comment.