Skip to content
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 7 commits into from
Nov 8, 2024

Conversation

georgi4444
Copy link
Collaborator

@georgi4444 georgi4444 commented Nov 4, 2024

  • used nextui card instead of shadcn implementation
  • added context provider with the state of the sidebar and information about clicked map type and alert type
  • can be closed and opened
  • alert menu bottom right when sidebar is closed
  • dark/light mode switch

todos:

  • missing alert info when hovered
  • missing input field when sidebar is closed
  • maptypes shouldn't lose selected styling when out of focus

@georgi4444 georgi4444 changed the title feat: implement sidebar feat: initial sidebar implementation Nov 4, 2024
@georgi4444 georgi4444 marked this pull request as ready for review November 4, 2024 14:14
Copy link
Collaborator

@Tschonti Tschonti left a 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

Comment on lines 78 to 86
<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>
Copy link
Collaborator

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

Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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

Comment on lines 14 to 25
type Alert = {
key: AlertKey;
label: string;
icon: string;
};

type AlertType = {
key: AlertTypeKey;
label: string;
icon: string;
subalerts: Alert[];
};
Copy link
Collaborator

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)

Copy link
Collaborator

@marinovl7 marinovl7 left a 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.

Comment on lines 20 to 21
<SidebarProvider>
<NextUIProvider navigate={router.push}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SidebarProvider after the NextUIProvider

Comment on lines 14 to 25
type Alert = {
key: AlertKey;
label: string;
icon: string;
};

type AlertType = {
key: AlertTypeKey;
label: string;
icon: string;
subalerts: Alert[];
};
Copy link
Collaborator

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

Comment on lines 27 to 55
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',
},
];
Copy link
Collaborator

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

Comment on lines 57 to 59
type AlertsMenuProps = {
variant: 'outside' | 'inside';
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type same as above

Comment on lines 78 to 86
<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>
Copy link
Collaborator

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

<p className="text-lg font-medium">HungerMap LIVE</p>
</div>
<Button isIconOnly variant="light" onClick={toggleSidebar} aria-label="Close sidebar">
<SquareChevronLeft size={18} />
Copy link
Collaborator

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

Comment on lines 153 to 156
<ListboxItem key="gloss">Glossary</ListboxItem>
<ListboxItem key="methd">Methodology</ListboxItem>
<ListboxItem key="disc">Disclaimer</ListboxItem>
</Listbox>
Copy link
Collaborator

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

Comment on lines 5 to 22
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;
}
Copy link
Collaborator

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

Copy link
Collaborator Author

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


const mapTypes: MapType[] = [
{
key: 'food',
Copy link
Collaborator

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',
Copy link
Collaborator

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

@georgi4444 georgi4444 force-pushed the feature/f-29-implement-sidebar branch from 07e85c8 to a11194c Compare November 7, 2024 19:59
@georgi4444
Copy link
Collaborator Author

All requested changes are done in a11194c

Copy link

netlify bot commented Nov 8, 2024

Deploy Preview for wfp-hungermap ready!

Name Link
🔨 Latest commit f3a026b
🔍 Latest deploy log https://app.netlify.com/sites/wfp-hungermap/deploys/672e4ee2e2e5c500084d771c
😎 Deploy Preview https://deploy-preview-11--wfp-hungermap.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@marinovl7 marinovl7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job!

@marinovl7 marinovl7 merged commit 3386164 into main Nov 8, 2024
5 checks passed
@marinovl7 marinovl7 deleted the feature/f-29-implement-sidebar branch November 8, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants