-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
517 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as React from "react" | ||
import { cva, type VariantProps } from "class-variance-authority" | ||
|
||
import { cn } from "~/utils/cn" | ||
|
||
const badgeVariants = cva( | ||
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", | ||
{ | ||
variants: { | ||
variant: { | ||
default: | ||
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80", | ||
secondary: | ||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
destructive: | ||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80", | ||
outline: "text-foreground", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
} | ||
) | ||
|
||
export interface BadgeProps | ||
extends React.HTMLAttributes<HTMLDivElement>, | ||
VariantProps<typeof badgeVariants> {} | ||
|
||
function Badge({ className, variant, ...props }: BadgeProps) { | ||
return ( | ||
<div className={cn(badgeVariants({ variant }), className)} {...props} /> | ||
) | ||
} | ||
|
||
export { Badge, badgeVariants } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as React from "react" | ||
import * as ProgressPrimitive from "@radix-ui/react-progress" | ||
|
||
import { cn } from "~/utils/cn" | ||
|
||
const Progress = React.forwardRef< | ||
React.ElementRef<typeof ProgressPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root> | ||
>(({ className, value, ...props }, ref) => ( | ||
<ProgressPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative h-2 w-full overflow-hidden rounded-full bg-primary/20", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<ProgressPrimitive.Indicator | ||
className="h-full w-full flex-1 bg-primary transition-all" | ||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }} | ||
/> | ||
</ProgressPrimitive.Root> | ||
)) | ||
Progress.displayName = ProgressPrimitive.Root.displayName | ||
|
||
export { Progress } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from "react" | ||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area" | ||
|
||
import { cn } from "~/utils/cn" | ||
|
||
const ScrollArea = React.forwardRef< | ||
React.ElementRef<typeof ScrollAreaPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> | ||
>(({ className, children, ...props }, ref) => ( | ||
<ScrollAreaPrimitive.Root | ||
ref={ref} | ||
className={cn("relative overflow-hidden", className)} | ||
{...props} | ||
> | ||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]"> | ||
{children} | ||
</ScrollAreaPrimitive.Viewport> | ||
<ScrollBar /> | ||
<ScrollAreaPrimitive.Corner /> | ||
</ScrollAreaPrimitive.Root> | ||
)) | ||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName | ||
|
||
const ScrollBar = React.forwardRef< | ||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>, | ||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar> | ||
>(({ className, orientation = "vertical", ...props }, ref) => ( | ||
<ScrollAreaPrimitive.ScrollAreaScrollbar | ||
ref={ref} | ||
orientation={orientation} | ||
className={cn( | ||
"flex touch-none select-none transition-colors", | ||
orientation === "vertical" && | ||
"h-full w-2.5 border-l border-l-transparent p-[1px]", | ||
orientation === "horizontal" && | ||
"h-2.5 flex-col border-t border-t-transparent p-[1px]", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" /> | ||
</ScrollAreaPrimitive.ScrollAreaScrollbar> | ||
)) | ||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName | ||
|
||
export { ScrollArea, ScrollBar } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; | ||
import { ScrollArea } from "~/components/ui/scroll-area"; | ||
import type { UserReadHistoryItem } from "../types"; | ||
import { Link } from "@remix-run/react"; | ||
import { Badge } from "~/components/ui/badge"; | ||
import { Progress } from "~/components/ui/progress"; | ||
|
||
type UserReadHistoryListProps = { | ||
userReadHistory: UserReadHistoryItem[]; | ||
targetLanguage: string; | ||
}; | ||
|
||
export function UserReadHistoryList({ userReadHistory, targetLanguage }: UserReadHistoryListProps) { | ||
return ( | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>Recently Read</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<ScrollArea className="h-[300px]"> | ||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4"> | ||
{userReadHistory.map((item) => { | ||
const translationInfo = item.pageVersion.pageVersionTranslationInfo[0]; | ||
return ( | ||
<Link | ||
key={item.id} | ||
to={`/reader/${encodeURIComponent(item.pageVersion.page.url)}`} | ||
className="no-underline text-inherit" | ||
> | ||
<Card className="flex flex-col hover:shadow-md transition-shadow duration-200"> | ||
<CardHeader> | ||
<CardTitle className="text-sm truncate">{item.pageVersion.title}</CardTitle> | ||
</CardHeader> | ||
<CardContent className="flex-grow"> | ||
<p className="text-xs text-muted-foreground truncate"> | ||
{item.pageVersion.page.url} | ||
</p> | ||
<p className="text-xs mt-2"> | ||
{new Date(item.readAt).toLocaleDateString()} | ||
</p> | ||
{translationInfo && ( | ||
<> | ||
<Badge className="mt-2" variant={getVariantForStatus(translationInfo.translationStatus)}> | ||
{translationInfo.translationStatus} | ||
</Badge> | ||
<Progress value={translationInfo.translationProgress} className="mt-2" /> | ||
</> | ||
)} | ||
{!translationInfo && ( | ||
<Badge className="mt-2" variant="outline"> | ||
Not started | ||
</Badge> | ||
)} | ||
</CardContent> | ||
</Card> | ||
</Link> | ||
); | ||
})} | ||
</div> | ||
</ScrollArea> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
function getVariantForStatus(status: string): "default" | "secondary" | "destructive" | "outline" { | ||
switch (status) { | ||
case "completed": | ||
return "default"; | ||
case "processing": | ||
return "secondary"; | ||
case "failed": | ||
return "destructive"; | ||
default: | ||
return "outline"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.