"use client";
import type { BookmarksLayoutTypes } from "@/lib/userLocalSettings/types";
import type { ReactNode } from "react";
import { useEffect, useState } from "react";
import Image from "next/image";
import Link from "next/link";
import useBulkActionsStore from "@/lib/bulkActions";
import {
bookmarkLayoutSwitch,
useBookmarkDisplaySettings,
useBookmarkLayout,
} from "@/lib/userLocalSettings/bookmarksLayout";
import { cn } from "@/lib/utils";
import { Check, Image as ImageIcon, NotebookPen } from "lucide-react";
import { useTheme } from "next-themes";
import type { ZBookmark } from "@karakeep/shared/types/bookmarks";
import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";
import { isBookmarkStillTagging } from "@karakeep/shared/utils/bookmarkUtils";
import BookmarkActionBar from "./BookmarkActionBar";
import BookmarkFormattedCreatedAt from "./BookmarkFormattedCreatedAt";
import { NotePreview } from "./NotePreview";
import TagList from "./TagList";
interface Props {
bookmark: ZBookmark;
image: (layout: BookmarksLayoutTypes, className: string) => ReactNode;
title?: ReactNode;
content?: ReactNode;
footer?: ReactNode;
className?: string;
fitHeight?: boolean;
wrapTags: boolean;
}
function BottomRow({
footer,
bookmark,
}: {
footer?: ReactNode;
bookmark: ZBookmark;
}) {
return (
);
}
function MultiBookmarkSelector({ bookmark }: { bookmark: ZBookmark }) {
const { selectedBookmarks, isBulkEditEnabled } = useBulkActionsStore();
const toggleBookmark = useBulkActionsStore((state) => state.toggleBookmark);
const [isSelected, setIsSelected] = useState(false);
const { theme } = useTheme();
useEffect(() => {
setIsSelected(selectedBookmarks.some((item) => item.id === bookmark.id));
}, [selectedBookmarks]);
if (!isBulkEditEnabled) return null;
const getIconColor = () => {
if (theme === "dark") {
return isSelected ? "black" : "white";
}
return isSelected ? "white" : "black";
};
const getIconBackgroundColor = () => {
if (theme === "dark") {
return isSelected ? "bg-white" : "bg-white bg-opacity-10";
}
return isSelected ? "bg-black" : "bg-white bg-opacity-40";
};
return (
);
}
function ListView({
bookmark,
image,
title,
content,
footer,
className,
}: Props) {
const { showNotes } = useBookmarkDisplaySettings();
const note = showNotes ? bookmark.note?.trim() : undefined;
return (
{image("list", "object-cover rounded-lg size-32")}
{title && (
{title}
)}
{content &&
{content}
}
{note &&
}
);
}
function GridView({
bookmark,
image,
title,
content,
footer,
className,
wrapTags,
layout,
fitHeight = false,
}: Props & { layout: BookmarksLayoutTypes }) {
const { showNotes } = useBookmarkDisplaySettings();
const note = showNotes ? bookmark.note?.trim() : undefined;
const img = image("grid", "h-52 min-h-52 w-full object-cover rounded-t-lg");
return (
{img &&
{img}
}
{title && (
{title}
)}
{content &&
{content}
}
{note &&
}
);
}
function CompactView({ bookmark, title, footer, className }: Props) {
return (
{bookmark.content.type === BookmarkTypes.LINK &&
bookmark.content.favicon && (
)}
{bookmark.content.type === BookmarkTypes.TEXT && (
)}
{bookmark.content.type === BookmarkTypes.ASSET && (
)}
{
{title ?? "Untitled"}
}
{footer && (
•{footer}
)}
•
);
}
export function BookmarkLayoutAdaptingCard(props: Props) {
const layout = useBookmarkLayout();
return bookmarkLayoutSwitch(layout, {
masonry: ,
grid: ,
list: ,
compact: ,
});
}