[FA-misc] Various UI updates
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import * as NavigationMenu from '$lib/components/ui/navigation-menu';
|
||||
import AuthenticationDisplay from './AuthenticationDisplay.svelte';
|
||||
import SearchBar from './SearchBar.svelte';
|
||||
|
||||
let pathname = $state(typeof window !== 'undefined' ? window.location.pathname : '/');
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
</NavigationMenu.List>
|
||||
</NavigationMenu.Root>
|
||||
<div class="flex-1"></div>
|
||||
<Input type="search" placeholder="Search..." class="max-w-xs" />
|
||||
<SearchBar />
|
||||
<AuthenticationDisplay />
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts" module>
|
||||
import type { NovelsQuery, NovelStatus } from '$lib/graphql/__generated__/graphql';
|
||||
import { SystemTags } from '$lib/constants/systemTags';
|
||||
|
||||
export type NovelNode = NonNullable<NonNullable<NovelsQuery['novels']>['edges']>[number]['node'];
|
||||
|
||||
@@ -55,6 +56,8 @@
|
||||
const status = $derived(novel.rawStatus ?? 'UNKNOWN');
|
||||
const statusColor = $derived(statusColors[status]);
|
||||
const statusLabel = $derived(statusLabels[status]);
|
||||
|
||||
const isNsfw = $derived(novel.tags?.some((tag) => tag.key === SystemTags.Nsfw) ?? false);
|
||||
</script>
|
||||
|
||||
<a
|
||||
@@ -76,6 +79,9 @@
|
||||
>
|
||||
{statusLabel}
|
||||
</Badge>
|
||||
{#if isNsfw}
|
||||
<Badge class="absolute top-9 right-2 bg-red-600 text-white shadow-sm">NSFW</Badge>
|
||||
{/if}
|
||||
</div>
|
||||
<CardHeader class="space-y-2 pt-4">
|
||||
<CardTitle class="line-clamp-2 text-lg leading-tight" title={title}>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts" module>
|
||||
import type { NovelQuery, NovelStatus, Language } from '$lib/graphql/__generated__/graphql';
|
||||
import { TagType } from '$lib/graphql/__generated__/graphql';
|
||||
import { SystemTags } from '$lib/constants/systemTags';
|
||||
|
||||
export type NovelNode = NonNullable<NonNullable<NovelQuery['novels']>['nodes']>[number];
|
||||
|
||||
@@ -80,6 +82,8 @@
|
||||
};
|
||||
let viewerOpen = $state(false);
|
||||
let viewerIndex = $state(0);
|
||||
let activeTab = $state('chapters');
|
||||
let galleryLoaded = $state(false);
|
||||
|
||||
const DESCRIPTION_PREVIEW_LENGTH = 300;
|
||||
|
||||
@@ -110,6 +114,10 @@
|
||||
|
||||
const chapterCount = $derived(novel?.chapters?.length ?? 0);
|
||||
|
||||
// Filter out system tags for display, check for NSFW
|
||||
const displayTags = $derived(novel?.tags?.filter((tag) => tag.tagType !== TagType.System) ?? []);
|
||||
const isNsfw = $derived(novel?.tags?.some((tag) => tag.key === SystemTags.Nsfw) ?? false);
|
||||
|
||||
const canRefresh = $derived(() => {
|
||||
if (status === 'COMPLETED') return false;
|
||||
if (!lastUpdated) return true;
|
||||
@@ -146,6 +154,14 @@
|
||||
});
|
||||
|
||||
const currentImage = $derived(galleryImages[viewerIndex]);
|
||||
const imageCount = $derived(galleryImages.length);
|
||||
|
||||
// Load gallery images when tab is first activated
|
||||
$effect(() => {
|
||||
if (activeTab === 'gallery' && !galleryLoaded) {
|
||||
galleryLoaded = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Image viewer functions
|
||||
function openImageViewer(index: number) {
|
||||
@@ -321,6 +337,9 @@
|
||||
<!-- Badges -->
|
||||
<div class="flex flex-wrap gap-2 items-center">
|
||||
<Badge class={statusColor}>{statusLabel}</Badge>
|
||||
{#if isNsfw}
|
||||
<Badge class="bg-red-600 text-white">NSFW</Badge>
|
||||
{/if}
|
||||
<Badge variant="outline">{languageLabel}</Badge>
|
||||
{#if $isAuthenticated}
|
||||
<TooltipProvider>
|
||||
@@ -390,9 +409,9 @@
|
||||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
{#if novel.tags && novel.tags.length > 0}
|
||||
{#if displayTags.length > 0}
|
||||
<div class="flex flex-wrap gap-1.5 pt-1">
|
||||
{#each novel.tags as tag (tag.key)}
|
||||
{#each displayTags as tag (tag.key)}
|
||||
<Badge
|
||||
variant="secondary"
|
||||
href="/novels?tags={tag.key}"
|
||||
@@ -435,20 +454,20 @@
|
||||
|
||||
<!-- Tabbed Content -->
|
||||
<Card>
|
||||
<Tabs value="chapters" class="w-full">
|
||||
<Tabs bind:value={activeTab} class="w-full">
|
||||
<CardHeader class="pb-0">
|
||||
<TabsList class="grid w-full grid-cols-3 bg-muted/50 p-1 rounded-lg">
|
||||
<TabsTrigger
|
||||
value="chapters"
|
||||
class="rounded-md data-[state=active]:bg-background data-[state=active]:shadow-sm px-3 py-1.5 text-sm font-medium transition-all"
|
||||
>
|
||||
Chapters
|
||||
Chapters ({chapterCount})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="gallery"
|
||||
class="rounded-md data-[state=active]:bg-background data-[state=active]:shadow-sm px-3 py-1.5 text-sm font-medium transition-all"
|
||||
>
|
||||
Gallery
|
||||
Gallery ({imageCount})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="bookmarks"
|
||||
@@ -498,7 +517,7 @@
|
||||
<p class="text-muted-foreground text-sm py-4 text-center">
|
||||
No images available.
|
||||
</p>
|
||||
{:else}
|
||||
{:else if galleryLoaded}
|
||||
<div class="grid grid-cols-3 sm:grid-cols-4 md:grid-cols-5 gap-2">
|
||||
{#each galleryImages as image, index (image.src)}
|
||||
<button
|
||||
@@ -506,13 +525,20 @@
|
||||
onclick={() => openImageViewer(index)}
|
||||
class="relative aspect-square overflow-hidden rounded-md bg-muted/50 hover:ring-2 ring-primary transition-all"
|
||||
>
|
||||
<img src={image.src} alt={image.alt} class="h-full w-full object-cover" />
|
||||
<img src={image.src} alt={image.alt} class="h-full w-full object-cover" loading="lazy" />
|
||||
{#if image.isCover}
|
||||
<Badge class="absolute top-1 left-1 text-xs">Cover</Badge>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex items-center justify-center py-8">
|
||||
<div
|
||||
class="border-primary h-8 w-8 animate-spin rounded-full border-2 border-t-transparent"
|
||||
aria-label="Loading gallery"
|
||||
></div>
|
||||
</div>
|
||||
{/if}
|
||||
</TabsContent>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Badge } from '$lib/components/ui/badge';
|
||||
import { type NovelFilters, hasActiveFilters, EMPTY_FILTERS } from '$lib/utils/filterParams';
|
||||
import { type NovelFilters, type SortField, type SortDirection, hasActiveFilters, EMPTY_FILTERS } from '$lib/utils/filterParams';
|
||||
import { NovelStatus, type NovelTagDto } from '$lib/graphql/__generated__/graphql';
|
||||
|
||||
interface Props {
|
||||
@@ -34,6 +34,19 @@
|
||||
{ value: NovelStatus.Unknown, label: 'Unknown' }
|
||||
];
|
||||
|
||||
// Sort options
|
||||
const sortOptions: { value: `${SortField}-${SortDirection}`; label: string }[] = [
|
||||
{ value: 'lastUpdatedTime-DESC', label: 'Recently Updated' },
|
||||
{ value: 'lastUpdatedTime-ASC', label: 'Oldest Updated' },
|
||||
{ value: 'createdTime-DESC', label: 'Recently Added' },
|
||||
{ value: 'createdTime-ASC', label: 'Oldest Added' },
|
||||
{ value: 'name-ASC', label: 'Name (A-Z)' },
|
||||
{ value: 'name-DESC', label: 'Name (Z-A)' }
|
||||
];
|
||||
|
||||
// Current sort value as combined string for the select
|
||||
const currentSortValue = $derived(`${filters.sort.field}-${filters.sort.direction}` as const);
|
||||
|
||||
// Derived state for display
|
||||
const selectedStatusLabels = $derived(
|
||||
filters.statuses.map((s) => statusOptions.find((o) => o.value === s)?.label ?? s).join(', ')
|
||||
@@ -71,6 +84,12 @@
|
||||
onFilterChange({ ...filters, tags: selected });
|
||||
}
|
||||
|
||||
// Sort selection handler
|
||||
function handleSortChange(value: string) {
|
||||
const [field, direction] = value.split('-') as [SortField, SortDirection];
|
||||
onFilterChange({ ...filters, sort: { field, direction } });
|
||||
}
|
||||
|
||||
// Clear all filters
|
||||
function clearFilters() {
|
||||
searchInput = '';
|
||||
@@ -196,6 +215,41 @@
|
||||
</Select.Root>
|
||||
{/if}
|
||||
|
||||
<!-- Sort Dropdown -->
|
||||
<Select.Root
|
||||
type="single"
|
||||
value={currentSortValue}
|
||||
onValueChange={(v) => v && handleSortChange(v)}
|
||||
>
|
||||
<Select.Trigger
|
||||
class="border-input bg-background ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex h-9 min-w-[160px] items-center justify-between gap-2 rounded-md border px-3 py-2 text-sm shadow-sm focus:outline-none focus:ring-1 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
>
|
||||
<span class="truncate text-left">
|
||||
{sortOptions.find((o) => o.value === currentSortValue)?.label ?? 'Sort by'}
|
||||
</span>
|
||||
<ChevronDown class="h-4 w-4 opacity-50" />
|
||||
</Select.Trigger>
|
||||
<Select.Content
|
||||
class="bg-popover text-popover-foreground z-50 max-h-60 min-w-[160px] overflow-auto rounded-md border p-1 shadow-md"
|
||||
>
|
||||
{#each sortOptions as option (option.value)}
|
||||
<Select.Item
|
||||
value={option.value}
|
||||
class="hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
||||
>
|
||||
{#snippet children({ selected })}
|
||||
<div class="flex h-4 w-4 items-center justify-center">
|
||||
{#if selected}
|
||||
<Check class="h-3 w-3" />
|
||||
{/if}
|
||||
</div>
|
||||
<span>{option.label}</span>
|
||||
{/snippet}
|
||||
</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
|
||||
<!-- Clear Filters Button -->
|
||||
{#if hasActiveFilters(filters)}
|
||||
<Button variant="outline" size="sm" onclick={clearFilters} class="gap-1">
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
parseFiltersFromURL,
|
||||
syncFiltersToURL,
|
||||
filtersToGraphQLWhere,
|
||||
sortToGraphQLOrder,
|
||||
hasActiveFilters,
|
||||
EMPTY_FILTERS
|
||||
} from '$lib/utils/filterParams';
|
||||
@@ -52,8 +53,9 @@
|
||||
|
||||
try {
|
||||
const where = filtersToGraphQLWhere(filters);
|
||||
const order = sortToGraphQLOrder(filters.sort);
|
||||
const result = await client
|
||||
.query(NovelsDocument, { first: PAGE_SIZE, after, where })
|
||||
.query(NovelsDocument, { first: PAGE_SIZE, after, where, order })
|
||||
.toPromise();
|
||||
|
||||
if (result.error) {
|
||||
@@ -116,20 +118,13 @@
|
||||
<Card class="shadow-md shadow-primary/10">
|
||||
<CardHeader>
|
||||
<div class="flex items-center justify-between">
|
||||
<CardTitle>Novels</CardTitle>
|
||||
<CardTitle>Controls</CardTitle>
|
||||
{#if $isAuthenticated}
|
||||
<Button variant="outline" onclick={() => (showImportModal = true)}>
|
||||
Import Novel
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-muted-foreground text-sm">
|
||||
{#if hasActiveFilters(filters)}
|
||||
Showing filtered results
|
||||
{:else}
|
||||
Browse all novels
|
||||
{/if}
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<NovelFilters {filters} onFilterChange={handleFilterChange} availableTags={availableTags()} />
|
||||
|
||||
@@ -18,7 +18,12 @@
|
||||
error = null;
|
||||
|
||||
try {
|
||||
const result = await client.query(NovelsDocument, { first: 5 }).toPromise();
|
||||
const result = await client
|
||||
.query(NovelsDocument, {
|
||||
first: 5,
|
||||
order: [{ lastUpdatedTime: 'DESC' }]
|
||||
})
|
||||
.toPromise();
|
||||
|
||||
if (result.error) {
|
||||
error = result.error.message;
|
||||
|
||||
141
fictionarchive-web-astro/src/lib/components/SearchBar.svelte
Normal file
141
fictionarchive-web-astro/src/lib/components/SearchBar.svelte
Normal file
@@ -0,0 +1,141 @@
|
||||
<script lang="ts">
|
||||
import Search from '@lucide/svelte/icons/search';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { NovelsDocument, type NovelDto } from '$lib/graphql/__generated__/graphql';
|
||||
import { client } from '$lib/graphql/client';
|
||||
|
||||
let searchTerm = $state('');
|
||||
let results = $state<NovelDto[]>([]);
|
||||
let isOpen = $state(false);
|
||||
let fetching = $state(false);
|
||||
let searchTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
let containerRef: HTMLDivElement;
|
||||
|
||||
async function fetchResults(term: string) {
|
||||
if (!term.trim()) {
|
||||
results = [];
|
||||
isOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
fetching = true;
|
||||
try {
|
||||
const result = await client
|
||||
.query(NovelsDocument, {
|
||||
first: 4,
|
||||
where: { name: { contains: term } }
|
||||
})
|
||||
.toPromise();
|
||||
|
||||
if (result.data?.novels?.edges) {
|
||||
results = result.data.novels.edges.map((edge) => edge.node);
|
||||
isOpen = results.length > 0;
|
||||
} else {
|
||||
results = [];
|
||||
isOpen = false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Search error:', error);
|
||||
results = [];
|
||||
isOpen = false;
|
||||
} finally {
|
||||
fetching = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleInput(value: string) {
|
||||
searchTerm = value;
|
||||
if (searchTimeout) clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(() => {
|
||||
fetchResults(value);
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'Enter' && searchTerm.trim()) {
|
||||
event.preventDefault();
|
||||
isOpen = false;
|
||||
window.location.href = `/novels?search=${encodeURIComponent(searchTerm.trim())}`;
|
||||
} else if (event.key === 'Escape') {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleResultClick() {
|
||||
isOpen = false;
|
||||
searchTerm = '';
|
||||
results = [];
|
||||
}
|
||||
|
||||
function handleFocus() {
|
||||
if (results.length > 0) {
|
||||
isOpen = true;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
if (containerRef && !containerRef.contains(event.target as Node)) {
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getCoverSrc(novel: NovelDto): string | undefined {
|
||||
return novel.coverImage?.newPath ?? novel.coverImage?.originalPath ?? undefined;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener('click', handleClickOutside);
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="relative max-w-xs" bind:this={containerRef}>
|
||||
<div class="relative">
|
||||
<Search class="absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
type="search"
|
||||
placeholder="Search..."
|
||||
class="pl-8"
|
||||
value={searchTerm}
|
||||
oninput={(e) => handleInput(e.currentTarget.value)}
|
||||
onkeydown={handleKeydown}
|
||||
onfocus={handleFocus}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{#if isOpen}
|
||||
<div
|
||||
class="absolute top-full left-0 right-0 z-50 mt-1 overflow-hidden rounded-md border bg-white shadow-lg dark:bg-gray-900"
|
||||
>
|
||||
{#if fetching}
|
||||
<div class="px-4 py-3 text-sm text-muted-foreground">Searching...</div>
|
||||
{:else if results.length === 0}
|
||||
<div class="px-4 py-3 text-sm text-muted-foreground">No results found</div>
|
||||
{:else}
|
||||
{#each results as novel (novel.id)}
|
||||
<a
|
||||
href="/novels/{novel.id}"
|
||||
class="flex items-center gap-3 px-3 py-2 hover:bg-muted transition-colors"
|
||||
onclick={handleResultClick}
|
||||
>
|
||||
{#if getCoverSrc(novel)}
|
||||
<img
|
||||
src={getCoverSrc(novel)}
|
||||
alt=""
|
||||
class="h-12 w-9 rounded object-cover flex-shrink-0"
|
||||
loading="lazy"
|
||||
/>
|
||||
{:else}
|
||||
<div class="h-12 w-9 rounded bg-muted flex-shrink-0"></div>
|
||||
{/if}
|
||||
<span class="text-sm font-medium truncate">{novel.name}</span>
|
||||
</a>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
Reference in New Issue
Block a user