-
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
Conversation
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.
generally, all types and interfaces should be defined in the domain folder
<Button isIconOnly radius="full" className={isSubAlertClicked(item.key) ? 'bg-primary' : 'bg-background'}> | ||
<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> | ||
</Button> |
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.
it seems like this is repeated 3 times in this file. Can't we create a component from this? Olcick and className could be set with props
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've tried but couldn't make the popover trigger work when I provide it with my custom button function 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.
You should provide a function in the custom component props
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.
Solved: had to forward the ref
type Alert = { | ||
key: AlertKey; | ||
label: string; | ||
icon: string; | ||
}; | ||
|
||
type AlertType = { | ||
key: AlertTypeKey; | ||
label: string; | ||
icon: string; | ||
subalerts: Alert[]; | ||
}; |
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.
isn't one type enough with the subalerts property being optional? (or just an empty array)
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.
Sidebar Implementation is generally good, I really like it and overall awesome job. Just some refactoring would be needed to make it perfect, but no coding mistake here, just few code style guidelines which if you follow will make the component cleaner and easily maintanable.
src/app/providers.tsx
Outdated
<SidebarProvider> | ||
<NextUIProvider navigate={router.push}> |
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.
SidebarProvider after the NextUIProvider
type Alert = { | ||
key: AlertKey; | ||
label: string; | ||
icon: string; | ||
}; | ||
|
||
type AlertType = { | ||
key: AlertTypeKey; | ||
label: string; | ||
icon: string; | ||
subalerts: Alert[]; | ||
}; |
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.
Types to be moved in domain/entities/sidebar
const alertTypes: (Alert | AlertType)[] = [ | ||
{ | ||
key: 'hunger', | ||
label: 'Hunger Alert', | ||
icon: '/menu_fcs.png', | ||
}, | ||
{ | ||
key: 'conflicts', | ||
label: 'Conflicts', | ||
icon: '/menu_conflicts.png', | ||
subalerts: [ | ||
{ | ||
key: 'conflicts1', | ||
label: 'Conflicts 1', | ||
icon: '/menu_conflicts.png', | ||
}, | ||
{ | ||
key: 'conflicts2', | ||
label: 'Conflicts 2', | ||
icon: '/menu_conflicts.png', | ||
}, | ||
], | ||
}, | ||
{ | ||
key: 'hazards', | ||
label: 'Hazards', | ||
icon: '/menu_hazards.png', | ||
}, | ||
]; |
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 could be moved to operations/sidebar/SidebarOperations.ts
type AlertsMenuProps = { | ||
variant: 'outside' | 'inside'; | ||
}; |
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.
Type same as above
<Button isIconOnly radius="full" className={isSubAlertClicked(item.key) ? 'bg-primary' : 'bg-background'}> | ||
<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> | ||
</Button> |
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 should provide a function in the custom component props
src/components/Sidebar/Sidebar.tsx
Outdated
<p className="text-lg font-medium">HungerMap LIVE</p> | ||
</div> | ||
<Button isIconOnly variant="light" onClick={toggleSidebar} aria-label="Close sidebar"> | ||
<SquareChevronLeft size={18} /> |
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.
size 18 in expanded vs size 24 for expanded is inconsistent
src/components/Sidebar/Sidebar.tsx
Outdated
<ListboxItem key="gloss">Glossary</ListboxItem> | ||
<ListboxItem key="methd">Methodology</ListboxItem> | ||
<ListboxItem key="disc">Disclaimer</ListboxItem> | ||
</Listbox> |
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.
use entire words for the keys as well
interface SelectedMapTypeState { | ||
selectedMapType: MapKey; | ||
setSelectedMapType: (value: MapKey) => void; | ||
} | ||
|
||
interface SelectedAlertsState { | ||
selectedAlert: string; | ||
setSelectedAlert: (value: string) => void; | ||
isAlertSelected: (alertType: string) => boolean; | ||
toggleAlert: (alertType: string) => void; | ||
} | ||
|
||
interface SidebarState { | ||
isSidebarOpen: boolean; | ||
toggleSidebar: () => void; | ||
openSidebar: () => void; | ||
closeSidebar: () => void; | ||
} |
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.
interfaces go to domain/entries/Sidebar
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 moved SidebarContext.tsx to domain/contexts/SidebarContext.tsx
. I left the intefaces in the file like it is in CountryContext.tsx
src/components/Sidebar/Sidebar.tsx
Outdated
|
||
const mapTypes: MapType[] = [ | ||
{ | ||
key: 'food', |
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.
keys here generally should be an Enum
|
||
const alertTypes: (Alert | AlertType)[] = [ | ||
{ | ||
key: 'hunger', |
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.
keys should generally be Enums
export enum AlertTypes {
HUNGER = 'hunger'
...
]
And use it like this
key: AlertType.HUNGER
07e85c8
to
a11194c
Compare
All requested changes are done in a11194c |
✅ Deploy Preview for wfp-hungermap ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Great Job!
todos: