Skip to content

Commit

Permalink
fix(vx-demo/gallery): clear package filter on click if already selected
Browse files Browse the repository at this point in the history
  • Loading branch information
williaster committed Aug 19, 2020
1 parent 92a1b2e commit 6d6117e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/vx-demo/src/components/Gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ const tiles = [

export default function Gallery() {
const router = useRouter();
const { pkg } = router.query;
const { pkg: routePackage } = router.query;

const filteredTiles = pkg
const filteredTiles = routePackage
? tiles.filter(Tile =>
exampleToVxDependencyLookup[Tile.packageJson.name]?.has(pkg as VxPackage),
exampleToVxDependencyLookup[Tile.packageJson.name]?.has(routePackage as VxPackage),
)
: tiles;

Expand All @@ -110,10 +110,16 @@ export default function Gallery() {
<div className="filters">
<h6>Examples by package</h6>
{vxPackages.map(vxPackage => (
<Link key={vxPackage} href={{ pathname: '/gallery', query: { pkg: vxPackage } }}>
<Link
key={vxPackage}
href={{
pathname: '/gallery',
query: routePackage === vxPackage ? undefined : { pkg: vxPackage },
}}
>
<a
className={cx('filter-button', {
emphasize: pkg === vxPackage,
emphasize: routePackage === vxPackage,
})}
>{`@vx/${vxPackage}`}</a>
</Link>
Expand Down

0 comments on commit 6d6117e

Please sign in to comment.