Skip to content

Commit 81bb46a

Browse files
committed
feat(ui): add ShareButton component for sharing functionality and update InfiniteList pageSize to 48
1 parent b854728 commit 81bb46a

File tree

6 files changed

+80
-27
lines changed

6 files changed

+80
-27
lines changed

src/components/auth/user-profile.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"use client";
22

3-
import type { User } from "@supabase/supabase-js";
4-
53
import { useEffect, useState } from "react";
64
import { useRouter } from "next/navigation";
75
import {
@@ -13,7 +11,9 @@ import {
1311
DropdownTrigger,
1412
Skeleton,
1513
} from "@heroui/react";
14+
import { Layers3, LayoutDashboard, LogOut } from "lucide-react";
1615
import { createClient } from "@/lib/supabase/client";
16+
import type { User } from "@supabase/supabase-js";
1717

1818
export default function UserProfile() {
1919
const router = useRouter();
@@ -108,6 +108,7 @@ export default function UserProfile() {
108108
key="admin-dashboard"
109109
textValue="Dashboard"
110110
onPress={() => router.push("/dashboard")}
111+
startContent={<LayoutDashboard size={16} />}
111112
>
112113
Dashboard
113114
</DropdownItem>
@@ -116,10 +117,16 @@ export default function UserProfile() {
116117
key="my-resources"
117118
textValue="My Resources"
118119
onPress={() => router.push("/my-resources")}
120+
startContent={<Layers3 size={16} />}
119121
>
120122
My Resources
121123
</DropdownItem>
122-
<DropdownItem key="logout" textValue="Log out" onPress={handleLogout}>
124+
<DropdownItem
125+
key="logout"
126+
textValue="Log out"
127+
onPress={handleLogout}
128+
startContent={<LogOut size={16} />}
129+
>
123130
Log out
124131
</DropdownItem>
125132
</DropdownMenu>

src/components/resources/resource-detail.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"use client";
22

3-
import type { Resource } from "@/types";
4-
53
import Link from "next/link";
64
import { Avatar, Button, Card, Chip, Image } from "@heroui/react";
75
import { formatDistanceToNow } from "date-fns";
86
import { ArrowUpRight, Clock, Hash } from "lucide-react";
7+
import { ShareButton } from "@/components/ui";
8+
import type { Resource } from "@/types";
99

10-
type Props = {
11-
resource: Resource;
12-
};
10+
type Props = { resource: Resource };
1311

1412
const comments = [
1513
{
@@ -104,6 +102,7 @@ export default function ResourceDetail({ resource }: Props) {
104102
</span>
105103
</div>
106104
<div className="flex gap-2">
105+
<ShareButton />
107106
<Button
108107
as={Link}
109108
size="sm"
@@ -131,13 +130,15 @@ export default function ResourceDetail({ resource }: Props) {
131130

132131
{/* Image */}
133132
{resource.image && (
134-
<figure className="overflow-hidden rounded-xl border-2 border-neutral-200 dark:border-neutral-800">
133+
<figure className="overflow-hidden rounded-xl border-2 border-neutral-200 dark:border-neutral-800 aspect-[2/1]">
135134
<Image
136-
src={resource.image || "/placeholder.svg"}
135+
isBlurred
136+
src={resource.image}
137137
alt={`Image for ${resource.name}`}
138-
width={600}
139-
height={400}
140-
className="h-auto w-full object-cover transition-all hover:scale-105"
138+
loading="eager"
139+
radius="none"
140+
sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw"
141+
className="w-full h-full object-cover"
141142
/>
142143
</figure>
143144
)}

src/components/ui/breadcrumbs.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,40 @@ import { Breadcrumbs as HeroBreadcrumbs, BreadcrumbItem } from "@heroui/react";
55
import { capitalize } from "@/lib/utils";
66

77
export default function Breadcrumbs() {
8-
// ! TODO: add blacklist for breadcrumbs
98
const router = useRouter();
109
const pathname = usePathname();
1110

11+
const blacklist = ["/resources", "/categories"];
12+
1213
const segments = pathname.split("/").filter(Boolean);
1314
const paths = segments.map(
1415
(_, idx) => "/" + segments.slice(0, idx + 1).join("/"),
1516
);
1617

1718
return (
1819
<HeroBreadcrumbs
19-
itemClasses={{
20-
separator: "px-2",
21-
}}
2220
separator="/"
21+
itemClasses={{ separator: "px-2" }}
2322
classNames={{ base: "hidden md:flex" }}
2423
>
25-
{segments.map((segment, idx) => (
26-
<BreadcrumbItem
27-
key={paths[idx]}
28-
onPress={() => router.push(paths[idx])}
29-
isCurrent={idx === segments.length - 1}
30-
>
31-
{capitalize(decodeURIComponent(segment).replace(/-/g, " "))}
32-
</BreadcrumbItem>
33-
))}
24+
{segments.map((segment, idx) => {
25+
const path = paths[idx];
26+
const isCurrent = idx === segments.length - 1;
27+
const isDisabled = blacklist.includes(path);
28+
29+
return (
30+
<BreadcrumbItem
31+
key={path}
32+
isCurrent={isCurrent}
33+
isDisabled={isCurrent || isDisabled}
34+
onPress={
35+
isCurrent || isDisabled ? undefined : () => router.push(path)
36+
}
37+
>
38+
{capitalize(decodeURIComponent(segment).replace(/-/g, " "))}
39+
</BreadcrumbItem>
40+
);
41+
})}
3442
</HeroBreadcrumbs>
3543
);
3644
}

src/components/ui/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ export { default as HeadingDashboard } from "./heading-dashboard";
1010
export { default as InfiniteList } from "./infinite-list";
1111
export { default as LinearLoading } from "./linear-loading";
1212
export { default as PulseDotsLoading } from "./pulse-dots-loading";
13+
export { default as ShareButton } from "./share-button";
1314
export { default as Table } from "./table";
1415
export { default as ThemeSwitcher } from "./theme-switcher";
16+
17+
export * from "./scroll-progress";

src/components/ui/infinite-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Props<T> = {
2121
};
2222

2323
export default function InfiniteList<T>({
24-
pageSize = 10,
24+
pageSize = 48,
2525
loadMore,
2626
renderItem,
2727
renderWrapper = (children) => <>{children}</>,

src/components/ui/share-button.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use client";
2+
3+
import { Button } from "@heroui/react";
4+
import { Share } from "lucide-react";
5+
6+
export default function ShareButton() {
7+
const shareData = {
8+
title: "Page Title",
9+
text: "Check out this page!",
10+
url: window.location.href,
11+
};
12+
13+
const handleShare = async () => {
14+
try {
15+
if (navigator.share) {
16+
await navigator.share(shareData);
17+
}
18+
} catch (error) {
19+
console.error("Error sharing:", error);
20+
}
21+
};
22+
23+
return (
24+
<Button
25+
isIconOnly
26+
size="sm"
27+
variant="bordered"
28+
onPress={handleShare}
29+
className="border-2 border-neutral-200 dark:border-neutral-800"
30+
>
31+
<Share size={16} />
32+
</Button>
33+
);
34+
}

0 commit comments

Comments
 (0)