-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Sidebar history Section #50
Changes from 6 commits
cc46f30
0dcb558
db8b261
b1a160c
65637a0
39b480b
2569896
266778e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
@@ -111,9 +124,10 @@ const ChatBottomBar = ({ onSend }: Props) => { | |
<Button | ||
size="icon" | ||
variant="default" | ||
className="rounded-full flex-shrink-0" | ||
className={buttonClass} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the styling logic moves here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: You can use |
||
type="button" | ||
onClick={handleSubmit} | ||
disabled={!message.content.trim()} | ||
> | ||
<ArrowUp /> | ||
</Button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const historyData = [ | ||
{ | ||
id: 1, | ||
title: 'What is hyperledge...' | ||
}, | ||
{ | ||
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' | ||
} | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
'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] | ||
})); | ||
}; | ||
|
||
const truncateTitle = (title: string) => { | ||
return title.length > 17 | ||
? title.slice(0, 17) + '...' | ||
: title; | ||
}; | ||
Sauradip07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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"> | ||
{truncateTitle(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 /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont need this. |
||
<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 "> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these can be |
||
<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 "> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too. |
||
<Trash2 className="ml-6" /> | ||
<span className="ml-3"> | ||
Delete | ||
</span> | ||
</button> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</button> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SidebarHistory; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ const config = { | |
extend: { | ||
colors: { | ||
border: 'hsl(var(--border))', | ||
'hover-blue': '#f1f5f9', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this, just use a lighter shade of whatever is available. |
||
input: 'hsl(var(--input))', | ||
ring: 'hsl(var(--ring))', | ||
background: 'hsl(var(--background))', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could instead use a disabled variable. Makes it easier when you extend it with global state.