Skip to content

Commit

Permalink
use linkify to automatically convert links to href (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dohsimpson authored Jan 4, 2025
1 parent 140bb9b commit a4af30b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 226 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 0.1.6

### Added

- make links clickable in habit, wishlist and calendar

## Version 0.1.5

### Added
Expand Down
11 changes: 9 additions & 2 deletions components/DailyOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Badge } from '@/components/ui/badge'
import { Progress } from '@/components/ui/progress'
import { WishlistItemType } from '@/lib/types'
import { Habit } from '@/lib/types'
import Linkify from './linkify'

interface UpcomingItemsProps {
habits: Habit[]
Expand Down Expand Up @@ -91,7 +92,9 @@ export default function DailyOverview({
)}
</button>
<span className={isCompleted ? 'line-through' : ''}>
{habit.name}
<Linkify>
{habit.name}
</Linkify>
</span>
</span>
<span className="flex items-center text-xs text-muted-foreground">
Expand Down Expand Up @@ -144,7 +147,11 @@ export default function DailyOverview({
.map((item) => (
<div key={item.id} className="bg-secondary/20 p-3 rounded-md">
<div className="flex items-center justify-between mb-2">
<span className="text-sm">{item.name}</span>
<span className="text-sm">
<Linkify>
{item.name}
</Linkify>
</span>
<span className="text-xs flex items-center">
<Coins className="h-3 w-3 text-yellow-400 mr-1" />
{item.coinCost}
Expand Down
5 changes: 4 additions & 1 deletion components/HabitCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { d2s, getNow } from '@/lib/utils'
import { useAtom } from 'jotai'
import { settingsAtom } from '@/lib/atoms'
import { DateTime } from 'luxon'
import Linkify from './linkify'

export default function HabitCalendar() {
const [settings] = useAtom(settingsAtom)
Expand Down Expand Up @@ -73,7 +74,9 @@ export default function HabitCalendar() {
const isCompleted = getHabitsForDate(selectedDate.toJSDate()).some(h => h.id === habit.id)
return (
<li key={habit.id} className="flex items-center justify-between">
<span>{habit.name}</span>
<span>
<Linkify>{habit.name}</Linkify>
</span>
{isCompleted ? (
<Badge variant="default">Completed</Badge>
) : (
Expand Down
1 change: 1 addition & 0 deletions components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Header from './Header'
import LinkifyComponent from './linkify'
import Navigation from './Navigation'

export default function Layout({ children }: { children: React.ReactNode }) {
Expand Down
40 changes: 0 additions & 40 deletions components/RewardProgress.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions components/linkify.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Linkify0 from "linkify-react";

export default function Linkify({ children }: { children: React.ReactNode }) {
return <Linkify0 options={{ className: "underline" }}>{children}</Linkify0>;
}
25 changes: 15 additions & 10 deletions components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from "react"

import { cn } from "@/lib/utils"
import Linkify from "../linkify"

const Card = React.forwardRef<
HTMLDivElement,
Expand Down Expand Up @@ -33,23 +34,27 @@ const CardTitle = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("font-semibold leading-none tracking-tight", className)}
{...props}
/>
<Linkify>
<div
ref={ref}
className={cn("font-semibold leading-none tracking-tight", className)}
{...props}
/>
</Linkify>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
<Linkify>
<div
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
</Linkify>
))
CardDescription.displayName = "CardDescription"

Expand Down
Loading

0 comments on commit a4af30b

Please sign in to comment.