From 54531a8df7d0b5d0db0683082e37db4d15ae96c7 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Sun, 22 Nov 2026 13:55:26 +0900 Subject: [PATCH 1/9] feat(maintainers): move the globe to the homepage --- src/components/MaintainersFilter.tsx | 317 +++++++++++++++++ src/components/MaintainersMap.tsx | 67 ++-- src/components/home/HomeCommunitySection.tsx | 106 +++--- src/components/home/HomeSectionFallbacks.tsx | 18 - src/libraries/maintainers.ts | 14 + src/routes/maintainers.tsx | 347 +------------------ 6 files changed, 430 insertions(+), 439 deletions(-) create mode 100644 src/components/MaintainersFilter.tsx diff --git a/src/components/MaintainersFilter.tsx b/src/components/MaintainersFilter.tsx new file mode 100644 index 000000000..f0df1deec --- /dev/null +++ b/src/components/MaintainersFilter.tsx @@ -0,0 +1,317 @@ +import { useEffect, useId, useRef, useState } from 'react' +import { + FunnelIcon, + GridFourIcon, + GridNineIcon, + RowsIcon, + XIcon, +} from '@phosphor-icons/react' +import * as v from 'valibot' +import { libraries } from '~/libraries' +import type { LibraryId } from '~/libraries/types' + +export const viewModeSchema = v.picklist(['compact', 'full', 'row']) +export const groupBySchema = v.picklist(['none', 'core', 'library', 'role']) +export const sortBySchema = v.picklist([ + 'none', + 'name', + 'role', + 'contributions', +]) + +const availableLibraries = libraries.filter((lib) => lib.visible !== false) + +interface FilterProps { + selectedLibraries: LibraryId[] | undefined + onLibrariesChange: (libraries: LibraryId[] | undefined) => void + onClearAll: () => void + directory?: { + viewMode: v.InferOutput + groupBy: v.InferOutput + sortBy: v.InferOutput + onViewModeChange: (mode: v.InferOutput) => void + onGroupByChange: (groupBy: v.InferOutput) => void + onSortByChange: (sortBy: v.InferOutput) => void + } +} + +export function MaintainersFilter({ + selectedLibraries, + onLibrariesChange, + onClearAll, + directory, +}: FilterProps) { + const [isOpen, setIsOpen] = useState(false) + const dropdown = useRef(null) + const trigger = useRef(null) + const panelId = useId() + + const toggleLibrary = (libraryId: LibraryId) => { + if (!selectedLibraries) { + onLibrariesChange([libraryId]) + return + } + + if (selectedLibraries.includes(libraryId)) { + const newLibraries = selectedLibraries.filter((id) => id !== libraryId) + onLibrariesChange(newLibraries.length > 0 ? newLibraries : undefined) + } else { + onLibrariesChange([...selectedLibraries, libraryId]) + } + } + + const clearFilters = () => { + onClearAll() + setIsOpen(false) + trigger.current?.focus() + } + + useEffect(() => { + if (!isOpen) return + + const handleClickOutside = (event: MouseEvent) => { + if ( + event.target instanceof Node && + !dropdown.current?.contains(event.target) + ) { + setIsOpen(false) + } + } + const handleEscape = (event: KeyboardEvent) => { + if (event.key === 'Escape') { + setIsOpen(false) + trigger.current?.focus() + } + } + + document.addEventListener('click', handleClickOutside) + document.addEventListener('keydown', handleEscape) + return () => { + document.removeEventListener('click', handleClickOutside) + document.removeEventListener('keydown', handleEscape) + } + }, [isOpen]) + + const filterCount = + (selectedLibraries?.length ?? 0) + + (directory && directory.groupBy !== 'none' ? 1 : 0) + + (directory && directory.sortBy !== 'none' ? 1 : 0) + const label = directory ? 'Filter & Sort' : 'Filter by Library' + + return ( +
+
+ {directory && ( +
+ {( + [ + { + mode: 'compact', + Icon: GridNineIcon, + title: 'Compact cards', + rounded: 'rounded-l-lg', + }, + { + mode: 'full', + Icon: GridFourIcon, + title: 'Full cards', + rounded: '', + }, + { + mode: 'row', + Icon: RowsIcon, + title: 'Row cards', + rounded: 'rounded-r-lg', + }, + ] as const + ).map(({ mode, Icon, title, rounded }) => ( + + ))} +
+ )} +
+ + + {/* Dropdown menu */} + {isOpen && ( +
+
+
+ + {directory ? 'Filter & Sort Options' : 'Libraries'} + + {filterCount > 0 && ( + + )} +
+ + {directory && ( + <> +
+ + +
+ + {/* Sort By */} +
+ + +
+ + )} +
+ {directory && ( +

+ Filter by Libraries +

+ )} +
+ {availableLibraries.map((library) => { + const isSelected = + selectedLibraries?.includes(library.id) || false + + const bgStyle = library.bgStyle ?? 'bg-category-tooling' + + return ( + + ) + })} +
+
+
+
+ )} +
+ + {/* Current filter chips */} +
+ {selectedLibraries?.map((libraryId) => { + const library = availableLibraries.find( + (lib) => lib.id === libraryId, + ) + const bgStyle = library?.bgStyle ?? 'bg-category-tooling' + + return ( + + {library?.name || libraryId} + + + ) + })} +
+
+
+ ) +} diff --git a/src/components/MaintainersMap.tsx b/src/components/MaintainersMap.tsx index 4cbf2fcb7..9da0d382c 100644 --- a/src/components/MaintainersMap.tsx +++ b/src/components/MaintainersMap.tsx @@ -8,6 +8,7 @@ import { useState, } from 'react' import { ClientOnly } from '@tanstack/react-router' +import { useSuspenseQuery } from '@tanstack/react-query' import { geoDistance, select, zoom, zoomIdentity, type D3ZoomEvent } from 'd3' import { ArrowCounterClockwiseIcon, @@ -22,7 +23,8 @@ import type { LibraryId } from '~/libraries/types' import { categoryOf } from '~/libraries/categories' import { Tooltip } from '~/ui/Tooltip' import { MaintainerAvatarImage } from './MaintainerAvatarImage' -import { createChartsGlobe, globeHaloScale } from './maintainersChartsGlobe' +import { getVisitorLocation } from '~/utils/visitor-location.functions' +import { createChartsGlobe } from './maintainersChartsGlobe' import { initialMaintainersView, initialView } from './maintainersGlobeView' const zoomStep = 1.5 @@ -30,8 +32,6 @@ const maxZoom = 128 const mobileInitialScale = zoomStep const desktopInitialScale = initialView.scale * zoomStep const mobileViewport = '(max-width: 639px)' -const mobileTopInset = 8 -const mobileCornerBleed = 6 const mobileZoomFade = 48 // Allow for rounding in rAF timestamps at 60 Hz and cap redraws on faster displays. const frameInterval = 1000 / 60 - 1 @@ -647,7 +647,6 @@ function placeProfiles( type MaintainersMapProps = { maintainers: Maintainer[] selectedLibraries?: LibraryId[] - initialLocation: Parameters[0] } function Key({ children }: { children: React.ReactNode }) { @@ -687,8 +686,12 @@ function GlobeAvatar({ export function MaintainersMap({ maintainers, selectedLibraries, - initialLocation, }: MaintainersMapProps) { + const { data: initialLocation } = useSuspenseQuery({ + queryKey: ['maintainers-globe', 'visitor-location'], + queryFn: () => getVisitorLocation().catch(() => null), + staleTime: Infinity, + }) const prefix = useId().replace(/[^a-zA-Z0-9_-]/g, '') const [host, setHost] = useState((): HTMLDivElement | null => null) const [surface, setSurface] = useState((): HTMLDivElement | null => null) @@ -783,54 +786,27 @@ export function MaintainersMap({ useLayoutEffect(() => { if (!host || !surface) return const mobile = window.matchMedia(mobileViewport) - let landingWidth = 0 - let landingHeight = 0 const readBounds = () => { const width = host.clientWidth const contentWidth = host.parentElement?.clientWidth ?? width const paintWidth = surface.clientWidth - let height = host.clientHeight - let centerY = height / 2 - let mobilePaintTop = 0 - let projectionHeight = Math.min( + const height = host.clientHeight + const initialScale = mobile.matches + ? mobileInitialScale + : desktopInitialScale + const projectionHeight = Math.min( height, - paintWidth / (desktopInitialScale * globeGlowDiameter), + paintWidth / (initialScale * globeGlowDiameter), ) - if (mobile.matches) { - if (paintWidth !== landingWidth || window.scrollY === 0) { - landingWidth = paintWidth - landingHeight = - window.visualViewport?.height ?? - document.documentElement.clientHeight - } - const pageTop = host.getBoundingClientRect().top + window.scrollY - mobilePaintTop = -Math.ceil(Math.max(0, pageTop)) - host.style.setProperty('--globe-paint-top', `${mobilePaintTop}px`) - const halfWidth = paintWidth / 2 + mobileCornerBleed - // Fill the first viewport's corners, then reserve room for the entire globe. - const bottomDepth = Math.max( - halfWidth, - landingHeight - pageTop - mobileTopInset, - ) - const radius = (bottomDepth ** 2 + halfWidth ** 2) / (2 * bottomDepth) - projectionHeight = radius / (mobileInitialScale * globeRadius) - centerY = mobileTopInset + radius - const globeHeight = Math.ceil( - centerY + radius * globeHaloScale + mobileTopInset, - ) - if (height !== globeHeight) - host.style.setProperty('--globe-mobile-height', `${globeHeight}px`) - height = globeHeight - } const paintHeight = surface.clientHeight return { width, height, - centerY, + centerY: height / 2, contentInset: (width - contentWidth) / 2, paintWidth, paintHeight, - paintTop: mobile.matches ? mobilePaintTop : (height - paintHeight) / 2, + paintTop: (height - paintHeight) / 2, projectionHeight, } } @@ -1106,7 +1082,6 @@ export function MaintainersMap({ ? Number(entered || reducedMotion) : Math.min(1, (now - entranceStart) / entranceDuration) const remaining = (1 - progress) ** 4 - // Keep the mobile corners covered even at the start of the entrance. const startScale = mobile.matches ? mobileEntranceScale : entranceScale @@ -1283,8 +1258,6 @@ export function MaintainersMap({ } @media ${mobileViewport} { [data-globe-surface] { - top: var(--globe-paint-top, 0px); - height: calc(100% - var(--globe-paint-top, 0px)); mask-image: linear-gradient( to bottom, @@ -1319,7 +1292,7 @@ export function MaintainersMap({ to { opacity: 1; } } `} -
+
-
+
- Drag to rotate, pinch to zoom. Tap a profile to see nearby + Drag sideways to rotate, pinch to zoom. Tap a profile to see nearby maintainers.

diff --git a/src/components/home/HomeCommunitySection.tsx b/src/components/home/HomeCommunitySection.tsx index 16d7589c7..847464332 100644 --- a/src/components/home/HomeCommunitySection.tsx +++ b/src/components/home/HomeCommunitySection.tsx @@ -1,69 +1,85 @@ -import { Link } from '@tanstack/react-router' +import { lazy, Suspense, useState } from 'react' +import { ClientOnly, createLink } from '@tanstack/react-router' import { Hydrate } from '@tanstack/react-start' import { visible } from '@tanstack/react-start/hydration' import { ArrowRightIcon } from '@phosphor-icons/react' -import { MaintainerCard } from '~/components/MaintainerCard' -import { coreMaintainers } from '~/libraries/maintainers' +import { MaintainersFilter } from '~/components/MaintainersFilter' import { Button } from '~/components/ds/ui' +import { getMaintainersForLibraries } from '~/libraries/maintainers' +import type { LibraryId } from '~/libraries/types' + +const ButtonLink = createLink(Button) + +const MaintainersMap = lazy(() => + import('~/components/MaintainersMap').then((module) => ({ + default: module.MaintainersMap, + })), +) + +const globeFallback = ( +