-
Notifications
You must be signed in to change notification settings - Fork 4
Add hover cards for apps, tags, and alerts #354
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6421e9f
chore(ui): add shadcn hover-card
Enigmatrix 1624a8a
feat(ui): add app, tag, alert hover cards
Enigmatrix 3129234
feat(ui): add hover cards to relevant elements
Enigmatrix 61aa772
fix(ui): app hover card getting cut off inside choose-multi-apps.tsx
Enigmatrix d585c7c
fix(ui): spread extra props to app iconand text
Enigmatrix 49254a0
feat(ui): create tag icon component so that extra props can be passed…
Enigmatrix 2b485de
feat(ui): move app horizontal list overflow into its own component
Enigmatrix 5d43b56
fix(ui): don't show double hover cards
Enigmatrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,162 @@ | ||
| import { StatusBadge } from "@/components/alert/status-badge"; | ||
| import { TriggerActionIndicator } from "@/components/alert/trigger-action"; | ||
| import AppIcon from "@/components/app/app-icon"; | ||
| import TagIcon from "@/components/tag/tag-icon"; | ||
| import { DurationText } from "@/components/time/duration-text"; | ||
| import { | ||
| HoverCard, | ||
| HoverCardContent, | ||
| HoverCardTrigger, | ||
| } from "@/components/ui/hover-card"; | ||
| import { Progress } from "@/components/ui/progress"; | ||
| import { Separator } from "@/components/ui/separator"; | ||
| import { Text } from "@/components/ui/text"; | ||
| import { useApp, useTag } from "@/hooks/use-refresh"; | ||
| import type { Alert } from "@/lib/entities"; | ||
| import { timeFrameToLabel } from "@/lib/entities"; | ||
| import { ArrowRightIcon, ClockAlertIcon } from "lucide-react"; | ||
| import { useMemo, type ReactNode } from "react"; | ||
| import { NavLink } from "react-router"; | ||
|
|
||
| export function AlertHoverCard({ | ||
| alert, | ||
| children, | ||
| }: { | ||
| alert: Alert; | ||
| children: ReactNode; | ||
| }) { | ||
| return ( | ||
| <HoverCard> | ||
| <HoverCardTrigger asChild>{children}</HoverCardTrigger> | ||
| <HoverCardContent side="bottom" align="start" className="w-80"> | ||
| <AlertHoverCardContent alert={alert} /> | ||
| </HoverCardContent> | ||
| </HoverCard> | ||
| ); | ||
| } | ||
|
|
||
| function AlertHoverCardContent({ alert }: { alert: Alert }) { | ||
| const app = useApp(alert.target.tag === "app" ? alert.target.id : null); | ||
| const tag = useTag(alert.target.tag === "tag" ? alert.target.id : null); | ||
| const targetEntity = app ?? tag; | ||
|
|
||
| const currentUsage = useMemo(() => { | ||
| const usages = alert.target.tag === "app" ? app?.usages : tag?.usages; | ||
| if (!usages) return 0; | ||
| switch (alert.timeFrame) { | ||
| case "daily": | ||
| return usages.today; | ||
| case "weekly": | ||
| return usages.week; | ||
| case "monthly": | ||
| return usages.month; | ||
| } | ||
| }, [alert, app, tag]); | ||
|
|
||
| const progress = Math.min( | ||
| (currentUsage / (alert.usageLimit || 1)) * 100, | ||
| 100, | ||
| ); | ||
|
|
||
| const targetLink = app ? `/apps/${app.id}` : tag ? `/tags/${tag.id}` : "#"; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-3"> | ||
| <div className="flex items-center gap-3"> | ||
| {app ? ( | ||
| <AppIcon app={app} className="w-10 h-10 shrink-0" /> | ||
| ) : tag ? ( | ||
| <TagIcon tag={tag} className="w-10 h-10 shrink-0" /> | ||
| ) : null} | ||
| <div className="flex flex-col min-w-0 gap-1"> | ||
| <NavLink | ||
| to={targetLink} | ||
| className="hover:underline" | ||
| onClick={(e) => e.stopPropagation()} | ||
| > | ||
| <Text className="font-semibold"> | ||
| {targetEntity?.name ?? "Unknown"} | ||
| </Text> | ||
| </NavLink> | ||
| <div className="flex items-center gap-2"> | ||
| <StatusBadge status={alert.status} className="text-xs h-5" /> | ||
| <TriggerActionIndicator | ||
| action={alert.triggerAction} | ||
| className="text-xs" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="space-y-1.5"> | ||
| <div className="flex items-center justify-between text-sm"> | ||
| <div className="flex items-center gap-1.5"> | ||
| <DurationText ticks={currentUsage} className="font-medium" /> | ||
| <span className="text-muted-foreground"> | ||
| ({Math.round(progress)}%) | ||
| </span> | ||
| </div> | ||
| <div className="flex items-center gap-1 text-muted-foreground text-xs"> | ||
| <DurationText ticks={alert.usageLimit} /> | ||
| <span>/</span> | ||
| <span>{timeFrameToLabel(alert.timeFrame)}</span> | ||
| </div> | ||
| </div> | ||
| <Progress value={progress} className="h-1.5 rounded-sm" /> | ||
| </div> | ||
|
|
||
| {alert.reminders.length > 0 && ( | ||
| <> | ||
| <Separator /> | ||
| <div className="flex items-center gap-2 text-sm text-muted-foreground"> | ||
| <ClockAlertIcon className="size-3.5" /> | ||
| <span> | ||
| {alert.reminders.length} Reminder | ||
| {alert.reminders.length !== 1 ? "s" : ""} | ||
| </span> | ||
| </div> | ||
| </> | ||
| )} | ||
|
|
||
| {targetEntity && ( | ||
| <> | ||
| <Separator /> | ||
| <div className="grid grid-cols-3 gap-2 text-center"> | ||
| <div> | ||
| <div className="text-xs text-muted-foreground">Today</div> | ||
| <DurationText | ||
| ticks={targetEntity.usages.today} | ||
| className="text-sm font-medium" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <div className="text-xs text-muted-foreground">Week</div> | ||
| <DurationText | ||
| ticks={targetEntity.usages.week} | ||
| className="text-sm font-medium" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <div className="text-xs text-muted-foreground">Month</div> | ||
| <DurationText | ||
| ticks={targetEntity.usages.month} | ||
| className="text-sm font-medium" | ||
| /> | ||
| </div> | ||
| </div> | ||
| </> | ||
| )} | ||
|
|
||
| <Separator /> | ||
|
|
||
| <NavLink | ||
| to={`/alerts/${alert.id}`} | ||
| className="text-sm text-primary hover:underline inline-flex items-center gap-1 self-start" | ||
| onClick={(e) => e.stopPropagation()} | ||
| > | ||
| View Details | ||
| <ArrowRightIcon className="size-3" /> | ||
| </NavLink> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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,138 @@ | ||
| import AppIcon from "@/components/app/app-icon"; | ||
| import { ScoreCircle } from "@/components/tag/score"; | ||
| import TagIcon from "@/components/tag/tag-icon"; | ||
| import { DurationText } from "@/components/time/duration-text"; | ||
| import { Badge } from "@/components/ui/badge"; | ||
| import { | ||
| HoverCard, | ||
| HoverCardContent, | ||
| HoverCardTrigger, | ||
| } from "@/components/ui/hover-card"; | ||
| import { Separator } from "@/components/ui/separator"; | ||
| import { Text } from "@/components/ui/text"; | ||
| import { useTag } from "@/hooks/use-refresh"; | ||
| import type { App } from "@/lib/entities"; | ||
| import { ArrowRightIcon } from "lucide-react"; | ||
| import type { ReactNode } from "react"; | ||
| import { NavLink } from "react-router"; | ||
|
|
||
| export function AppHoverCard({ | ||
| app, | ||
| children, | ||
| }: { | ||
| app: App; | ||
| children: ReactNode; | ||
| }) { | ||
| return ( | ||
| <HoverCard> | ||
| <HoverCardTrigger asChild>{children}</HoverCardTrigger> | ||
| <HoverCardContent side="bottom" align="start" className="w-80"> | ||
| <AppHoverCardContent app={app} /> | ||
| </HoverCardContent> | ||
| </HoverCard> | ||
| ); | ||
| } | ||
|
|
||
| function AppHoverCardContent({ app }: { app: App }) { | ||
| const tag = useTag(app.tagId); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-3"> | ||
| <div className="flex items-center gap-3"> | ||
| <AppIcon app={app} className="w-10 h-10 shrink-0" /> | ||
| <div className="flex flex-col min-w-0 gap-1"> | ||
| <Text className="font-semibold">{app.name}</Text> | ||
| {app.identity.tag !== "website" && app.company && ( | ||
| <Text className="text-sm text-muted-foreground">{app.company}</Text> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| {tag && ( | ||
| <NavLink | ||
| to={`/tags/${tag.id}`} | ||
| className="inline-flex self-start" | ||
| onClick={(e) => e.stopPropagation()} | ||
| > | ||
| <Badge | ||
| variant="outline" | ||
| style={{ | ||
| borderColor: tag.color, | ||
| color: tag.color, | ||
| backgroundColor: "rgba(255, 255, 255, 0.2)", | ||
| }} | ||
| className="whitespace-nowrap hover:opacity-80 transition-opacity" | ||
| > | ||
| <TagIcon tag={tag} className="size-3 mr-1" /> | ||
| <Text className="max-w-32">{tag.name}</Text> | ||
| <ScoreCircle score={tag.score} className="ml-1.5" /> | ||
| </Badge> | ||
| </NavLink> | ||
| )} | ||
|
|
||
| {app.description && ( | ||
| <Text className="text-sm text-muted-foreground line-clamp-2"> | ||
| {app.description} | ||
| </Text> | ||
| )} | ||
|
|
||
| <div className="text-xs inline-flex items-center border border-border rounded-md overflow-hidden bg-muted/30 self-start max-w-full"> | ||
| <div className="bg-muted px-2 py-1 border-r border-border font-medium shrink-0"> | ||
| {app.identity.tag === "uwp" | ||
| ? "UWP" | ||
| : app.identity.tag === "win32" | ||
| ? "Win32" | ||
| : app.identity.tag === "website" | ||
| ? "Web" | ||
| : "Squirrel"} | ||
| </div> | ||
| <Text className="font-mono px-2 py-1 text-muted-foreground"> | ||
| {app.identity.tag === "uwp" | ||
| ? app.identity.aumid | ||
| : app.identity.tag === "win32" | ||
| ? app.identity.path | ||
| : app.identity.tag === "website" | ||
| ? app.identity.baseUrl | ||
| : app.identity.identifier} | ||
| </Text> | ||
| </div> | ||
|
|
||
| <Separator /> | ||
|
|
||
| <div className="grid grid-cols-3 gap-2 text-center"> | ||
| <div> | ||
| <div className="text-xs text-muted-foreground">Today</div> | ||
| <DurationText | ||
| ticks={app.usages.today} | ||
| className="text-sm font-medium" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <div className="text-xs text-muted-foreground">Week</div> | ||
| <DurationText | ||
| ticks={app.usages.week} | ||
| className="text-sm font-medium" | ||
| /> | ||
| </div> | ||
| <div> | ||
| <div className="text-xs text-muted-foreground">Month</div> | ||
| <DurationText | ||
| ticks={app.usages.month} | ||
| className="text-sm font-medium" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <Separator /> | ||
|
|
||
| <NavLink | ||
| to={`/apps/${app.id}`} | ||
| className="text-sm text-primary hover:underline inline-flex items-center gap-1 self-start" | ||
| onClick={(e) => e.stopPropagation()} | ||
| > | ||
| View Details | ||
| <ArrowRightIcon className="size-3" /> | ||
| </NavLink> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.