-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: initial sidebar implementation #11
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a2ab08
feat: inital sidebar implementation
georgi4444 2362dc8
feat: update sidebar implementation and add alerts menu
georgi4444 9556032
feat: add AlertsMenuWrapper component and update sidebar context for …
georgi4444 13dfdcf
feat: improve layout and spacing for Alerts section
georgi4444 a11194c
feat: requested changes
georgi4444 00d49d1
fix: theme switcher alignment
marinovl7 f3a026b
fix: solve merge conflicts
marinovl7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Button } from '@nextui-org/button'; | ||
import { Image } from '@nextui-org/image'; | ||
import clsx from 'clsx'; | ||
import { forwardRef } from 'react'; | ||
|
||
import { AlertButtonProps } from '@/domain/props/AlertButtonProps'; | ||
|
||
export const AlertButton = forwardRef<HTMLButtonElement, AlertButtonProps>( | ||
({ icon, label, isSelected, onClick, className, ...props }, ref) => { | ||
return ( | ||
<Button | ||
isIconOnly | ||
radius="full" | ||
className={clsx(isSelected ? 'bg-primary' : 'bg-content2', className)} | ||
onClick={onClick} | ||
ref={ref} | ||
{...props} | ||
> | ||
<div className="w-6 h-6 flex items-center justify-center"> | ||
<Image src={icon} alt={label} className="object-contain w-auto h-auto max-w-full max-h-full" /> | ||
</div> | ||
</Button> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use client'; | ||
|
||
import { Popover, PopoverContent, PopoverTrigger } from '@nextui-org/popover'; | ||
import { useMemo } from 'react'; | ||
|
||
import { AlertButton } from '@/components/AlertsMenu/AlertButton'; | ||
import { useSidebar } from '@/domain/contexts/SidebarContext'; | ||
import { AlertType } from '@/domain/enums/AlertType'; | ||
import { AlertsMenuProps } from '@/domain/props/AlertsMenuProps'; | ||
import { SidebarOperations } from '@/operations/charts/SidebarOperations'; | ||
|
||
export function AlertsMenu({ variant }: AlertsMenuProps) { | ||
const { isAlertSelected, toggleAlert } = useSidebar(); | ||
|
||
const isSubAlertClicked = useMemo( | ||
() => (mainAlert: AlertType) => { | ||
const alert = SidebarOperations.getSidebarAlertTypeByKey(mainAlert); | ||
return alert?.subalerts?.some((subalert) => isAlertSelected(subalert.key)) ?? false; | ||
}, | ||
[isAlertSelected] | ||
); | ||
|
||
return ( | ||
<div className="flex gap-1"> | ||
{SidebarOperations.getSidebarAlertTypes().map((item) => | ||
SidebarOperations.hasSubalerts(item) ? ( | ||
<Popover placement={variant === 'inside' ? 'bottom' : 'top'} key={item.key}> | ||
<PopoverTrigger> | ||
<AlertButton icon={item.icon} label={item.label} isSelected={isSubAlertClicked(item.key)} /> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<div className="gap-1 flex"> | ||
{item.subalerts.map((subalert) => ( | ||
<AlertButton | ||
key={subalert.key} | ||
icon={subalert.icon} | ||
label={subalert.label} | ||
isSelected={isAlertSelected(subalert.key)} | ||
onClick={() => toggleAlert(subalert.key)} | ||
/> | ||
))} | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
) : ( | ||
<AlertButton | ||
key={item.key} | ||
icon={item.icon} | ||
label={item.label} | ||
isSelected={isAlertSelected(item.key)} | ||
onClick={() => toggleAlert(item.key)} | ||
/> | ||
) | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client'; | ||
|
||
import { AlertsMenu } from '@/components/AlertsMenu/AlertsMenu'; | ||
import { useSidebar } from '@/domain/contexts/SidebarContext'; | ||
import { AlertsMenuVariant } from '@/domain/enums/AlertsMenuVariant'; | ||
|
||
export function AlertsMenuWrapper() { | ||
const { isSidebarOpen } = useSidebar(); | ||
|
||
if (isSidebarOpen) { | ||
return null; | ||
} | ||
return ( | ||
<div className="absolute bottom-0 left-0 z-50 p-4"> | ||
<AlertsMenu variant={AlertsMenuVariant.Outside} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Button } from '@nextui-org/button'; | ||
import { Card, CardBody, CardHeader } from '@nextui-org/card'; | ||
import { Image } from '@nextui-org/image'; | ||
import { Listbox, ListboxItem } from '@nextui-org/listbox'; | ||
import { SidebarRight } from 'iconsax-react'; | ||
|
||
import { CollapsedSidebarProps } from '@/domain/props/CollapsedSidebarProps'; | ||
import { SidebarOperations } from '@/operations/charts/SidebarOperations'; | ||
|
||
export function CollapsedSidebar({ selectedMapType, handleSelectionChange, toggleSidebar }: CollapsedSidebarProps) { | ||
return ( | ||
<div className="absolute top-0 left-0 z-50 p-4"> | ||
<Card className="h-full"> | ||
<CardHeader className="flex justify-center items-center"> | ||
<Button isIconOnly variant="light" onClick={toggleSidebar} aria-label="Close sidebar"> | ||
<SidebarRight size={24} /> | ||
</Button> | ||
</CardHeader> | ||
<CardBody> | ||
<Listbox | ||
variant="flat" | ||
aria-label="Listbox menu with sections" | ||
selectionMode="single" | ||
selectedKeys={new Set(selectedMapType)} | ||
onSelectionChange={handleSelectionChange} | ||
disallowEmptySelection | ||
hideSelectedIcon | ||
> | ||
{SidebarOperations.getSidebarMapTypes().map((item) => ( | ||
<ListboxItem key={item.key} textValue={item.label}> | ||
<div className="w-6 h-6 flex items-center justify-center"> | ||
<Image | ||
src={item.icon} | ||
alt={item.label} | ||
className="object-contain w-auto h-auto max-w-full max-h-full" | ||
/> | ||
</div> | ||
</ListboxItem> | ||
))} | ||
</Listbox> | ||
</CardBody> | ||
</Card> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
'use client'; | ||
|
||
import { Button } from '@nextui-org/button'; | ||
import { Card, CardBody, CardFooter, CardHeader } from '@nextui-org/card'; | ||
import { Input } from '@nextui-org/input'; | ||
import { Listbox, ListboxItem, ListboxSection } from '@nextui-org/listbox'; | ||
import { SidebarLeft } from 'iconsax-react'; | ||
import NextImage from 'next/image'; | ||
|
||
import { AlertsMenu } from '@/components/AlertsMenu/AlertsMenu'; | ||
import { CollapsedSidebar } from '@/components/Sidebar/CollapsedSidebar'; | ||
import { ThemeSwitch } from '@/components/Sidebar/ThemeSwitch'; | ||
import { useSidebar } from '@/domain/contexts/SidebarContext'; | ||
import { AlertsMenuVariant } from '@/domain/enums/AlertsMenuVariant'; | ||
import { GlobalInsight } from '@/domain/enums/GlobalInsight'; | ||
import { SidebarOperations } from '@/operations/charts/SidebarOperations'; | ||
|
||
export function Sidebar() { | ||
const { isSidebarOpen, toggleSidebar, selectedMapType, setSelectedMapType } = useSidebar(); | ||
|
||
const handleSelectionChange = (key: 'all' | Set<string | number>) => { | ||
return key instanceof Set | ||
? setSelectedMapType(Array.from(key)[0] as GlobalInsight) | ||
: setSelectedMapType(key as GlobalInsight); | ||
}; | ||
|
||
if (!isSidebarOpen) { | ||
return ( | ||
<CollapsedSidebar | ||
selectedMapType={selectedMapType} | ||
handleSelectionChange={handleSelectionChange} | ||
toggleSidebar={toggleSidebar} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="absolute top-0 left-0 z-50 h-screen p-4"> | ||
<Card | ||
classNames={{ | ||
base: 'h-full', | ||
header: 'flex flex-col gap-4 w-full items-start', | ||
footer: 'flex flex-col items-start', | ||
}} | ||
> | ||
<CardHeader> | ||
<div className="flex items-center w-full gap-4"> | ||
<NextImage src="/wfp_logo.svg" alt="HungerMap" width={45} height={45} /> | ||
<p className="text-lg font-medium flex-1">HungerMap LIVE</p> | ||
<Button isIconOnly variant="light" onClick={toggleSidebar} aria-label="Close sidebar"> | ||
<SidebarLeft size={24} /> | ||
</Button> | ||
</div> | ||
|
||
<ThemeSwitch /> | ||
<Input className="w-full" color="primary" placeholder="Search a country" variant="faded" /> | ||
</CardHeader> | ||
<CardBody> | ||
<Listbox | ||
variant="flat" | ||
aria-label="Listbox menu with sections" | ||
selectionMode="single" | ||
selectedKeys={new Set(selectedMapType)} | ||
onSelectionChange={handleSelectionChange} | ||
disallowEmptySelection | ||
hideSelectedIcon | ||
> | ||
<ListboxSection title="Global Insights"> | ||
{SidebarOperations.getSidebarMapTypes().map((item) => ( | ||
<ListboxItem | ||
key={item.key} | ||
startContent={item.icon && <NextImage src={item.icon} alt={item.label} width={24} height={24} />} | ||
> | ||
{item.label} | ||
</ListboxItem> | ||
))} | ||
</ListboxSection> | ||
</Listbox> | ||
<div className="p-1 w-full"> | ||
<span className="text-xs text-foreground-500 pl-1">Alerts</span> | ||
<div className="pt-1"> | ||
<AlertsMenu variant={AlertsMenuVariant.Inside} /> | ||
</div> | ||
</div> | ||
</CardBody> | ||
<CardFooter> | ||
<Button radius="full" onClick={() => alert('Subscribe!')} size="sm"> | ||
SUBSCRIBE | ||
</Button> | ||
<Listbox variant="flat" aria-label="Listbox menu with sections"> | ||
<ListboxItem key="home">Home</ListboxItem> | ||
<ListboxItem key="about">About</ListboxItem> | ||
<ListboxItem key="glossary">Glossary</ListboxItem> | ||
<ListboxItem key="methodology">Methodology</ListboxItem> | ||
<ListboxItem key="disclaimer">Disclaimer</ListboxItem> | ||
</Listbox> | ||
</CardFooter> | ||
</Card> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this doesn't use any client side APIs so could be a server component
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.
I get an error when I make server component, because it uses useSidebar from the context