mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Feat: Basic ExtensionLibrary Filter
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { ArrowLeft, MagnifyingGlass, GearSix, Swap } from "phosphor-svelte";
|
import { ArrowLeft, MagnifyingGlass, GearSix, Swap, Funnel, Check } from "phosphor-svelte";
|
||||||
import Thumbnail from "@shared/manga/Thumbnail.svelte";
|
import Thumbnail from "@shared/manga/Thumbnail.svelte";
|
||||||
import { resolvedCover } from "@core/cover/coverResolver";
|
import { resolvedCover } from "@core/cover/coverResolver";
|
||||||
import { gql } from "@api/client";
|
import { gql } from "@api/client";
|
||||||
@@ -29,14 +29,24 @@
|
|||||||
let loading = $state(true);
|
let loading = $state(true);
|
||||||
let search = $state("");
|
let search = $state("");
|
||||||
|
|
||||||
|
type ContentFilter = "unread" | "downloaded";
|
||||||
|
let activeFilters = $state<Partial<Record<ContentFilter, boolean>>>({});
|
||||||
|
let filterOpen = $state(false);
|
||||||
|
|
||||||
|
const hasActiveFilters = $derived(Object.values(activeFilters).some(Boolean));
|
||||||
|
|
||||||
let migrateTarget: { sourceId: string; sourceName: string; iconUrl: string; manga: LibraryManga[] } | null = $state(null);
|
let migrateTarget: { sourceId: string; sourceName: string; iconUrl: string; manga: LibraryManga[] } | null = $state(null);
|
||||||
|
|
||||||
const allManga = $derived(groups.flatMap(g => g.manga));
|
const allManga = $derived(groups.flatMap(g => g.manga));
|
||||||
const filtered = $derived(
|
|
||||||
search.trim()
|
const filtered = $derived((() => {
|
||||||
? allManga.filter(m => m.title.toLowerCase().includes(search.toLowerCase()))
|
let items = allManga;
|
||||||
: allManga
|
const q = search.trim().toLowerCase();
|
||||||
);
|
if (q) items = items.filter(m => m.title.toLowerCase().includes(q));
|
||||||
|
if (activeFilters.unread) items = items.filter(m => m.unreadCount > 0);
|
||||||
|
if (activeFilters.downloaded) items = items.filter(m => m.downloadCount > 0);
|
||||||
|
return items;
|
||||||
|
})());
|
||||||
|
|
||||||
let sourceNodes: SourceNode[] = $state([]);
|
let sourceNodes: SourceNode[] = $state([]);
|
||||||
|
|
||||||
@@ -56,6 +66,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleFilter(f: ContentFilter) {
|
||||||
|
activeFilters = { ...activeFilters, [f]: !activeFilters[f] };
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearFilters() {
|
||||||
|
activeFilters = {};
|
||||||
|
}
|
||||||
|
|
||||||
function openMigrate(group: SourceLibrary) {
|
function openMigrate(group: SourceLibrary) {
|
||||||
const node = sourceNodes.find(s => s.id === group.sourceId);
|
const node = sourceNodes.find(s => s.id === group.sourceId);
|
||||||
migrateTarget = {
|
migrateTarget = {
|
||||||
@@ -65,6 +83,20 @@
|
|||||||
manga: group.manga,
|
manga: group.manga,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!filterOpen) return;
|
||||||
|
function onOutside(e: MouseEvent) {
|
||||||
|
if (!(e.target as HTMLElement).closest(".filter-wrap")) filterOpen = false;
|
||||||
|
}
|
||||||
|
setTimeout(() => document.addEventListener("mousedown", onOutside, true), 0);
|
||||||
|
return () => document.removeEventListener("mousedown", onOutside, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const CONTENT_FILTERS: [ContentFilter, string][] = [
|
||||||
|
["unread", "Unread"],
|
||||||
|
["downloaded", "Downloaded"],
|
||||||
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="root">
|
<div class="root">
|
||||||
@@ -80,18 +112,57 @@
|
|||||||
<span class="title">{extensionName}</span>
|
<span class="title">{extensionName}</span>
|
||||||
</div>
|
</div>
|
||||||
{#if !loading}
|
{#if !loading}
|
||||||
<span class="count-badge">{allManga.length}</span>
|
<span class="count-badge">{filtered.length}{filtered.length !== allManga.length ? ` / ${allManga.length}` : ""}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
<div class="header-right">
|
||||||
<div class="search-wrap">
|
<div class="search-wrap">
|
||||||
<MagnifyingGlass size={12} class="search-icon" weight="light" />
|
<MagnifyingGlass size={12} class="search-icon" weight="light" />
|
||||||
<input class="search" placeholder="Search" bind:value={search} autocomplete="off" />
|
<input class="search" placeholder="Search" bind:value={search} autocomplete="off" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="filter-wrap">
|
||||||
|
<button
|
||||||
|
class="filter-btn"
|
||||||
|
class:filter-btn-active={hasActiveFilters}
|
||||||
|
title="Filter"
|
||||||
|
onclick={() => filterOpen = !filterOpen}
|
||||||
|
>
|
||||||
|
<Funnel size={13} weight={hasActiveFilters ? "fill" : "bold"} />
|
||||||
|
</button>
|
||||||
|
{#if filterOpen}
|
||||||
|
<div class="filter-panel" role="menu">
|
||||||
|
<div class="panel-header">
|
||||||
|
<span class="panel-heading">Filter</span>
|
||||||
|
{#if hasActiveFilters}
|
||||||
|
<button class="panel-clear-btn" onclick={clearFilters}>Clear all</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="panel-divider"></div>
|
||||||
|
<p class="panel-label">Content</p>
|
||||||
|
{#each CONTENT_FILTERS as [f, label]}
|
||||||
|
<button
|
||||||
|
class="panel-item"
|
||||||
|
class:panel-item-active={activeFilters[f]}
|
||||||
|
role="menuitem"
|
||||||
|
onclick={() => toggleFilter(f)}
|
||||||
|
>
|
||||||
|
<span class="panel-check" class:panel-check-on={activeFilters[f]}>
|
||||||
|
{#if activeFilters[f]}<Check size={9} weight="bold" />{/if}
|
||||||
|
</span>
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if sources.length > 0}
|
{#if sources.length > 0}
|
||||||
<button class="header-btn" onclick={onSettings} title="Extension settings">
|
<button class="header-btn" onclick={onSettings} title="Extension settings">
|
||||||
<GearSix size={14} weight="bold" />
|
<GearSix size={14} weight="bold" />
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{#if loading}
|
{#if loading}
|
||||||
@@ -181,6 +252,7 @@
|
|||||||
:global(.header-icon) { width: 24px; height: 24px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; background: var(--bg-raised); }
|
:global(.header-icon) { width: 24px; height: 24px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; background: var(--bg-raised); }
|
||||||
|
|
||||||
.header { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-bottom: 1px solid var(--border-dim); flex-shrink: 0; }
|
.header { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-bottom: 1px solid var(--border-dim); flex-shrink: 0; }
|
||||||
|
.header-right { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }
|
||||||
|
|
||||||
.header-btn { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--radius-md); color: var(--text-faint); flex-shrink: 0; transition: color var(--t-base), background var(--t-base); }
|
.header-btn { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: var(--radius-md); color: var(--text-faint); flex-shrink: 0; transition: color var(--t-base), background var(--t-base); }
|
||||||
.header-btn:hover { color: var(--text-primary); background: var(--bg-raised); }
|
.header-btn:hover { color: var(--text-primary); background: var(--bg-raised); }
|
||||||
@@ -191,12 +263,31 @@
|
|||||||
|
|
||||||
.count-badge { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide); padding: 2px 8px; border-radius: var(--radius-sm); background: var(--bg-overlay); border: 1px solid var(--border-dim); color: var(--text-muted); flex-shrink: 0; }
|
.count-badge { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide); padding: 2px 8px; border-radius: var(--radius-sm); background: var(--bg-overlay); border: 1px solid var(--border-dim); color: var(--text-muted); flex-shrink: 0; }
|
||||||
|
|
||||||
.search-wrap { position: relative; display: flex; align-items: center; margin-left: auto; }
|
.search-wrap { position: relative; display: flex; align-items: center; }
|
||||||
.search-wrap :global(.search-icon) { position: absolute; left: 9px; color: var(--text-faint); pointer-events: none; }
|
.search-wrap :global(.search-icon) { position: absolute; left: 9px; color: var(--text-faint); pointer-events: none; }
|
||||||
.search { background: var(--bg-raised); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 5px 10px 5px 26px; color: var(--text-primary); font-size: var(--text-sm); width: 160px; outline: none; transition: border-color var(--t-base); }
|
.search { background: var(--bg-raised); border: 1px solid var(--border-dim); border-radius: var(--radius-md); padding: 5px 10px 5px 26px; color: var(--text-primary); font-size: var(--text-sm); width: 160px; outline: none; transition: border-color var(--t-base); }
|
||||||
.search::placeholder { color: var(--text-faint); }
|
.search::placeholder { color: var(--text-faint); }
|
||||||
.search:focus { border-color: var(--border-strong); }
|
.search:focus { border-color: var(--border-strong); }
|
||||||
|
|
||||||
|
.filter-wrap { position: relative; }
|
||||||
|
.filter-btn { display: flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: var(--radius-md); border: 1px solid var(--border-dim); background: var(--bg-raised); color: var(--text-faint); cursor: pointer; flex-shrink: 0; transition: color var(--t-base), border-color var(--t-base), background var(--t-base); }
|
||||||
|
.filter-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }
|
||||||
|
.filter-btn-active { color: var(--accent-fg); border-color: var(--accent-dim); background: var(--accent-muted); }
|
||||||
|
|
||||||
|
.filter-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 9999; min-width: 200px; background: var(--bg-raised); border: 1px solid var(--border-base); border-radius: var(--radius-lg); padding: var(--sp-1); box-shadow: 0 8px 32px rgba(0,0,0,0.5); animation: fadeIn 0.1s ease both; }
|
||||||
|
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 4px; }
|
||||||
|
.panel-heading { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); color: var(--text-secondary); font-weight: var(--weight-medium, 500); }
|
||||||
|
.panel-clear-btn { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wide); color: var(--text-faint); background: none; border: none; cursor: pointer; padding: 0; transition: color var(--t-base); }
|
||||||
|
.panel-clear-btn:hover { color: var(--color-error); }
|
||||||
|
.panel-divider { height: 1px; background: var(--border-dim); margin: 4px 2px; }
|
||||||
|
.panel-label { font-family: var(--font-ui); font-size: var(--text-2xs); letter-spacing: var(--tracking-wider); text-transform: uppercase; color: var(--text-faint); padding: 4px 8px 8px; }
|
||||||
|
.panel-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: 7px 10px; border-radius: var(--radius-sm); border: none; background: transparent; color: var(--text-muted); font-family: var(--font-ui); font-size: var(--text-xs); cursor: pointer; text-align: left; transition: background var(--t-base), color var(--t-base); }
|
||||||
|
.panel-item:hover { background: var(--bg-overlay); color: var(--text-primary); }
|
||||||
|
.panel-item-active { color: var(--accent-fg); background: var(--accent-muted); font-weight: var(--weight-medium, 500); }
|
||||||
|
.panel-item-active:hover { background: var(--accent-dim); }
|
||||||
|
.panel-check { width: 13px; height: 13px; border-radius: 2px; border: 1px solid var(--border-strong); background: transparent; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: var(--bg-base); transition: background var(--t-base), border-color var(--t-base); }
|
||||||
|
.panel-check-on { background: var(--accent); border-color: var(--accent); }
|
||||||
|
|
||||||
.content { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-6) var(--sp-6); will-change: scroll-position; display: flex; flex-direction: column; gap: var(--sp-3); }
|
.content { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-6) var(--sp-6); will-change: scroll-position; display: flex; flex-direction: column; gap: var(--sp-3); }
|
||||||
|
|
||||||
.source-groups { display: flex; flex-direction: column; gap: var(--sp-1); }
|
.source-groups { display: flex; flex-direction: column; gap: var(--sp-1); }
|
||||||
@@ -237,4 +328,6 @@
|
|||||||
.title-skeleton { height: 12px; margin-top: var(--sp-2); width: 80%; border-radius: var(--radius-sm); }
|
.title-skeleton { height: 12px; margin-top: var(--sp-2); width: 80%; border-radius: var(--radius-sm); }
|
||||||
|
|
||||||
.empty { display: flex; align-items: center; justify-content: center; height: 60%; color: var(--text-muted); font-size: var(--text-sm); }
|
.empty { display: flex; align-items: center; justify-content: center; height: 60%; color: var(--text-muted); font-size: var(--text-sm); }
|
||||||
|
|
||||||
|
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user