Skip to content

Commit

Permalink
feat: Add tooltip functionality to album artwork and
Browse files Browse the repository at this point in the history
preview modal components
  • Loading branch information
hqwuzhaoyi committed Nov 19, 2023
1 parent 04be5eb commit 4e89d57
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 1 deletion.
31 changes: 30 additions & 1 deletion apps/web/app/preview/gallery/components/album-artwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import { toast } from "@/components/ui/use-toast";
import { Terminal } from "@/components/Terminal";
import { useSWRConfig } from "swr";
import { PaginationState } from "@tanstack/react-table";
import { PreviewModal } from "./preview-modal";

import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "components/ui/tooltip";

interface AlbumArtworkProps extends React.HTMLAttributes<HTMLDivElement> {
album: Album;
Expand Down Expand Up @@ -70,7 +78,16 @@ export function AlbumArtwork({
)}
<div className="absolute right-1 top-1 flex gap-2">
{album.path && (
<CheckCircle2 className=" opacity-80 rounded-full shadow-md text-green-600"></CheckCircle2>
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<CheckCircle2 className=" opacity-80 rounded-full shadow-md text-green-600"></CheckCircle2>
</TooltipTrigger>
<TooltipContent>
<p>Status: Finished</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
{album.processingJobId && (
<HoverCard>
Expand All @@ -83,6 +100,18 @@ export function AlbumArtwork({
</HoverCard>
)}
</div>
<div className="absolute right-1 bottom-1 flex gap-2">
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
<PreviewModal />
</TooltipTrigger>
<TooltipContent>
<p>Preview Information</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
</div>
</ContextMenuTrigger>
<ContextMenuContent className="w-40">
Expand Down
90 changes: 90 additions & 0 deletions apps/web/app/preview/gallery/components/preview-modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Button } from "components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "components/ui/dialog";
import { ChevronDownCircle } from "lucide-react";

export function PreviewModal() {
return (
<Dialog open={false}>
<DialogTrigger asChild>
<ChevronDownCircle className="opacity-80 rounded-full shadow-md text-gray-400 cursor-not-allowed" />
</DialogTrigger>
<DialogContent className="sm:max-w-[625px]">
<DialogHeader>
<DialogTitle>View code</DialogTitle>
<DialogDescription>
You can use the following code to start integrating your current
prompt and settings into your application.
</DialogDescription>
</DialogHeader>
<div className="grid gap-4">
<div className="rounded-md bg-black p-6">
<pre>
<code className="grid gap-1 text-sm text-muted-foreground [&_span]:h-4">
<span>
<span className="text-sky-300">import</span> os
</span>
<span>
<span className="text-sky-300">import</span> openai
</span>
<span />
<span>
openai.api_key = os.getenv(
<span className="text-green-300">
&quot;OPENAI_API_KEY&quot;
</span>
)
</span>
<span />
<span>response = openai.Completion.create(</span>
<span>
{" "}
model=
<span className="text-green-300">&quot;davinci&quot;</span>,
</span>
<span>
{" "}
prompt=<span className="text-amber-300">&quot;&quot;</span>,
</span>
<span>
{" "}
temperature=<span className="text-amber-300">0.9</span>,
</span>
<span>
{" "}
max_tokens=<span className="text-amber-300">5</span>,
</span>
<span>
{" "}
top_p=<span className="text-amber-300">1</span>,
</span>
<span>
{" "}
frequency_penalty=<span className="text-amber-300">0</span>,
</span>
<span>
{" "}
presence_penalty=<span className="text-green-300">0</span>,
</span>
<span>)</span>
</code>
</pre>
</div>
<div>
<p className="text-sm text-muted-foreground">
Your API Key can be found here. You should use environment
variables or a secret management tool to expose your key to your
applications.
</p>
</div>
</div>
</DialogContent>
</Dialog>
);
}
30 changes: 30 additions & 0 deletions apps/web/components/ui/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client"

import * as React from "react"
import * as TooltipPrimitive from "@radix-ui/react-tooltip"

import { cn } from "@/lib/utils"

const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"@tanstack/react-table": "^8.10.7",
"@types/node": "20.9.0",
"@types/ramda": "^0.29.7",
Expand Down

0 comments on commit 4e89d57

Please sign in to comment.