-
Notifications
You must be signed in to change notification settings - Fork 184
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
15 changed files
with
266 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getCurrentUser } from '@/lib/session'; | ||
import { getUserImages } from '@/lib/store/image'; | ||
import { ImageList } from '@/components/dashboard/image-list'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
export default async function MyPages() { | ||
const user = await getCurrentUser(); | ||
if (!user) { | ||
redirect('/login'); | ||
} | ||
const images = await getUserImages(user.id); | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-between space-y-6"> | ||
<div className="flex items-center justify-between"> | ||
<h1 className="text-3xl font-bold">MemFree Image Gallery</h1> | ||
</div> | ||
<ImageList user={user} items={images} /> | ||
</div> | ||
); | ||
} |
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,53 @@ | ||
import { Separator } from '@/components/ui/separator'; | ||
import { redirect } from 'next/navigation'; | ||
import { getCurrentUser } from '@/lib/session'; | ||
import SiteHeader from '@/components/layout/site-header'; | ||
import { mainNavConfig } from '@/config'; | ||
import { DashBoardSidebarNav } from '@/components/dashboard/sidebar-nav'; | ||
|
||
const sidebarNavItems = [ | ||
{ | ||
title: 'Images', | ||
href: '/images', | ||
}, | ||
{ | ||
title: 'Settings', | ||
href: '/settings', | ||
}, | ||
{ | ||
title: 'AI Search', | ||
href: '/', | ||
is_target_blank: true, | ||
}, | ||
{ | ||
title: 'AI Image ', | ||
href: '/generate-image', | ||
is_target_blank: true, | ||
}, | ||
{ | ||
title: 'AI Page', | ||
href: 'https://pagegen.ai', | ||
is_target_blank: true, | ||
}, | ||
]; | ||
|
||
export default async function DashboardLayout({ children }: { children: React.ReactNode }) { | ||
const user = await getCurrentUser(); | ||
if (!user?.id) { | ||
redirect('/login'); | ||
} | ||
return ( | ||
<> | ||
<SiteHeader user={user} items={mainNavConfig.mainNav} /> | ||
<div className="container px-4 mx-auto max-w-8xl py-10"> | ||
<div className="space-y-6 md:flex md:space-y-0 md:space-x-6"> | ||
<aside className="md:w-1/6"> | ||
<DashBoardSidebarNav items={sidebarNavItems} /> | ||
</aside> | ||
<Separator orientation="vertical" className="hidden md:block" /> | ||
<div className="flex-1">{children}</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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
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,81 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Card } from '@/components/ui/card'; | ||
import { Fullscreen, Link as LinkIcon, Download, Loader2 } from 'lucide-react'; | ||
import { GenImage } from '@/lib/types'; | ||
import React from 'react'; | ||
import Link from 'next/link'; | ||
import useCopyToClipboard from '@/hooks/use-copy-clipboard'; | ||
import { useDownloadImage } from '@/hooks/use-download-image'; | ||
import { toast } from 'sonner'; | ||
|
||
const ImageCard = ({ item, isPriority }: { item: GenImage; isPriority: boolean }) => { | ||
const { copyToClipboard } = useCopyToClipboard(); | ||
const { downloadImage, isDownloading } = useDownloadImage(); | ||
|
||
const handleCopyToClipboard = async () => { | ||
await copyToClipboard(item.imageUrl); | ||
toast.success('Image url copied to clipboard'); | ||
}; | ||
|
||
return ( | ||
<Card className="group relative overflow-hidden rounded-xl border border-border/40 hover:border-primary/40 hover:shadow-xl transition-all duration-500 flex flex-col h-full bg-background/50 backdrop-blur-sm"> | ||
<div className="relative aspect-[16/9] overflow-hidden rounded-t-xl"> | ||
<Image | ||
src={item.imageUrl} | ||
alt={item.title} | ||
fill | ||
className="object-cover transform group-hover:scale-110 transition-transform duration-700 ease-out" | ||
priority={isPriority} | ||
/> | ||
<div className="absolute inset-0 bg-gradient-to-t from-background/90 via-background/50 to-transparent opacity-40 group-hover:opacity-60 transition-opacity duration-500" /> | ||
</div> | ||
|
||
<div className="p-6 space-y-3 flex-1"> | ||
<div className="space-y-2"> | ||
<h3 className="font-semibold text-lg text-foreground group-hover:text-primary transition-colors duration-300">{item.title}</h3> | ||
<p className="text-sm text-muted-foreground/90 line-clamp-2 group-hover:text-muted-foreground transition-colors duration-300"> | ||
{item.prompt} | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div className="px-2 pb-4"> | ||
<div className="grid grid-cols-3 gap-1"> | ||
<Link href={item.imageUrl} target="_blank"> | ||
<Button variant="outline" size="icon" className="text-xs w-full"> | ||
<Fullscreen className="w-4 h-4 mr-1" /> | ||
Preview | ||
</Button> | ||
</Link> | ||
<Button variant="outline" className="text-xs" onClick={handleCopyToClipboard}> | ||
<LinkIcon className="w-4 h-4 mr-1" /> | ||
Copy | ||
</Button> | ||
<Button | ||
variant="outline" | ||
className="text-xs" | ||
onClick={() => downloadImage(item.imageUrl, `memfree-${item.title.substring(0, 50)}.png`)} | ||
disabled={isDownloading} | ||
> | ||
{isDownloading ? ( | ||
<> | ||
<Loader2 className="mr-1 h-4 w-4 animate-spin" /> | ||
Downloading... | ||
</> | ||
) : ( | ||
<> | ||
<Download className="w-4 h-4 mr-1" /> | ||
Download | ||
</> | ||
)} | ||
</Button> | ||
</div> | ||
</div> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default ImageCard; |
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,53 @@ | ||
'use client'; | ||
|
||
import { Loader2 } from 'lucide-react'; | ||
|
||
import { useState } from 'react'; | ||
import { GenImage } from '@/lib/types'; | ||
import React from 'react'; | ||
import { type User } from 'next-auth'; | ||
import { getUserImages } from '@/lib/store/image'; | ||
import InfiniteScroll from '@/components/ui/infinite-scroll'; | ||
import ImageCard from '@/components/dashboard/image-card'; | ||
|
||
const limit = 20; | ||
export const ImageList = ({ items, user }: { items: GenImage[]; user: User }) => { | ||
const [loading, setLoading] = useState(false); | ||
const [offset, setOffset] = useState(0); | ||
const [hasMore, setHasMore] = useState(true); | ||
|
||
const next = async () => { | ||
if (!user) { | ||
setHasMore(false); | ||
return; | ||
} | ||
setLoading(true); | ||
const newSearches = await getUserImages(user.id, offset); | ||
if (newSearches.length < limit) { | ||
setHasMore(false); | ||
} | ||
setOffset((prev) => prev + limit); | ||
setLoading(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> | ||
{items?.length > 0 ? ( | ||
items.map((item, index) => <ImageCard key={item.id} item={item} isPriority={index <= 2} />) | ||
) : ( | ||
<div className="text-center py-8 text-gray-500">No items in this category</div> | ||
)} | ||
</div> | ||
|
||
<InfiniteScroll hasMore={hasMore} isLoading={loading} next={next} threshold={1}> | ||
{hasMore && ( | ||
<div className="flex justify-center my-4"> | ||
<Loader2 className="size-6 text-primary animate-spin mr-2" /> | ||
<span>Loading More</span> | ||
</div> | ||
)} | ||
</InfiniteScroll> | ||
</> | ||
); | ||
}; |
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,38 @@ | ||
'use client'; | ||
|
||
import Link from 'next/link'; | ||
import { usePathname } from 'next/navigation'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
import { buttonVariants } from '@/components/ui/button'; | ||
|
||
interface SidebarNavProps extends React.HTMLAttributes<HTMLElement> { | ||
items: { | ||
href: string; | ||
title: string; | ||
is_target_blank?: boolean; | ||
}[]; | ||
} | ||
|
||
export function DashBoardSidebarNav({ className, items, ...props }: SidebarNavProps) { | ||
const pathname = usePathname(); | ||
|
||
return ( | ||
<nav className={cn('flex space-x-2 md:flex-col md:space-x-0 md:space-y-1', className)} {...props}> | ||
{items.map((item) => ( | ||
<Link | ||
key={item.href} | ||
href={item.href} | ||
target={item.is_target_blank ? '_blank' : undefined} | ||
className={cn( | ||
buttonVariants({ variant: 'ghost' }), | ||
pathname === item.href ? 'bg-muted hover:bg-muted' : 'hover:bg-transparent hover:underline', | ||
'justify-start', | ||
)} | ||
> | ||
{item.title} | ||
</Link> | ||
))} | ||
</nav> | ||
); | ||
} |
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