-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Optimize mobile nav #16111
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
Merged
Merged
Optimize mobile nav #16111
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f7fff39
disabled sheet overlay for performance improvements
pettinarip baa3078
calc filtered locales outside of the component
pettinarip bfc7d85
disable dialog overlay for performance improvements
pettinarip b965e5d
reorder nav to enable server rendering
pettinarip 9f13310
refactor mobile menu to implement rsc as much as possible
pettinarip 9a753de
refactor MenuFooter to be server rendered
pettinarip 38c1c6d
refactor the LanguagePicker to precompute the languages list on the s…
pettinarip a0151bf
add navigation links lib
pettinarip aecae90
moblie menu
pettinarip 74e00e1
remove back button
pettinarip 7c0d78e
cleanup
pettinarip 24db038
refactor mobile nav
pettinarip 5bb9623
compute progress on the server
pettinarip 65ae384
use collapsible instead of accordion
pettinarip 5aaaa6d
active link styles
pettinarip 849c001
track matomo events
pettinarip 56e96bd
nav: lazy render & loading skeletons
pettinarip 2049df8
hide sheet overlay only for the mobile menu
pettinarip 6b75608
implement SheetDismiss to close menu when a link is clicked
pettinarip 00db348
Merge branch 'staging' into optimize-nav
pettinarip 19f73bd
cleanup duplicated code
pettinarip f0638e5
create a new sheet component to close on navigation
pettinarip fa9099e
refactor lang picker to share code between desktop and mobile versions
pettinarip 4fd1b18
remove code duplication for the nav links
pettinarip 2699afd
use intl navigation hooks
pettinarip 59b9d46
fix intl in sc
pettinarip d007c11
remove unnecessary p tags
pettinarip 0b94574
fix rtl support in mobile menu tab content
pettinarip ba34098
fix hydration issue with media queries
pettinarip 75d3c7e
update openLanguagePickerMobile function with correct test id
pettinarip afec995
move localeToDisplayInfo function to lib
pettinarip 7fd2a85
cleanup redundant code component
pettinarip f8f3f5e
reorg menu footer buttons and replace the serach with menu button
pettinarip 92ffc7f
highlight selected footer button in menu
pettinarip 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 hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,19 @@ | ||
| "use client" | ||
|
|
||
| import { type ReactNode } from "react" | ||
|
|
||
| import { useIsClient } from "@/hooks/useIsClient" | ||
|
|
||
| type ClientOnlyProps = { | ||
| children: ReactNode | ||
| fallback?: ReactNode | ||
| } | ||
|
|
||
| const ClientOnly = ({ children, fallback = null }: ClientOnlyProps) => { | ||
| const isClient = useIsClient() | ||
|
|
||
| if (!isClient) return <>{fallback}</> | ||
| return <>{children}</> | ||
| } | ||
|
|
||
| export default ClientOnly | ||
This file contains hidden or 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,59 @@ | ||
| "use client" | ||
|
|
||
| import type { LocaleDisplayInfo } from "@/lib/types" | ||
|
|
||
| import { cn } from "@/lib/utils/cn" | ||
|
|
||
| import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover" | ||
|
|
||
| import LanguagePicker from "." | ||
|
|
||
| import { useDisclosure } from "@/hooks/useDisclosure" | ||
| import { useEventListener } from "@/hooks/useEventListener" | ||
|
|
||
| type DesktopLanguagePickerProps = { | ||
| children: React.ReactNode | ||
| languages: LocaleDisplayInfo[] | ||
| className?: string | ||
| } | ||
|
|
||
| const DesktopLanguagePicker = ({ | ||
| children, | ||
| languages, | ||
| className, | ||
| }: DesktopLanguagePickerProps) => { | ||
| const { isOpen, setValue, onClose, onOpen } = useDisclosure() | ||
|
|
||
| /** | ||
| * Adds a keydown event listener to focus filter input (\). | ||
| * @param {string} event - The keydown event. | ||
| */ | ||
| useEventListener("keydown", (e) => { | ||
| if (e.key !== "\\" || e.metaKey || e.ctrlKey) return | ||
| e.preventDefault() | ||
| onOpen() | ||
| }) | ||
|
|
||
| return ( | ||
| <Popover open={isOpen} onOpenChange={setValue}> | ||
| <PopoverTrigger asChild>{children}</PopoverTrigger> | ||
| <PopoverContent | ||
| align="end" | ||
| className={cn( | ||
| "flex w-[320px] flex-col bg-background-highlight p-0", | ||
| className | ||
| )} | ||
| > | ||
| <LanguagePicker | ||
| className="max-h-[calc(100vh-12rem)]" | ||
| languages={languages} | ||
| onSelect={onClose} | ||
| onNoResultsClose={onClose} | ||
| onTranslationProgramClick={onClose} | ||
| /> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ) | ||
| } | ||
|
|
||
| export default DesktopLanguagePicker |
This file contains hidden or 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,55 @@ | ||
| import { useLocale } from "next-intl" | ||
|
|
||
| import type { LocaleDisplayInfo } from "@/lib/types" | ||
|
|
||
| import { ButtonLink } from "@/components/ui/buttons/Button" | ||
|
|
||
| import { DEFAULT_LOCALE } from "@/lib/constants" | ||
|
|
||
| import { useTranslation } from "@/hooks/useTranslation" | ||
|
|
||
| type LanguagePickerFooterProps = { | ||
| intlLanguagePreference?: LocaleDisplayInfo | ||
| onTranslationProgramClick: () => void | ||
| } | ||
|
|
||
| const LanguagePickerFooter = ({ | ||
| intlLanguagePreference, | ||
| onTranslationProgramClick, | ||
| }: LanguagePickerFooterProps) => { | ||
| const { t } = useTranslation("common") | ||
| const locale = useLocale() | ||
| return ( | ||
| <div className="sticky bottom-0 flex border-t-2 border-primary bg-primary-low-contrast p-0 pb-1 pt-1"> | ||
| <div className="flex w-full items-center justify-between px-4"> | ||
| <div className="flex min-w-0 flex-col items-start"> | ||
| {locale === DEFAULT_LOCALE ? ( | ||
| <p className="overflow-hidden text-ellipsis whitespace-nowrap text-xs font-bold text-body"> | ||
| {intlLanguagePreference | ||
| ? `${t("page-languages-translate-cta-title")} ${t(`language-${intlLanguagePreference.localeOption}`)}` | ||
| : "Translate ethereum.org"} | ||
| </p> | ||
| ) : ( | ||
| <p className="overflow-hidden text-ellipsis whitespace-nowrap text-xs font-bold text-body"> | ||
| {t("page-languages-translate-cta-title")}{" "} | ||
| {t(`language-${locale}`)} | ||
| </p> | ||
| )} | ||
| <p className="text-xs text-body"> | ||
| {t("page-languages-recruit-community")} | ||
| </p> | ||
| </div> | ||
| <ButtonLink | ||
| className="text-nowrap" | ||
| href="/contributing/translation-program/" | ||
| size="sm" | ||
| onClick={onTranslationProgramClick} | ||
| > | ||
| {t("get-involved")} | ||
| </ButtonLink> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default LanguagePickerFooter |
This file contains hidden or 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,85 @@ | ||
| import type { LocaleDisplayInfo } from "@/lib/types" | ||
|
|
||
| import { | ||
| Command, | ||
| CommandEmpty, | ||
| CommandGroup, | ||
| CommandInput, | ||
| CommandList, | ||
| } from "../ui/command" | ||
|
|
||
| import MenuItem from "./MenuItem" | ||
| import NoResultsCallout from "./NoResultsCallout" | ||
|
|
||
| import { useTranslation } from "@/hooks/useTranslation" | ||
|
|
||
| type LanguagePickerMenuProps = { | ||
| className?: string | ||
| languages: LocaleDisplayInfo[] | ||
| onClose: () => void | ||
| onSelect: (value: string) => void | ||
| } | ||
|
|
||
| const LanguagePickerMenu = ({ | ||
| className, | ||
| languages, | ||
| onClose, | ||
| onSelect, | ||
| }: LanguagePickerMenuProps) => { | ||
| const { t } = useTranslation("common") | ||
|
|
||
| return ( | ||
| <Command | ||
| className={className} | ||
| filter={(value: string, search: string) => { | ||
| const item = languages.find((name) => name.localeOption === value) | ||
|
|
||
| if (!item) return 0 | ||
|
|
||
| const { localeOption, sourceName, targetName, englishName } = item | ||
|
|
||
| if ( | ||
| (localeOption + sourceName + targetName + englishName) | ||
| .toLowerCase() | ||
| .includes(search.toLowerCase()) | ||
| ) { | ||
| return 1 | ||
| } | ||
|
|
||
| return 0 | ||
| }} | ||
| > | ||
| <div className="text-xs text-body-medium"> | ||
| {t("page-languages-filter-label")}{" "} | ||
| <span className="lowercase"> | ||
| ({languages.length} {t("common:languages")}) | ||
| </span> | ||
| </div> | ||
|
|
||
| <CommandInput | ||
| placeholder={t("page-languages-filter-placeholder")} | ||
| className="h-9" | ||
| kbdShortcut="\" | ||
| data-testid="language-filter-input" | ||
| /> | ||
|
|
||
| <CommandList className="max-h-full"> | ||
| <CommandEmpty className="py-0 text-left text-base"> | ||
| <NoResultsCallout onClose={onClose} /> | ||
| </CommandEmpty> | ||
| <CommandGroup className="p-0"> | ||
| {languages.map((displayInfo) => ( | ||
| <MenuItem | ||
| key={"item-" + displayInfo.localeOption} | ||
| displayInfo={displayInfo} | ||
| onSelect={onSelect} | ||
| data-testid={`language-option-${displayInfo.localeOption}`} | ||
| /> | ||
| ))} | ||
| </CommandGroup> | ||
| </CommandList> | ||
| </Command> | ||
| ) | ||
| } | ||
|
|
||
| export default LanguagePickerMenu |
This file contains hidden or 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
Oops, something went wrong.
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.
Shouldn't block, but perhaps we rename this to
loadingfor consistency with other loading components?Uh oh!
There was an error while loading. Please reload this page.
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.
Hmm, but the intention of
fallbackis that it can be anything (includingnull). On the other hand,loadingnarrows the scope, leading developers to think they should only use loading UIs, which isn’t correct.