Skip to content

Commit

Permalink
Add Sidebar history Section (#50)
Browse files Browse the repository at this point in the history
* Add sidebar history and submit button ui change

Signed-off-by: Sauradip Ghosh <[email protected]>

* Format Fix

Signed-off-by: Sauradip Ghosh <[email protected]>

* Span and Overflow added

Signed-off-by: Sauradip Ghosh <[email protected]>

* Rename files

Signed-off-by: Sauradip Ghosh <[email protected]>

* convert checkboxes to button

Signed-off-by: Sauradip Ghosh <[email protected]>

* button's class a state variable added

Signed-off-by: Sauradip Ghosh <[email protected]>

* Remove truncateTitle

Signed-off-by: Sauradip Ghosh <[email protected]>

* Format Fix

Signed-off-by: Sauradip Ghosh <[email protected]>

---------

Signed-off-by: Sauradip Ghosh <[email protected]>
  • Loading branch information
Sauradip07 authored Oct 2, 2024
1 parent 62b4aa7 commit 2574e99
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/frontend/components/chat-bottom-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,25 @@ const ChatBottomBar = ({ onSend }: Props) => {
id: '-1'
}
);
const [buttonClass, setButtonClass] = useState(
'rounded-full flex-shrink-0 transition-opacity duration-200 opacity-50'
);
const { isMobile } = useWindowSize();

useEffect(() => {
setIsMounted(true);
}, [isMounted]);

useEffect(() => {
setButtonClass(
`rounded-full flex-shrink-0 transition-opacity duration-200 ${
message.content.trim()
? 'opacity-100'
: 'opacity-50'
}`
);
}, [message.content]);

if (!isMounted) {
return null;
}
Expand Down Expand Up @@ -111,9 +124,10 @@ const ChatBottomBar = ({ onSend }: Props) => {
<Button
size="icon"
variant="default"
className="rounded-full flex-shrink-0"
className={buttonClass}
type="button"
onClick={handleSubmit}
disabled={!message.content.trim()}
>
<ArrowUp />
</Button>
Expand Down
22 changes: 22 additions & 0 deletions src/frontend/components/history-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const historyData = [
{
id: 1,
title: 'What is hyperledger fabric'
},
{
id: 2,
title: 'How to install hyperledger fabric'
},
{
id: 3,
title: 'How to deploy hyperledger fabric'
},
{
id: 4,
title: 'How to run hyperledger fabric'
},
{
id: 5,
title: 'How to ensure data privacy'
}
];
105 changes: 105 additions & 0 deletions src/frontend/components/sidebar-history.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'use client';
import React, {
useEffect,
useState
} from 'react';
import {
DropdownMenuCheckboxItemProps,
DropdownMenuItem
} from '@radix-ui/react-dropdown-menu';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuSeparator,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu';
import {
EllipsisVertical,
Pencil,
Pin,
Trash2
} from 'lucide-react';

// Import the mock data
import { historyData as mockHistoryData } from './history-data';

type Props = {};
type Checked =
DropdownMenuCheckboxItemProps['checked'];

const SidebarHistory = (props: Props) => {
const [checkedItems, setCheckedItems] =
useState<Record<number, Checked>>({});
const [historyData, setHistoryData] = useState<
{ id: number; title: string }[]
>([]);

useEffect(() => {
setHistoryData(mockHistoryData);
}, []);

const handleCheckedChange = (id: number) => {
setCheckedItems((prevCheckedItems) => ({
...prevCheckedItems,
[id]: !prevCheckedItems[id]
}));
};

return (
<div className="mt-10">
{historyData.map((item) => (
<div
key={item.id}
className="flex justify-between mt-1 p-3 border-none rounded-lg font-semibold bg-slate-800 hover:bg-slate-800 cursor-pointer"
>
<span className="my-auto truncate overflow-hidden whitespace-nowrap">
{item.title}
</span>

<button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="outline"
className="p-0 m-0 text-white bg-slate-800 hover:bg-slate-800 hover:text-white font-semibold border-none"
>
<EllipsisVertical />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
<DropdownMenuSeparator />
<DropdownMenuCheckboxItem
checked={
!!checkedItems[item.id]
}
onCheckedChange={() =>
handleCheckedChange(item.id)
}
>
<Pin className="mr-2" /> Pin
</DropdownMenuCheckboxItem>
<button className="p-[7px] flex flex-rowtext-left w-full hover:bg-hover-blue border-none hover:border-none ">
<Pencil className="ml-6" />
<span className="ml-3">
Rename
</span>
</button>

<button className="p-[7px] flex flex-rowtext-left w-full hover:bg-hover-blue border-none hover:border-none ">
<Trash2 className="ml-6" />
<span className="ml-3">
Delete
</span>
</button>
</DropdownMenuContent>
</DropdownMenu>
</button>
</div>
))}
</div>
);
};

export default SidebarHistory;
3 changes: 3 additions & 0 deletions src/frontend/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SheetTitle,
SheetTrigger
} from '@/components/ui/sheet';
import SidebarHistory from './sidebar-history';

type Props = {};

Expand Down Expand Up @@ -93,6 +94,7 @@ const Sidebar = (props: Props) => {
<FilePlus />
</button>
</div>
<SidebarHistory />
</SheetHeader>
</SheetContent>
</Sheet>
Expand All @@ -118,6 +120,7 @@ const Sidebar = (props: Props) => {
isOpen={sidebarOpen}
toggleSidebar={handleViewSidebar}
/>
<SidebarHistory />
</aside>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const config = {
extend: {
colors: {
border: 'hsl(var(--border))',
'hover-blue': '#f1f5f9',
input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))',
background: 'hsl(var(--background))',
Expand Down

0 comments on commit 2574e99

Please sign in to comment.