Add nsfw handling. Add zustand for global store
This commit is contained in:
11
bun.lock
11
bun.lock
@ -5,8 +5,8 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "app.gaertan.art",
|
"name": "app.gaertan.art",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.974.0",
|
"@aws-sdk/client-s3": "^3.980.0",
|
||||||
"@aws-sdk/s3-request-presigner": "^3.974.0",
|
"@aws-sdk/s3-request-presigner": "^3.980.0",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
"@prisma/adapter-pg": "^7.3.0",
|
"@prisma/adapter-pg": "^7.3.0",
|
||||||
"@prisma/client": "^7.3.0",
|
"@prisma/client": "^7.3.0",
|
||||||
@ -27,15 +27,16 @@
|
|||||||
"lucide-react": "^0.561.0",
|
"lucide-react": "^0.561.0",
|
||||||
"next": "16.1.6",
|
"next": "16.1.6",
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"pg": "^8.17.2",
|
"pg": "^8.18.0",
|
||||||
"react": "19.2.4",
|
"react": "19.2.4",
|
||||||
"react-dom": "19.2.4",
|
"react-dom": "19.2.4",
|
||||||
"react-hook-form": "^7.71.1",
|
"react-hook-form": "^7.71.1",
|
||||||
"react-markdown": "^10.1.0",
|
"react-markdown": "^10.1.0",
|
||||||
"simple-icons": "^16.6.0",
|
"simple-icons": "^16.7.0",
|
||||||
"sonner": "^2.0.7",
|
"sonner": "^2.0.7",
|
||||||
"tailwind-merge": "^3.4.0",
|
"tailwind-merge": "^3.4.0",
|
||||||
"zod": "^4.3.6",
|
"zod": "^4.3.6",
|
||||||
|
"zustand": "^5.0.6",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.2.0",
|
"@biomejs/biome": "2.2.0",
|
||||||
@ -944,6 +945,8 @@
|
|||||||
|
|
||||||
"zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="],
|
"zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="],
|
||||||
|
|
||||||
|
"zustand": ["zustand@5.0.11", "", { "peerDependencies": { "@types/react": ">=18.0.0", "immer": ">=9.0.6", "react": ">=18.0.0", "use-sync-external-store": ">=1.2.0" }, "optionalPeers": ["@types/react", "immer", "react", "use-sync-external-store"] }, "sha512-fdZY+dk7zn/vbWNCYmzZULHRrss0jx5pPFiOuMZ/5HJN6Yv3u+1Wswy/4MpZEkEGhtNH+pwxZB8OKgUBPzYAGg=="],
|
||||||
|
|
||||||
"zwitch": ["zwitch@2.0.4", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
|
"zwitch": ["zwitch@2.0.4", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
|
||||||
|
|
||||||
"@aws-crypto/crc32/@aws-sdk/types": ["@aws-sdk/types@3.953.0", "", { "dependencies": { "@smithy/types": "^4.10.0", "tslib": "^2.6.2" } }, "sha512-M9Iwg9kTyqTErI0vOTVVpcnTHWzS3VplQppy8MuL02EE+mJ0BIwpWfsaAPQW+/XnVpdNpWZTsHcNE29f1+hR8g=="],
|
"@aws-crypto/crc32/@aws-sdk/types": ["@aws-sdk/types@3.953.0", "", { "dependencies": { "@smithy/types": "^4.10.0", "tslib": "^2.6.2" } }, "sha512-M9Iwg9kTyqTErI0vOTVVpcnTHWzS3VplQppy8MuL02EE+mJ0BIwpWfsaAPQW+/XnVpdNpWZTsHcNE29f1+hR8g=="],
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
"simple-icons": "^16.7.0",
|
"simple-icons": "^16.7.0",
|
||||||
"sonner": "^2.0.7",
|
"sonner": "^2.0.7",
|
||||||
"tailwind-merge": "^3.4.0",
|
"tailwind-merge": "^3.4.0",
|
||||||
|
"zustand": "^5.0.6",
|
||||||
"zod": "^4.3.6"
|
"zod": "^4.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -51,6 +51,7 @@ export async function getAnimalStudiesPage(input: unknown): Promise<AnimalStudie
|
|||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
altText: true,
|
altText: true,
|
||||||
|
nsfw: true,
|
||||||
sortKey: true,
|
sortKey: true,
|
||||||
file: { select: { fileKey: true } },
|
file: { select: { fileKey: true } },
|
||||||
variants: {
|
variants: {
|
||||||
@ -80,6 +81,7 @@ export async function getAnimalStudiesPage(input: unknown): Promise<AnimalStudie
|
|||||||
id: r.id,
|
id: r.id,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
altText: r.altText,
|
altText: r.altText,
|
||||||
|
nsfw: r.nsfw ?? false,
|
||||||
fileKey: r.file.fileKey,
|
fileKey: r.file.fileKey,
|
||||||
width: w,
|
width: w,
|
||||||
height: h,
|
height: h,
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export type PortfolioArtworkItem = {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
altText: string | null;
|
altText: string | null;
|
||||||
|
nsfw: boolean;
|
||||||
|
|
||||||
sortKey: number | null;
|
sortKey: number | null;
|
||||||
year: number | null;
|
year: number | null;
|
||||||
@ -113,6 +114,7 @@ export async function getPortfolioArtworksPage(args: {
|
|||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
altText: true,
|
altText: true,
|
||||||
|
nsfw: true,
|
||||||
year: true,
|
year: true,
|
||||||
sortKey: true,
|
sortKey: true,
|
||||||
file: { select: { fileKey: true } },
|
file: { select: { fileKey: true } },
|
||||||
@ -138,6 +140,7 @@ export async function getPortfolioArtworksPage(args: {
|
|||||||
id: r.id,
|
id: r.id,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
altText: r.altText ?? null,
|
altText: r.altText ?? null,
|
||||||
|
nsfw: r.nsfw ?? false,
|
||||||
sortKey: r.sortKey ?? null,
|
sortKey: r.sortKey ?? null,
|
||||||
year: r.year ?? null,
|
year: r.year ?? null,
|
||||||
fileKey: r.file.fileKey,
|
fileKey: r.file.fileKey,
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export type TaggedArtworkItem = {
|
|||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
altText: string | null;
|
altText: string | null;
|
||||||
|
nsfw: boolean;
|
||||||
sortKey: number | null;
|
sortKey: number | null;
|
||||||
year: number | null;
|
year: number | null;
|
||||||
fileKey: string;
|
fileKey: string;
|
||||||
@ -54,6 +55,7 @@ export async function getTaggedArtworksPage(args: {
|
|||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
altText: true,
|
altText: true,
|
||||||
|
nsfw: true,
|
||||||
year: true,
|
year: true,
|
||||||
sortKey: true,
|
sortKey: true,
|
||||||
file: { select: { fileKey: true } },
|
file: { select: { fileKey: true } },
|
||||||
@ -79,6 +81,7 @@ export async function getTaggedArtworksPage(args: {
|
|||||||
id: r.id,
|
id: r.id,
|
||||||
name: r.name,
|
name: r.name,
|
||||||
altText: r.altText ?? null,
|
altText: r.altText ?? null,
|
||||||
|
nsfw: r.nsfw ?? false,
|
||||||
sortKey: r.sortKey ?? null,
|
sortKey: r.sortKey ?? null,
|
||||||
year: r.year ?? null,
|
year: r.year ?? null,
|
||||||
fileKey: r.file.fileKey,
|
fileKey: r.file.fileKey,
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
import ArtworkMetaCard from "@/components/artworks/ArtworkMetaCard";
|
import ArtworkMetaCard from "@/components/artworks/ArtworkMetaCard";
|
||||||
import ArtworkTimelapseViewer from "@/components/artworks/ArtworkTimelapseViewer";
|
import ArtworkTimelapseViewer from "@/components/artworks/ArtworkTimelapseViewer";
|
||||||
import { ContextBackButton } from "@/components/artworks/ContextBackButton";
|
import { ContextBackButton } from "@/components/artworks/ContextBackButton";
|
||||||
|
import NsfwConsentDialog from "@/components/nsfw/NsfwConsentDialog";
|
||||||
|
import NsfwImage from "@/components/nsfw/NsfwImage";
|
||||||
|
import NsfwLink from "@/components/nsfw/NsfwLink";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { PlayCircle } from "lucide-react";
|
import { PlayCircle } from "lucide-react";
|
||||||
import Image from "next/image";
|
|
||||||
import Link from "next/link";
|
|
||||||
|
|
||||||
export default async function SingleArtworkPage({
|
export default async function SingleArtworkPage({
|
||||||
params,
|
params,
|
||||||
@ -49,6 +50,7 @@ export default async function SingleArtworkPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="px-4 sm:px-8 py-4">
|
<div className="px-4 sm:px-8 py-4">
|
||||||
|
<NsfwConsentDialog hasNsfw={Boolean(artwork.nsfw)} />
|
||||||
<div className="relative w-full min-h-10 flex items-center mb-4">
|
<div className="relative w-full min-h-10 flex items-center mb-4">
|
||||||
<div className="z-10 hidden sm:block">
|
<div className="z-10 hidden sm:block">
|
||||||
<ContextBackButton />
|
<ContextBackButton />
|
||||||
@ -69,16 +71,17 @@ export default async function SingleArtworkPage({
|
|||||||
className="relative w-full bg-muted items-center justify-center"
|
className="relative w-full bg-muted items-center justify-center"
|
||||||
style={{ aspectRatio: "4 / 3" }}
|
style={{ aspectRatio: "4 / 3" }}
|
||||||
>
|
>
|
||||||
<Link href={`/raw/${artwork.id}`}>
|
<NsfwLink href={`/raw/${artwork.id}`} nsfw={Boolean(artwork.nsfw)}>
|
||||||
<Image
|
<NsfwImage
|
||||||
src={`/api/image/resized/${artwork.file.fileKey}.webp`}
|
src={`/api/image/resized/${artwork.file.fileKey}.webp`}
|
||||||
alt={artwork.altText || "Artwork"}
|
alt={artwork.altText || "Artwork"}
|
||||||
fill={!width || !height}
|
fill={!width || !height}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
|
nsfw={Boolean(artwork.nsfw)}
|
||||||
className={cn("object-cover transition duration-300")}
|
className={cn("object-cover transition duration-300")}
|
||||||
/>
|
/>
|
||||||
</Link>
|
</NsfwLink>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{artwork.timelapse?.enabled ? (
|
{artwork.timelapse?.enabled ? (
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import NsfwBadge from "@/components/nsfw/NsfwBadge";
|
||||||
|
import NsfwConsentDialog from "@/components/nsfw/NsfwConsentDialog";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { useNsfwStore } from "@/stores/nsfw-store";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
@ -24,6 +27,9 @@ export type JustifiedGalleryItem = {
|
|||||||
|
|
||||||
/** Optional: dominant color for hover ring. */
|
/** Optional: dominant color for hover ring. */
|
||||||
dominantHex?: string | null;
|
dominantHex?: string | null;
|
||||||
|
|
||||||
|
/** Optional: NSFW flag */
|
||||||
|
nsfw?: boolean | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -94,12 +100,18 @@ export default function JustifiedGallery({
|
|||||||
debug = false,
|
debug = false,
|
||||||
className,
|
className,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
const consent = useNsfwStore((s) => s.consent);
|
||||||
|
const allowNsfw = consent === "allow";
|
||||||
|
const hasNsfw = useMemo(() => items.some((i) => i.nsfw), [items]);
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const sentinelRef = useRef<HTMLDivElement | null>(null);
|
const sentinelRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [containerWidth, setContainerWidth] = useState(0);
|
const [containerWidth, setContainerWidth] = useState(0);
|
||||||
const effectiveGap = (() => {
|
const effectiveGap = (() => {
|
||||||
if (gapBreakpoints && containerWidth > 0) {
|
if (gapBreakpoints && containerWidth > 0) {
|
||||||
const sorted = [...gapBreakpoints].sort((a, b) => a.maxWidth - b.maxWidth);
|
const sorted = [...gapBreakpoints].sort(
|
||||||
|
(a, b) => a.maxWidth - b.maxWidth,
|
||||||
|
);
|
||||||
for (const bp of sorted) {
|
for (const bp of sorted) {
|
||||||
if (containerWidth <= bp.maxWidth) return bp.gap;
|
if (containerWidth <= bp.maxWidth) return bp.gap;
|
||||||
}
|
}
|
||||||
@ -273,6 +285,7 @@ export default function JustifiedGallery({
|
|||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
className={cn("mx-auto w-full max-w-6xl", className)}
|
className={cn("mx-auto w-full max-w-6xl", className)}
|
||||||
>
|
>
|
||||||
|
<NsfwConsentDialog hasNsfw={hasNsfw} />
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{rows.map((row, idx) => (
|
{rows.map((row, idx) => (
|
||||||
<div key={getRowKey(row)}>
|
<div key={getRowKey(row)}>
|
||||||
@ -294,6 +307,7 @@ export default function JustifiedGallery({
|
|||||||
hrefBase={hrefBase}
|
hrefBase={hrefBase}
|
||||||
hrefFrom={hrefFrom}
|
hrefFrom={hrefFrom}
|
||||||
showCaption={showCaption}
|
showCaption={showCaption}
|
||||||
|
allowNsfw={allowNsfw}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@ -328,16 +342,20 @@ function GalleryTile({
|
|||||||
hrefBase,
|
hrefBase,
|
||||||
hrefFrom,
|
hrefFrom,
|
||||||
showCaption,
|
showCaption,
|
||||||
|
allowNsfw,
|
||||||
}: {
|
}: {
|
||||||
tile: RowTile;
|
tile: RowTile;
|
||||||
hrefBase: string;
|
hrefBase: string;
|
||||||
hrefFrom: string;
|
hrefFrom: string;
|
||||||
showCaption: boolean;
|
showCaption: boolean;
|
||||||
|
allowNsfw: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { item, w, h } = tile;
|
const { item, w, h } = tile;
|
||||||
|
|
||||||
const href = `${hrefBase}/${item.id}?from=${encodeURIComponent(hrefFrom)}`;
|
const href = `${hrefBase}/${item.id}?from=${encodeURIComponent(hrefFrom)}`;
|
||||||
const src = `/api/image/gallery/${item.fileKey}.webp`;
|
const src = `/api/image/gallery/${item.fileKey}.webp`;
|
||||||
|
const isNsfw = Boolean(item.nsfw);
|
||||||
|
const shouldBlur = isNsfw && !allowNsfw;
|
||||||
|
|
||||||
const style: CSSProperties & { "--dom"?: string } = {};
|
const style: CSSProperties & { "--dom"?: string } = {};
|
||||||
const dom = normalizeColor(item.dominantHex);
|
const dom = normalizeColor(item.dominantHex);
|
||||||
@ -372,11 +390,26 @@ function GalleryTile({
|
|||||||
alt={item.altText ?? item.name ?? "Artwork"}
|
alt={item.altText ?? item.name ?? "Artwork"}
|
||||||
width={w}
|
width={w}
|
||||||
height={h}
|
height={h}
|
||||||
className="h-full w-full object-cover"
|
className={cn(
|
||||||
|
"h-full w-full object-cover transition-[filter,transform] duration-200",
|
||||||
|
shouldBlur ? "blur-2xl scale-[1.02]" : "blur-0",
|
||||||
|
)}
|
||||||
// Tiles are thumbnail-ish; bias Next toward small resources.
|
// Tiles are thumbnail-ish; bias Next toward small resources.
|
||||||
sizes="(max-width: 640px) 90vw, (max-width: 1024px) 50vw, 320px"
|
sizes="(max-width: 640px) 90vw, (max-width: 1024px) 50vw, 320px"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{isNsfw ? (
|
||||||
|
shouldBlur ? null : (
|
||||||
|
<NsfwBadge className="absolute left-2 bottom-2 z-10" />
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{shouldBlur ? (
|
||||||
|
<div className="absolute inset-0 z-10 flex items-center justify-center bg-black/45">
|
||||||
|
<NsfwBadge className="scale-110 shadow-md" />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{showCaption ? (
|
{showCaption ? (
|
||||||
<div className="pointer-events-none absolute inset-x-0 top-0 bg-black/60 p-3">
|
<div className="pointer-events-none absolute inset-x-0 top-0 bg-black/60 p-3">
|
||||||
<div className="text-sm font-medium text-white line-clamp-1">
|
<div className="text-sm font-medium text-white line-clamp-1">
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import ModeToggle from "./ModeToggle";
|
import ModeToggle from "./ModeToggle";
|
||||||
|
import NsfwModeToggle from "./NsfwModeToggle";
|
||||||
import TopNav from "./TopNav";
|
import TopNav from "./TopNav";
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
@ -7,8 +8,11 @@ export default function Header() {
|
|||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-center justify-between px-4 md:px-8 py-2">
|
<div className="flex items-center justify-between px-4 md:px-8 py-2">
|
||||||
<TopNav />
|
<TopNav />
|
||||||
<ModeToggle />
|
<div className="flex items-center gap-2">
|
||||||
|
<NsfwModeToggle />
|
||||||
|
<ModeToggle />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/components/global/NsfwModeToggle.tsx
Normal file
42
src/components/global/NsfwModeToggle.tsx
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Eye, EyeOff } from "lucide-react";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import { useNsfwStore } from "@/stores/nsfw-store";
|
||||||
|
|
||||||
|
export default function NsfwModeToggle() {
|
||||||
|
const consent = useNsfwStore((s) => s.consent);
|
||||||
|
const setConsent = useNsfwStore((s) => s.setConsent);
|
||||||
|
|
||||||
|
const enabled = consent === "allow";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="outline" size="icon">
|
||||||
|
{enabled ? (
|
||||||
|
<Eye className="h-[1.2rem] w-[1.2rem]" />
|
||||||
|
) : (
|
||||||
|
<EyeOff className="h-[1.2rem] w-[1.2rem]" />
|
||||||
|
)}
|
||||||
|
<span className="sr-only">Toggle NSFW mode</span>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem onClick={() => setConsent("allow")}>
|
||||||
|
Allow NSFW Content
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem onClick={() => setConsent("deny")}>
|
||||||
|
Hide NSFW Content
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
19
src/components/nsfw/NsfwBadge.tsx
Normal file
19
src/components/nsfw/NsfwBadge.tsx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { EyeOff } from "lucide-react";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
export default function NsfwBadge({ className }: { className?: string }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"inline-flex items-center gap-1 rounded-full bg-black/70 px-2 py-1 text-xs font-semibold text-white shadow-sm",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<EyeOff className="h-3 w-3" />
|
||||||
|
NSFW
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
75
src/components/nsfw/NsfwConsentDialog.tsx
Normal file
75
src/components/nsfw/NsfwConsentDialog.tsx
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { EyeOff } from "lucide-react";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
import { useNsfwStore } from "@/stores/nsfw-store";
|
||||||
|
|
||||||
|
export default function NsfwConsentDialog({ hasNsfw }: { hasNsfw: boolean }) {
|
||||||
|
const consent = useNsfwStore((s) => s.consent);
|
||||||
|
const setConsent = useNsfwStore((s) => s.setConsent);
|
||||||
|
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!hasNsfw) {
|
||||||
|
setOpen(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (consent === "unset") setOpen(true);
|
||||||
|
else setOpen(false);
|
||||||
|
}, [hasNsfw, consent]);
|
||||||
|
|
||||||
|
if (!hasNsfw) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(next) => {
|
||||||
|
if (!next && consent === "unset") return;
|
||||||
|
setOpen(next);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent showCloseButton={false}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="flex items-center gap-2">
|
||||||
|
<EyeOff className="h-5 w-5 text-destructive" />
|
||||||
|
Sensitive Content
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Sensitive artworks ahead. Confirm you’re 18+ to view it. You can
|
||||||
|
change this anytime with the NSFW toggle in the header.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
setConsent("deny");
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Keep blurred
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setConsent("allow");
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
I’m 18+ · Show
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
47
src/components/nsfw/NsfwImage.tsx
Normal file
47
src/components/nsfw/NsfwImage.tsx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Image, { type ImageProps } from "next/image";
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { useNsfwStore } from "@/stores/nsfw-store";
|
||||||
|
|
||||||
|
import NsfwBadge from "./NsfwBadge";
|
||||||
|
|
||||||
|
type NsfwImageProps = ImageProps & {
|
||||||
|
nsfw?: boolean;
|
||||||
|
wrapperClassName?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function NsfwImage({
|
||||||
|
nsfw = false,
|
||||||
|
wrapperClassName,
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: NsfwImageProps) {
|
||||||
|
const consent = useNsfwStore((s) => s.consent);
|
||||||
|
const allowNsfw = consent === "allow";
|
||||||
|
const shouldBlur = nsfw && !allowNsfw;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Image
|
||||||
|
{...props}
|
||||||
|
className={cn(
|
||||||
|
"transition-[filter,transform] duration-200",
|
||||||
|
shouldBlur ? "blur-2xl scale-[1.02]" : "blur-0",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{nsfw ? shouldBlur ? null : (
|
||||||
|
<NsfwBadge className="absolute left-2 bottom-2 z-10" />
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{shouldBlur ? (
|
||||||
|
<div className="absolute inset-0 z-10 flex items-center justify-center bg-black/45">
|
||||||
|
<NsfwBadge className="scale-110 shadow-md" />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
38
src/components/nsfw/NsfwLink.tsx
Normal file
38
src/components/nsfw/NsfwLink.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { useNsfwStore } from "@/stores/nsfw-store";
|
||||||
|
|
||||||
|
export default function NsfwLink({
|
||||||
|
href,
|
||||||
|
nsfw = false,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
href: string;
|
||||||
|
nsfw?: boolean;
|
||||||
|
className?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const consent = useNsfwStore((s) => s.consent);
|
||||||
|
const allowNsfw = consent === "allow";
|
||||||
|
const blocked = nsfw && !allowNsfw;
|
||||||
|
|
||||||
|
if (blocked) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("block cursor-not-allowed", className)}
|
||||||
|
aria-disabled="true"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link href={href} className={cn("block", className)}>
|
||||||
|
{children}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -110,6 +110,7 @@ export default function PortfolioGallery({
|
|||||||
id: it.id,
|
id: it.id,
|
||||||
name: it.name,
|
name: it.name,
|
||||||
altText: it.altText,
|
altText: it.altText,
|
||||||
|
nsfw: it.nsfw,
|
||||||
fileKey: it.fileKey,
|
fileKey: it.fileKey,
|
||||||
width: it.thumbW,
|
width: it.thumbW,
|
||||||
height: it.thumbH,
|
height: it.thumbH,
|
||||||
|
|||||||
@ -30,6 +30,7 @@ export default function TaggedGallery({ tagSlugs }: { tagSlugs: string[] }) {
|
|||||||
const cursorRef = useRef<Cursor>(null);
|
const cursorRef = useRef<Cursor>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
void resetKey;
|
||||||
setItems([]);
|
setItems([]);
|
||||||
setDone(false);
|
setDone(false);
|
||||||
doneRef.current = false;
|
doneRef.current = false;
|
||||||
@ -75,6 +76,7 @@ export default function TaggedGallery({ tagSlugs }: { tagSlugs: string[] }) {
|
|||||||
id: it.id,
|
id: it.id,
|
||||||
name: it.name,
|
name: it.name,
|
||||||
altText: it.altText,
|
altText: it.altText,
|
||||||
|
nsfw: it.nsfw,
|
||||||
fileKey: it.fileKey,
|
fileKey: it.fileKey,
|
||||||
width: it.thumbW,
|
width: it.thumbW,
|
||||||
height: it.thumbH,
|
height: it.thumbH,
|
||||||
|
|||||||
30
src/stores/nsfw-store.ts
Normal file
30
src/stores/nsfw-store.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { create } from "zustand";
|
||||||
|
import { createJSONStorage, persist } from "zustand/middleware";
|
||||||
|
|
||||||
|
export type NsfwConsent = "unset" | "allow" | "deny";
|
||||||
|
|
||||||
|
type NsfwStore = {
|
||||||
|
consent: NsfwConsent;
|
||||||
|
setConsent: (consent: NsfwConsent) => void;
|
||||||
|
allow: () => void;
|
||||||
|
deny: () => void;
|
||||||
|
reset: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useNsfwStore = create<NsfwStore>()(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
|
consent: "unset",
|
||||||
|
setConsent: (consent) => set({ consent }),
|
||||||
|
allow: () => set({ consent: "allow" }),
|
||||||
|
deny: () => set({ consent: "deny" }),
|
||||||
|
reset: () => set({ consent: "unset" }),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: "gaertan-nsfw-consent",
|
||||||
|
storage: createJSONStorage(() => localStorage),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user