Add toggle to gray out unseen entries in collections
Hide unseen button near sort controls applies grayscale + low opacity to posters of entries that haven't been watched. Preference is persisted per-collection via the existing sort store.
This commit is contained in:
1 parent
e434dd3b5e
commit
3c29cf78ea
4 files changed
+91
-20
No files matched your search
@@ -53,6 +53,8 @@ interface EntryCardProps {
|
|||||||
collectionId?: number;
|
collectionId?: number;
|
||||||
/** Callback to remove entry from collection */
|
/** Callback to remove entry from collection */
|
||||||
onRemoveFromCollection?: (entryId: number) => void;
|
onRemoveFromCollection?: (entryId: number) => void;
|
||||||
|
/** When true, apply grayscale + low opacity to posters of unseen entries */
|
||||||
|
grayOutUnseen?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EntryCard({
|
export function EntryCard({
|
||||||
@@ -61,6 +63,7 @@ export function EntryCard({
|
|||||||
showTypeBadge,
|
showTypeBadge,
|
||||||
collectionId,
|
collectionId,
|
||||||
onRemoveFromCollection,
|
onRemoveFromCollection,
|
||||||
|
grayOutUnseen,
|
||||||
}: EntryCardProps) {
|
}: EntryCardProps) {
|
||||||
const [showConfirm, setShowConfirm] = useState(false);
|
const [showConfirm, setShowConfirm] = useState(false);
|
||||||
const [showRemoveCollectionConfirm, setShowRemoveCollectionConfirm] =
|
const [showRemoveCollectionConfirm, setShowRemoveCollectionConfirm] =
|
||||||
@@ -90,6 +93,11 @@ export function EntryCard({
|
|||||||
const isInLibrary = !!libraryEntry;
|
const isInLibrary = !!libraryEntry;
|
||||||
const displayEntry = libraryEntry || entry;
|
const displayEntry = libraryEntry || entry;
|
||||||
|
|
||||||
|
// Determine if entry has been watched
|
||||||
|
const isSeen = !!(
|
||||||
|
displayEntry?.entrySeens?.length || displayEntry?.date_last_seen
|
||||||
|
);
|
||||||
|
|
||||||
// Resolve display data
|
// Resolve display data
|
||||||
const title =
|
const title =
|
||||||
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || "Untitled";
|
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || "Untitled";
|
||||||
@@ -164,7 +172,9 @@ export function EntryCard({
|
|||||||
<img
|
<img
|
||||||
src={posterUrl}
|
src={posterUrl}
|
||||||
alt={title}
|
alt={title}
|
||||||
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
className={`h-full w-full object-cover transition-all duration-300 group-hover:scale-105 ${
|
||||||
|
grayOutUnseen && !isSeen ? "grayscale opacity-40" : ""
|
||||||
|
}`}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -182,7 +192,9 @@ export function EntryCard({
|
|||||||
|
|
||||||
{/* Quick actions button – top right, shown on hover */}
|
{/* Quick actions button – top right, shown on hover */}
|
||||||
{isInLibrary && (
|
{isInLibrary && (
|
||||||
<div className={`absolute right-2 top-2 z-20 transition-opacity ${dropdownOpen ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}>
|
<div
|
||||||
|
className={`absolute right-2 top-2 z-20 transition-opacity ${dropdownOpen ? "opacity-100" : "opacity-0 group-hover:opacity-100"}`}
|
||||||
|
>
|
||||||
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
|
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useRef, useEffect } from 'react';
|
import { useCallback, useRef, useEffect } from "react";
|
||||||
import { EntryCard, EntryCardSkeleton } from './EntryCard';
|
import { EntryCard, EntryCardSkeleton } from "./EntryCard";
|
||||||
import type { Entry } from '@/types';
|
import type { Entry } from "@/types";
|
||||||
|
|
||||||
interface EntryLibraryGridProps {
|
interface EntryLibraryGridProps {
|
||||||
entries: Entry[];
|
entries: Entry[];
|
||||||
@@ -9,6 +9,7 @@ interface EntryLibraryGridProps {
|
|||||||
onLoadMore?: () => void;
|
onLoadMore?: () => void;
|
||||||
collectionId?: number;
|
collectionId?: number;
|
||||||
onRemoveFromCollection?: (entryId: number) => void;
|
onRemoveFromCollection?: (entryId: number) => void;
|
||||||
|
grayOutUnseen?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EntryLibraryGrid({
|
export function EntryLibraryGrid({
|
||||||
@@ -18,6 +19,7 @@ export function EntryLibraryGrid({
|
|||||||
onLoadMore,
|
onLoadMore,
|
||||||
collectionId,
|
collectionId,
|
||||||
onRemoveFromCollection,
|
onRemoveFromCollection,
|
||||||
|
grayOutUnseen,
|
||||||
}: EntryLibraryGridProps) {
|
}: EntryLibraryGridProps) {
|
||||||
const observerRef = useRef<IntersectionObserver | null>(null);
|
const observerRef = useRef<IntersectionObserver | null>(null);
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ export function EntryLibraryGrid({
|
|||||||
});
|
});
|
||||||
if (node) observerRef.current.observe(node);
|
if (node) observerRef.current.observe(node);
|
||||||
},
|
},
|
||||||
[isLoading, hasMore, onLoadMore]
|
[isLoading, hasMore, onLoadMore],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -66,7 +68,12 @@ export function EntryLibraryGrid({
|
|||||||
className="animate-card-enter"
|
className="animate-card-enter"
|
||||||
style={{ animationDelay: `${Math.min(index * 30, 300)}ms` }}
|
style={{ animationDelay: `${Math.min(index * 30, 300)}ms` }}
|
||||||
>
|
>
|
||||||
<EntryCard entry={entry} collectionId={collectionId} onRemoveFromCollection={onRemoveFromCollection} />
|
<EntryCard
|
||||||
|
entry={entry}
|
||||||
|
collectionId={collectionId}
|
||||||
|
onRemoveFromCollection={onRemoveFromCollection}
|
||||||
|
grayOutUnseen={grayOutUnseen}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
{isLoading &&
|
{isLoading &&
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import {
|
|||||||
Trash2,
|
Trash2,
|
||||||
ArrowUp,
|
ArrowUp,
|
||||||
ArrowDown,
|
ArrowDown,
|
||||||
|
Eye,
|
||||||
|
EyeOff,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { CollectionEditDialog } from "@/components/dialogs/CollectionEditDialog";
|
import { CollectionEditDialog } from "@/components/dialogs/CollectionEditDialog";
|
||||||
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
||||||
@@ -44,10 +46,12 @@ export function CollectionDetailsPage() {
|
|||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||||
const collectionSortPrefs = useCollectionSortStore((s) => s.prefs);
|
const collectionSortPrefs = useCollectionSortStore((s) => s.prefs);
|
||||||
const setSortPref = useCollectionSortStore((s) => s.setSort);
|
const setSortPref = useCollectionSortStore((s) => s.setSort);
|
||||||
|
const setHideUnseen = useCollectionSortStore((s) => s.setHideUnseen);
|
||||||
const collectionId = Number(id);
|
const collectionId = Number(id);
|
||||||
const sortPref = collectionSortPrefs[collectionId];
|
const sortPref = collectionSortPrefs[collectionId];
|
||||||
const sortField: CollectionSortField = sortPref?.field ?? "order";
|
const sortField: CollectionSortField = sortPref?.field ?? "order";
|
||||||
const sortDir: SortDir = sortPref?.dir ?? "asc";
|
const sortDir: SortDir = sortPref?.dir ?? "asc";
|
||||||
|
const hideUnseen = sortPref?.hideUnseen ?? false;
|
||||||
const deleteCollection = useDeleteCollection();
|
const deleteCollection = useDeleteCollection();
|
||||||
const getCollectionParts = useGetCollectionParts();
|
const getCollectionParts = useGetCollectionParts();
|
||||||
const removeEntryFromCollection = useRemoveEntryFromCollection();
|
const removeEntryFromCollection = useRemoveEntryFromCollection();
|
||||||
@@ -235,9 +239,11 @@ export function CollectionDetailsPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Sort – bottom right */}
|
{/* Sort – bottom right */}
|
||||||
{entries.length > 1 && (
|
|
||||||
<div className="ml-auto flex items-center gap-1 self-end">
|
<div className="ml-auto flex items-center gap-1 self-end">
|
||||||
{(["order", "year", "title", "rating"] as const).map((field) => (
|
{entries.length > 1 && (
|
||||||
|
<>
|
||||||
|
{(["order", "year", "title", "rating"] as const).map(
|
||||||
|
(field) => (
|
||||||
<Button
|
<Button
|
||||||
key={field}
|
key={field}
|
||||||
variant={sortField === field ? "secondary" : "ghost"}
|
variant={sortField === field ? "secondary" : "ghost"}
|
||||||
@@ -253,9 +259,28 @@ export function CollectionDetailsPage() {
|
|||||||
<ArrowDown className="h-3 w-3" />
|
<ArrowDown className="h-3 w-3" />
|
||||||
))}
|
))}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
),
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
<span className="mx-1 h-5 w-px bg-white/30" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
variant={hideUnseen ? "secondary" : "ghost"}
|
||||||
|
size="sm"
|
||||||
|
className="h-7 text-xs gap-1"
|
||||||
|
title={
|
||||||
|
hideUnseen ? "Show all entries" : "Gray out unseen entries"
|
||||||
|
}
|
||||||
|
onClick={() => setHideUnseen(collectionId, !hideUnseen)}
|
||||||
|
>
|
||||||
|
{hideUnseen ? (
|
||||||
|
<Eye className="h-3 w-3" />
|
||||||
|
) : (
|
||||||
|
<EyeOff className="h-3 w-3" />
|
||||||
|
)}
|
||||||
|
{hideUnseen ? "Show seen" : "Show all"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -264,6 +289,7 @@ export function CollectionDetailsPage() {
|
|||||||
entries={sortedEntries}
|
entries={sortedEntries}
|
||||||
isLoading={false}
|
isLoading={false}
|
||||||
collectionId={collection.id}
|
collectionId={collection.id}
|
||||||
|
grayOutUnseen={hideUnseen}
|
||||||
onRemoveFromCollection={(entryId) =>
|
onRemoveFromCollection={(entryId) =>
|
||||||
removeEntryFromCollection.mutate({
|
removeEntryFromCollection.mutate({
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
|
|||||||
@@ -1,20 +1,32 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from "zustand";
|
||||||
import { persist } from 'zustand/middleware';
|
import { persist } from "zustand/middleware";
|
||||||
|
|
||||||
export type CollectionSortField = 'order' | 'year' | 'title' | 'rating';
|
export type CollectionSortField = "order" | "year" | "title" | "rating";
|
||||||
export type SortDir = 'asc' | 'desc';
|
export type SortDir = "asc" | "desc";
|
||||||
|
|
||||||
interface CollectionSortPref {
|
interface CollectionSortPref {
|
||||||
field: CollectionSortField;
|
field: CollectionSortField;
|
||||||
dir: SortDir;
|
dir: SortDir;
|
||||||
|
hideUnseen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CollectionSortState {
|
interface CollectionSortState {
|
||||||
/** Map of collection id -> sort preference */
|
/** Map of collection id -> sort preference */
|
||||||
prefs: Record<number, CollectionSortPref>;
|
prefs: Record<number, CollectionSortPref>;
|
||||||
setSort: (collectionId: number, field: CollectionSortField, dir: SortDir) => void;
|
setSort: (
|
||||||
|
collectionId: number,
|
||||||
|
field: CollectionSortField,
|
||||||
|
dir: SortDir,
|
||||||
|
) => void;
|
||||||
|
setHideUnseen: (collectionId: number, hideUnseen: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultPref: CollectionSortPref = {
|
||||||
|
field: "order",
|
||||||
|
dir: "asc",
|
||||||
|
hideUnseen: false,
|
||||||
|
};
|
||||||
|
|
||||||
export const useCollectionSortStore = create<CollectionSortState>()(
|
export const useCollectionSortStore = create<CollectionSortState>()(
|
||||||
persist(
|
persist(
|
||||||
(set) => ({
|
(set) => ({
|
||||||
@@ -23,12 +35,26 @@ export const useCollectionSortStore = create<CollectionSortState>()(
|
|||||||
set((state) => ({
|
set((state) => ({
|
||||||
prefs: {
|
prefs: {
|
||||||
...state.prefs,
|
...state.prefs,
|
||||||
[collectionId]: { field, dir },
|
[collectionId]: {
|
||||||
|
...(state.prefs[collectionId] || defaultPref),
|
||||||
|
field,
|
||||||
|
dir,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
setHideUnseen: (collectionId, hideUnseen) =>
|
||||||
|
set((state) => ({
|
||||||
|
prefs: {
|
||||||
|
...state.prefs,
|
||||||
|
[collectionId]: {
|
||||||
|
...(state.prefs[collectionId] || defaultPref),
|
||||||
|
hideUnseen,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: 'showy-collection-sort',
|
name: "showy-collection-sort",
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
Reference in new issue
Block a user