-
Notifications
You must be signed in to change notification settings - Fork 0
feature: Top Categories #2
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||
| import { fetcher } from '@/lib/coingecko.actions'; | ||||||
| import DataTable from '../DataTable'; | ||||||
| import { CategoriesFallback } from './fallback'; | ||||||
| import Image from 'next/image'; | ||||||
| import { cn, formatCurrency, formatPercentage } from '@/lib/utils'; | ||||||
| import { TrendingDown, TrendingUp } from 'lucide-react'; | ||||||
|
|
||||||
| const columns: DataTableColumn<Category>[] = [ | ||||||
| { | ||||||
| header: 'Name', | ||||||
| cellClassName: 'category-cell', | ||||||
| cell: (category) => category.name, | ||||||
| }, | ||||||
| { | ||||||
| header: 'Top Gainers', | ||||||
| cellClassName: 'top-gainers-cell', | ||||||
| cell: (category) => { | ||||||
| return category.top_3_coins.map((coin, index) => ( | ||||||
| <Image | ||||||
| key={category.top_3_coins[index]} | ||||||
| src={coin} | ||||||
| alt={category.top_3_coins[index]} | ||||||
| width={24} | ||||||
| height={24} | ||||||
| /> | ||||||
| )); | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| header: '24h Change', | ||||||
| cellClassName: 'change-header-cell ', | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove trailing space from className. The string 🧹 Proposed fix- cellClassName: 'change-header-cell ',
+ cellClassName: 'change-header-cell',📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| cell: (category) => { | ||||||
| const isTrendingUp = category.market_cap_change_24h > 0; | ||||||
|
|
||||||
| return ( | ||||||
| <div | ||||||
| className={cn( | ||||||
| 'change-cell flex items-center gap-1', | ||||||
| isTrendingUp ? 'text-green-500' : 'text-red-500', | ||||||
| )} | ||||||
| > | ||||||
| {isTrendingUp ? ( | ||||||
| <TrendingUp width={16} height={16} /> | ||||||
| ) : ( | ||||||
| <TrendingDown width={16} height={16} /> | ||||||
| )} | ||||||
| <p>{formatPercentage(category.market_cap_change_24h)}</p> | ||||||
| </div> | ||||||
| ); | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| header: 'Market Cap', | ||||||
| cellClassName: 'market-cap-cell', | ||||||
| cell: (category) => formatCurrency(category.market_cap), | ||||||
| }, | ||||||
| { | ||||||
| header: '24h Volume', | ||||||
| cellClassName: 'volume-cell', | ||||||
| cell: (category) => formatCurrency(category.volume_24h), | ||||||
| }, | ||||||
| ]; | ||||||
| const TopCategories = async () => { | ||||||
| let topCategories; | ||||||
| try { | ||||||
| topCategories = await fetcher<Category[]>( | ||||||
| '/coins/categories', | ||||||
| undefined, | ||||||
| 300, | ||||||
| ); | ||||||
| } catch (error) { | ||||||
| console.error('Error fetching top categories:', error); | ||||||
| return <CategoriesFallback />; | ||||||
| } | ||||||
| return ( | ||||||
| <div id="categories" className="custom-scrollbar"> | ||||||
| <h4>Top Categories</h4> | ||||||
| <DataTable | ||||||
| data={topCategories.slice(0, 10)} | ||||||
| columns={columns} | ||||||
| rowKey={(category) => category.name} | ||||||
| tableClassName="mt-3" | ||||||
| /> | ||||||
| </div> | ||||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| export default TopCategories; | ||||||
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.
Fix Image key and improve alt text for accessibility.
Two issues with the Image rendering:
Key: Using the URL (
category.top_3_coins[index]) as the React key is fragile. If the same coin URL appears multiple times or positions change, React's reconciliation may behave unexpectedly.Alt text: The
altprop is set to the URL string, which provides no meaningful description for screen readers and violates accessibility best practices.♿ Proposed fix for key and alt attributes
📝 Committable suggestion
🤖 Prompt for AI Agents