Skip to content

Commit

Permalink
Make all tags clickable
Browse files Browse the repository at this point in the history
Whenever a tag is clicked, redirect the user to the dashboard and filter
by the tag.

Solves: #53
  • Loading branch information
AlexGustafsson committed Jan 12, 2025
1 parent 262f13b commit 1129c8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion web/components/ImageCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { JSX } from 'react'

import { NavLink } from 'react-router-dom'
import { TagsByName } from '../tags'
import { formatRelativeTimeTo } from '../time'
import { Badge } from './Badge'
Expand Down Expand Up @@ -80,7 +81,13 @@ export function ImageCard({
<p className="text-sm mt-2">{description}</p>
<div className="flex flex-wrap gap-2 mt-4">
{tags.map((x) => (
<Badge key={x} label={x} color={TagsByName[x]?.color} />
<NavLink key={x} to={`/?tag=${encodeURIComponent(x)}`}>
<Badge
label={x}
color={TagsByName[x]?.color}
className="hover:opacity-90"
/>
</NavLink>
))}
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions web/pages/ImagePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JSX, ReactNode } from 'react'
import { Navigate, useSearchParams } from 'react-router-dom'
import { Link, NavLink, Navigate, useSearchParams } from 'react-router-dom'

import {
type Graph,
Expand Down Expand Up @@ -222,7 +222,14 @@ export function ImagePage(): JSX.Element {
{/* Image tags */}
<div className="flex mt-4 items-center gap-x-2">
{imageTags.map((x) => (
<Badge key={x.name} label={x.name} color={x.color} />
<NavLink key={x.name} to={`/?tag=${encodeURIComponent(x.name)}`}>
<Badge
key={x.name}
label={x.name}
color={x.color}
className="hover:opacity-90"
/>
</NavLink>
))}
</div>
{/* Links */}
Expand Down

0 comments on commit 1129c8a

Please sign in to comment.