1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-09 17:37:40 +01:00
smov/src/pages/parts/home/BookmarksPart.tsx

55 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-08-20 17:59:46 +02:00
import { useAutoAnimate } from "@formkit/auto-animate/react";
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { EditButton } from "@/components/buttons/EditButton";
import { Icons } from "@/components/Icon";
import { SectionHeading } from "@/components/layout/SectionHeading";
import { MediaGrid } from "@/components/media/MediaGrid";
import { WatchedMediaCard } from "@/components/media/WatchedMediaCard";
2023-10-17 16:14:46 +02:00
import { useBookmarkStore } from "@/stores/bookmarks";
import { MediaItem } from "@/utils/mediaTypes";
2023-08-20 17:59:46 +02:00
export function BookmarksPart() {
const { t } = useTranslation();
2023-10-17 16:14:46 +02:00
const bookmarks = useBookmarkStore((s) => s.bookmarks);
const removeBookmark = useBookmarkStore((s) => s.removeBookmark);
2023-08-20 17:59:46 +02:00
const [editing, setEditing] = useState(false);
const [gridRef] = useAutoAnimate<HTMLDivElement>();
2023-10-17 16:14:46 +02:00
// TODO sort on last watched
const items = useMemo(() => {
const output: MediaItem[] = [];
Object.entries(bookmarks).forEach((entry) => {
output.push({
id: entry[0],
...entry[1],
});
});
return output;
}, [bookmarks]);
2023-08-20 17:59:46 +02:00
2023-10-17 16:14:46 +02:00
if (items.length === 0) return null;
2023-08-20 17:59:46 +02:00
return (
<div>
<SectionHeading
title={t("search.bookmarks") || "Bookmarks"}
icon={Icons.BOOKMARK}
>
<EditButton editing={editing} onEdit={setEditing} />
</SectionHeading>
<MediaGrid ref={gridRef}>
2023-10-17 16:14:46 +02:00
{items.map((v) => (
<WatchedMediaCard
key={v.id}
media={v}
closable={editing}
onClose={() => removeBookmark(v.id)}
/>
2023-08-20 17:59:46 +02:00
))}
</MediaGrid>
</div>
);
}