Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/platformFilter/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function PlatformFilterClient({platforms}: {platforms: Platform[]}) {
return matches_;
}, [filter, platformsAndGuides]);

const matchKeys = useMemo(() => {
return matches.map(x => x.key);
}, [matches]);

const platformColumns: Platform[][] = splitToChunks(
3,
uniqByReference(matches.map(x => (x.type === 'platform' ? x : x.platform))).map(p => {
Expand Down Expand Up @@ -161,6 +165,7 @@ export function PlatformFilterClient({platforms}: {platforms: Platform[]}) {
<PlatformWithGuides
key={platform.key}
platform={platform}
matchKeys={matchKeys}
// force expand if the filter is long enough to have few results
forceExpand={filter.length >= 2}
/>
Expand All @@ -180,11 +185,19 @@ export function PlatformFilterClient({platforms}: {platforms: Platform[]}) {
function PlatformWithGuides({
platform,
forceExpand,
matchKeys,
}: {
forceExpand: boolean;
matchKeys: string[];
platform: Platform;
}) {
const [expanded, setExpanded] = useState(false);

const guides = useMemo(() => {
const showPlatformInContent = !forceExpand || matchKeys.includes(platform.key);
return showPlatformInContent ? [platform, ...platform.guides] : platform.guides;
}, [forceExpand, matchKeys, platform]);

return (
<Collapsible.Root
className={styles.CollapsibleRoot}
Expand Down Expand Up @@ -217,7 +230,7 @@ function PlatformWithGuides({
// scrollable if there are more than 8 (arbitrary limit) guides
data-scrollable={platform.guides.length >= 8 || platform.integrations.length >= 8}
>
{[platform, ...platform.guides].map((guide, i) => (
{guides.map((guide, i) => (
<Link
href={guide.url}
style={{textDecoration: 'none', color: 'var(--foreground) !important'}}
Expand Down
Loading