Compare commits
16 Commits
feature/FA
...
feature/FA
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbc0b5ec7d | ||
|
|
1e374e6eeb | ||
| c710f14257 | |||
|
|
6c10077505 | ||
| fecb3e6f43 | |||
|
|
f0ea71e00e | ||
| 45afb57df5 | |||
|
|
6fd76f6787 | ||
| baad092f07 | |||
|
|
4fb34bdef7 | ||
| 89a2cf6db1 | |||
|
|
f830773af5 | ||
| 7185b95c65 | |||
| ac48889f4c | |||
| 16004ad938 | |||
| 89dff0980b |
@@ -35,8 +35,16 @@ namespace FictionArchive.Service.FileService.Controllers
|
||||
BucketName = _s3Configuration.Bucket,
|
||||
Key = decodedPath
|
||||
});
|
||||
|
||||
return new FileStreamResult(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
||||
|
||||
Response.Headers.CacheControl = "public, max-age=604800"; // 7 days
|
||||
Response.Headers.LastModified = s3Response.LastModified?.ToString("R");
|
||||
|
||||
if (!string.IsNullOrEmpty(s3Response.ETag))
|
||||
{
|
||||
Response.Headers.ETag = s3Response.ETag;
|
||||
}
|
||||
|
||||
return File(s3Response.ResponseStream, s3Response.Headers.ContentType);
|
||||
}
|
||||
catch (AmazonS3Exception e)
|
||||
{
|
||||
|
||||
@@ -44,7 +44,6 @@ public class Program
|
||||
#region GraphQL
|
||||
|
||||
builder.Services.AddDefaultGraphQl<Query, Mutation>()
|
||||
.ModifyCostOptions(opt => opt.MaxFieldCost = 5000)
|
||||
.AddAuthorization();
|
||||
|
||||
#endregion
|
||||
@@ -63,12 +62,14 @@ public class Program
|
||||
builder.Services.AddHttpClient<NovelpiaAuthMessageHandler>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("https://novelpia.com");
|
||||
});
|
||||
})
|
||||
.AddStandardResilienceHandler();
|
||||
builder.Services.AddHttpClient<ISourceAdapter, NovelpiaAdapter>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri("https://novelpia.com");
|
||||
})
|
||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>();
|
||||
.AddHttpMessageHandler<NovelpiaAuthMessageHandler>()
|
||||
.AddStandardResilienceHandler();
|
||||
|
||||
builder.Services.Configure<NovelUpdateServiceConfiguration>(builder.Configuration.GetSection("UpdateService"));
|
||||
builder.Services.AddTransient<NovelUpdateService>();
|
||||
|
||||
@@ -281,15 +281,16 @@ public class NovelUpdateService
|
||||
// Step 3: Check for existing novel by ExternalId + Source.Key
|
||||
var existingNovel = await _dbContext.Novels
|
||||
.Include(n => n.Author)
|
||||
.ThenInclude(a => a.Name)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.ThenInclude(a => a.Name)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.Include(n => n.Source)
|
||||
.Include(n => n.Name)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.Include(n => n.Description)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.ThenInclude(lk => lk.Texts)
|
||||
.Include(n => n.Tags)
|
||||
.Include(n => n.Chapters)
|
||||
.Include(n => n.Chapters).ThenInclude(chapter => chapter.Body)
|
||||
.ThenInclude(localizationKey => localizationKey.Texts)
|
||||
.Include(n => n.CoverImage)
|
||||
.FirstOrDefaultAsync(n =>
|
||||
n.ExternalId == metadata.ExternalId &&
|
||||
|
||||
@@ -22,6 +22,7 @@ public static class GraphQLExtensions
|
||||
.AddErrorFilter<LoggingErrorFilter>()
|
||||
.AddType<UnsignedIntType>()
|
||||
.AddType<InstantType>()
|
||||
.ModifyCostOptions(opt => opt.MaxFieldCost = 10000)
|
||||
.AddMutationConventions(applyToAllMutations: true)
|
||||
.AddFiltering(opt => opt.AddDefaults().BindRuntimeType<uint, UnsignedIntOperationFilterInputType>())
|
||||
.AddSorting()
|
||||
|
||||
@@ -25,10 +25,12 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="3.2.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="9.0.4" />
|
||||
<PackageReference Include="Polly" Version="8.6.5" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="7.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -74,6 +74,8 @@
|
||||
|
||||
if (result.data?.chapter) {
|
||||
chapter = result.data.chapter;
|
||||
// Update the page title with chapter info
|
||||
document.title = `${chapter.novelName} - ${chapter.order}`;
|
||||
} else {
|
||||
error = 'Chapter not found';
|
||||
}
|
||||
@@ -155,10 +157,9 @@
|
||||
<Card>
|
||||
<CardContent class="px-6 py-8 md:px-12">
|
||||
<article
|
||||
class="prose prose-lg dark:prose-invert mx-auto max-w-none whitespace-pre-line
|
||||
prose-p:text-foreground prose-p:mb-4 prose-p:leading-relaxed
|
||||
class="prose prose-lg dark:prose-invert mx-auto max-w-none
|
||||
prose-headings:text-foreground
|
||||
first:prose-p:mt-0 last:prose-p:mb-0"
|
||||
[&>p]:text-foreground [&>p]:mb-6 [&>p]:leading-relaxed"
|
||||
>
|
||||
{@html sanitizedBody}
|
||||
</article>
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -51,6 +53,9 @@
|
||||
import ChevronDown from '@lucide/svelte/icons/chevron-down';
|
||||
import ChevronUp from '@lucide/svelte/icons/chevron-up';
|
||||
import RefreshCw from '@lucide/svelte/icons/refresh-cw';
|
||||
import X from '@lucide/svelte/icons/x';
|
||||
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
||||
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
||||
|
||||
interface Props {
|
||||
novelId?: string;
|
||||
@@ -66,10 +71,24 @@
|
||||
let refreshError: string | null = $state(null);
|
||||
let refreshSuccess = $state(false);
|
||||
|
||||
// Image viewer state
|
||||
type GalleryImage = {
|
||||
src: string;
|
||||
alt: string;
|
||||
chapterId?: number;
|
||||
chapterOrder?: number;
|
||||
chapterName?: string;
|
||||
isCover: boolean;
|
||||
};
|
||||
let viewerOpen = $state(false);
|
||||
let viewerIndex = $state(0);
|
||||
let activeTab = $state('chapters');
|
||||
let galleryLoaded = $state(false);
|
||||
|
||||
const DESCRIPTION_PREVIEW_LENGTH = 300;
|
||||
|
||||
// Derived values
|
||||
const coverSrc = $derived(novel?.coverImage?.newPath ?? novel?.coverImage?.originalPath);
|
||||
const coverSrc = $derived(novel?.coverImage?.newPath);
|
||||
const status = $derived(novel?.rawStatus ?? 'UNKNOWN');
|
||||
const statusColor = $derived(statusColors[status]);
|
||||
const statusLabel = $derived(statusLabels[status]);
|
||||
@@ -95,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;
|
||||
@@ -102,6 +125,73 @@
|
||||
return lastUpdated.getTime() < sixHoursAgo;
|
||||
});
|
||||
|
||||
// Gallery images - cover + chapter images
|
||||
const galleryImages = $derived.by(() => {
|
||||
const images: GalleryImage[] = [];
|
||||
|
||||
// Add cover image first
|
||||
if (coverSrc && novel) {
|
||||
images.push({ src: coverSrc, alt: `${novel.name} cover`, isCover: true });
|
||||
}
|
||||
|
||||
// Add chapter images
|
||||
for (const chapter of sortedChapters) {
|
||||
for (const img of chapter.images ?? []) {
|
||||
if (img.newPath) {
|
||||
images.push({
|
||||
src: img.newPath,
|
||||
alt: `Image from ${chapter.name}`,
|
||||
chapterId: chapter.id,
|
||||
chapterOrder: chapter.order,
|
||||
chapterName: chapter.name,
|
||||
isCover: false
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return images;
|
||||
});
|
||||
|
||||
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) {
|
||||
viewerIndex = index;
|
||||
viewerOpen = true;
|
||||
}
|
||||
|
||||
function closeViewer() {
|
||||
viewerOpen = false;
|
||||
}
|
||||
|
||||
function nextImage() {
|
||||
if (galleryImages.length > 0) {
|
||||
viewerIndex = (viewerIndex + 1) % galleryImages.length;
|
||||
}
|
||||
}
|
||||
|
||||
function prevImage() {
|
||||
if (galleryImages.length > 0) {
|
||||
viewerIndex = (viewerIndex - 1 + galleryImages.length) % galleryImages.length;
|
||||
}
|
||||
}
|
||||
|
||||
function handleViewerKeydown(e: KeyboardEvent) {
|
||||
if (!viewerOpen) return;
|
||||
if (e.key === 'Escape') closeViewer();
|
||||
if (e.key === 'ArrowRight') nextImage();
|
||||
if (e.key === 'ArrowLeft') prevImage();
|
||||
}
|
||||
|
||||
async function fetchNovel() {
|
||||
if (!novelId) {
|
||||
error = 'No novel ID provided';
|
||||
@@ -125,6 +215,7 @@
|
||||
const nodes = result.data?.novels?.nodes;
|
||||
if (nodes && nodes.length > 0) {
|
||||
novel = nodes[0];
|
||||
document.title = novel.name;
|
||||
} else {
|
||||
error = 'Novel not found';
|
||||
}
|
||||
@@ -247,6 +338,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>
|
||||
@@ -316,9 +410,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}"
|
||||
@@ -361,28 +455,27 @@
|
||||
|
||||
<!-- 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="comments"
|
||||
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 ({imageCount})
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="bookmarks"
|
||||
disabled
|
||||
class="rounded-md data-[state=active]:bg-background data-[state=active]:shadow-sm px-3 py-1.5 text-sm font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
Comments
|
||||
</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="recommendations"
|
||||
disabled
|
||||
class="rounded-md data-[state=active]:bg-background data-[state=active]:shadow-sm px-3 py-1.5 text-sm font-medium transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
Recommendations
|
||||
Bookmarks
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</CardHeader>
|
||||
@@ -420,15 +513,39 @@
|
||||
{/if}
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="comments" class="mt-0">
|
||||
<p class="text-muted-foreground text-sm py-8 text-center">
|
||||
Comments coming soon.
|
||||
</p>
|
||||
<TabsContent value="gallery" class="mt-0">
|
||||
{#if galleryImages.length === 0}
|
||||
<p class="text-muted-foreground text-sm py-4 text-center">
|
||||
No images available.
|
||||
</p>
|
||||
{: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
|
||||
type="button"
|
||||
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" 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>
|
||||
|
||||
<TabsContent value="recommendations" class="mt-0">
|
||||
<TabsContent value="bookmarks" class="mt-0">
|
||||
<p class="text-muted-foreground text-sm py-8 text-center">
|
||||
Recommendations coming soon.
|
||||
Bookmarks coming soon.
|
||||
</p>
|
||||
</TabsContent>
|
||||
</CardContent>
|
||||
@@ -436,3 +553,72 @@
|
||||
</Card>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Image Viewer Modal -->
|
||||
{#if viewerOpen && currentImage}
|
||||
<div
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-black/90 backdrop-blur-sm"
|
||||
onclick={closeViewer}
|
||||
onkeydown={handleViewerKeydown}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
tabindex="-1"
|
||||
>
|
||||
<!-- Close button -->
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="absolute top-4 right-4 text-white hover:bg-white/10"
|
||||
onclick={closeViewer}
|
||||
>
|
||||
<X class="h-6 w-6" />
|
||||
</Button>
|
||||
|
||||
<!-- Navigation arrows -->
|
||||
{#if galleryImages.length > 1}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="absolute left-4 text-white hover:bg-white/10 h-12 w-12"
|
||||
onclick={(e: MouseEvent) => { e.stopPropagation(); prevImage(); }}
|
||||
>
|
||||
<ChevronLeft class="h-8 w-8" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="absolute right-4 top-1/2 -translate-y-1/2 text-white hover:bg-white/10 h-12 w-12"
|
||||
onclick={(e: MouseEvent) => { e.stopPropagation(); nextImage(); }}
|
||||
>
|
||||
<ChevronRight class="h-8 w-8" />
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
<!-- Image container -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="flex flex-col items-center max-w-[90vw] max-h-[90vh]" onclick={(e: MouseEvent) => e.stopPropagation()}>
|
||||
<img
|
||||
src={currentImage.src}
|
||||
alt={currentImage.alt}
|
||||
class="max-w-full max-h-[80vh] object-contain rounded-lg"
|
||||
/>
|
||||
|
||||
<!-- Chapter link (if not cover) -->
|
||||
{#if !currentImage.isCover && currentImage.chapterOrder}
|
||||
<a
|
||||
href="/novels/{novelId}/chapters/{currentImage.chapterOrder}"
|
||||
class="text-white/80 hover:text-white text-sm inline-flex items-center gap-1 mt-3"
|
||||
>
|
||||
From: Ch. {currentImage.chapterOrder} - {currentImage.chapterName}
|
||||
<ExternalLink class="h-3 w-3" />
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
<!-- Image counter -->
|
||||
<div class="text-white/60 text-sm mt-2">
|
||||
{viewerIndex + 1} / {galleryImages.length}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -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>
|
||||
3
fictionarchive-web-astro/src/lib/constants/systemTags.ts
Normal file
3
fictionarchive-web-astro/src/lib/constants/systemTags.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const SystemTags = {
|
||||
Nsfw: 'Nsfw'
|
||||
} as const;
|
||||
@@ -114,7 +114,6 @@ export type ImageDto = {
|
||||
id: Scalars['UUID']['output'];
|
||||
lastUpdatedTime: Scalars['Instant']['output'];
|
||||
newPath: Maybe<Scalars['String']['output']>;
|
||||
originalPath: Scalars['String']['output'];
|
||||
};
|
||||
|
||||
export type ImageDtoFilterInput = {
|
||||
@@ -124,7 +123,6 @@ export type ImageDtoFilterInput = {
|
||||
lastUpdatedTime?: InputMaybe<InstantFilterInput>;
|
||||
newPath?: InputMaybe<StringOperationFilterInput>;
|
||||
or?: InputMaybe<Array<ImageDtoFilterInput>>;
|
||||
originalPath?: InputMaybe<StringOperationFilterInput>;
|
||||
};
|
||||
|
||||
export type ImageDtoSortInput = {
|
||||
@@ -132,7 +130,6 @@ export type ImageDtoSortInput = {
|
||||
id?: InputMaybe<SortEnumType>;
|
||||
lastUpdatedTime?: InputMaybe<SortEnumType>;
|
||||
newPath?: InputMaybe<SortEnumType>;
|
||||
originalPath?: InputMaybe<SortEnumType>;
|
||||
};
|
||||
|
||||
export type ImportNovelInput = {
|
||||
@@ -730,19 +727,20 @@ export type NovelQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type NovelQuery = { novels: { nodes: Array<{ id: any, name: string, description: string, url: string, rawLanguage: Language, rawStatus: NovelStatus, statusOverride: NovelStatus | null, externalId: string, createdTime: any, lastUpdatedTime: any, author: { id: any, name: string, externalUrl: string | null }, source: { id: any, name: string, key: string, url: string }, coverImage: { newPath: string | null } | null, tags: Array<{ id: any, key: string, displayName: string, tagType: TagType }>, chapters: Array<{ id: any, order: any, name: string, lastUpdatedTime: any }> }> | null } | null };
|
||||
export type NovelQuery = { novels: { nodes: Array<{ id: any, name: string, description: string, url: string, rawLanguage: Language, rawStatus: NovelStatus, statusOverride: NovelStatus | null, externalId: string, createdTime: any, lastUpdatedTime: any, author: { id: any, name: string, externalUrl: string | null }, source: { id: any, name: string, key: string, url: string }, coverImage: { newPath: string | null } | null, tags: Array<{ id: any, key: string, displayName: string, tagType: TagType }>, chapters: Array<{ id: any, order: any, name: string, lastUpdatedTime: any, images: Array<{ id: any, newPath: string | null }> }> }> | null } | null };
|
||||
|
||||
export type NovelsQueryVariables = Exact<{
|
||||
first?: InputMaybe<Scalars['Int']['input']>;
|
||||
after?: InputMaybe<Scalars['String']['input']>;
|
||||
where?: InputMaybe<NovelDtoFilterInput>;
|
||||
order?: InputMaybe<Array<NovelDtoSortInput> | NovelDtoSortInput>;
|
||||
}>;
|
||||
|
||||
|
||||
export type NovelsQuery = { novels: { edges: Array<{ cursor: string, node: { id: any, url: string, name: string, description: string, rawStatus: NovelStatus, lastUpdatedTime: any, coverImage: { newPath: string | null } | null, chapters: Array<{ order: any, name: string }>, tags: Array<{ key: string, displayName: string }> } }> | null, pageInfo: { hasNextPage: boolean, endCursor: string | null } } | null };
|
||||
export type NovelsQuery = { novels: { edges: Array<{ cursor: string, node: { id: any, url: string, name: string, description: string, rawStatus: NovelStatus, lastUpdatedTime: any, coverImage: { newPath: string | null } | null, chapters: Array<{ order: any, name: string }>, tags: Array<{ key: string, displayName: string, tagType: TagType }> } }> | null, pageInfo: { hasNextPage: boolean, endCursor: string | null } } | null };
|
||||
|
||||
|
||||
export const ImportNovelDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"ImportNovel"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ImportNovelInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"importNovel"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"novelUpdateRequestedEvent"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"novelUrl"}}]}}]}}]}}]} as unknown as DocumentNode<ImportNovelMutation, ImportNovelMutationVariables>;
|
||||
export const GetChapterDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetChapter"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"novelId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UnsignedInt"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"chapterOrder"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UnsignedInt"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chapter"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"novelId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"novelId"}}},{"kind":"Argument","name":{"kind":"Name","value":"chapterOrder"},"value":{"kind":"Variable","name":{"kind":"Name","value":"chapterOrder"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"order"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"body"}},{"kind":"Field","name":{"kind":"Name","value":"url"}},{"kind":"Field","name":{"kind":"Name","value":"revision"}},{"kind":"Field","name":{"kind":"Name","value":"createdTime"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}},{"kind":"Field","name":{"kind":"Name","value":"images"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"newPath"}}]}},{"kind":"Field","name":{"kind":"Name","value":"novelId"}},{"kind":"Field","name":{"kind":"Name","value":"novelName"}},{"kind":"Field","name":{"kind":"Name","value":"totalChapters"}},{"kind":"Field","name":{"kind":"Name","value":"prevChapterOrder"}},{"kind":"Field","name":{"kind":"Name","value":"nextChapterOrder"}}]}}]}}]} as unknown as DocumentNode<GetChapterQuery, GetChapterQueryVariables>;
|
||||
export const NovelDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Novel"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UnsignedInt"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"novels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}},{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"IntValue","value":"1"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"url"}},{"kind":"Field","name":{"kind":"Name","value":"rawLanguage"}},{"kind":"Field","name":{"kind":"Name","value":"rawStatus"}},{"kind":"Field","name":{"kind":"Name","value":"statusOverride"}},{"kind":"Field","name":{"kind":"Name","value":"externalId"}},{"kind":"Field","name":{"kind":"Name","value":"createdTime"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}},{"kind":"Field","name":{"kind":"Name","value":"author"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"externalUrl"}}]}},{"kind":"Field","name":{"kind":"Name","value":"source"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}},{"kind":"Field","name":{"kind":"Name","value":"coverImage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"newPath"}}]}},{"kind":"Field","name":{"kind":"Name","value":"tags"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"tagType"}}]}},{"kind":"Field","name":{"kind":"Name","value":"chapters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"order"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}}]}}]}}]}}]}}]} as unknown as DocumentNode<NovelQuery, NovelQueryVariables>;
|
||||
export const NovelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Novels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"NovelDtoFilterInput"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"novels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}},{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cursor"}},{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"url"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"coverImage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"newPath"}}]}},{"kind":"Field","name":{"kind":"Name","value":"rawStatus"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}},{"kind":"Field","name":{"kind":"Name","value":"chapters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"order"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"tags"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]}}]} as unknown as DocumentNode<NovelsQuery, NovelsQueryVariables>;
|
||||
export const NovelDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Novel"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UnsignedInt"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"novels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}]}},{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"IntValue","value":"1"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"url"}},{"kind":"Field","name":{"kind":"Name","value":"rawLanguage"}},{"kind":"Field","name":{"kind":"Name","value":"rawStatus"}},{"kind":"Field","name":{"kind":"Name","value":"statusOverride"}},{"kind":"Field","name":{"kind":"Name","value":"externalId"}},{"kind":"Field","name":{"kind":"Name","value":"createdTime"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}},{"kind":"Field","name":{"kind":"Name","value":"author"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"externalUrl"}}]}},{"kind":"Field","name":{"kind":"Name","value":"source"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"url"}}]}},{"kind":"Field","name":{"kind":"Name","value":"coverImage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"newPath"}}]}},{"kind":"Field","name":{"kind":"Name","value":"tags"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"tagType"}}]}},{"kind":"Field","name":{"kind":"Name","value":"chapters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"order"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}},{"kind":"Field","name":{"kind":"Name","value":"images"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"newPath"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode<NovelQuery, NovelQueryVariables>;
|
||||
export const NovelsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Novels"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"first"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"after"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"where"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"NovelDtoFilterInput"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"order"}},"type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"NovelDtoSortInput"}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"novels"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"first"},"value":{"kind":"Variable","name":{"kind":"Name","value":"first"}}},{"kind":"Argument","name":{"kind":"Name","value":"after"},"value":{"kind":"Variable","name":{"kind":"Name","value":"after"}}},{"kind":"Argument","name":{"kind":"Name","value":"where"},"value":{"kind":"Variable","name":{"kind":"Name","value":"where"}}},{"kind":"Argument","name":{"kind":"Name","value":"order"},"value":{"kind":"Variable","name":{"kind":"Name","value":"order"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cursor"}},{"kind":"Field","name":{"kind":"Name","value":"node"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"url"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"coverImage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"newPath"}}]}},{"kind":"Field","name":{"kind":"Name","value":"rawStatus"}},{"kind":"Field","name":{"kind":"Name","value":"lastUpdatedTime"}},{"kind":"Field","name":{"kind":"Name","value":"chapters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"order"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"tags"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"tagType"}}]}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"pageInfo"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hasNextPage"}},{"kind":"Field","name":{"kind":"Name","value":"endCursor"}}]}}]}}]}}]} as unknown as DocumentNode<NovelsQuery, NovelsQueryVariables>;
|
||||
@@ -41,6 +41,10 @@ query Novel($id: UnsignedInt!) {
|
||||
order
|
||||
name
|
||||
lastUpdatedTime
|
||||
images {
|
||||
id
|
||||
newPath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
query Novels($first: Int, $after: String, $where: NovelDtoFilterInput) {
|
||||
novels(first: $first, after: $after, where: $where) {
|
||||
query Novels($first: Int, $after: String, $where: NovelDtoFilterInput, $order: [NovelDtoSortInput!]) {
|
||||
novels(first: $first, after: $after, where: $where, order: $order) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
@@ -19,6 +19,7 @@ query Novels($first: Int, $after: String, $where: NovelDtoFilterInput) {
|
||||
tags {
|
||||
key
|
||||
displayName
|
||||
tagType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,37 @@
|
||||
import type { NovelDtoFilterInput, NovelStatus } from '$lib/graphql/__generated__/graphql';
|
||||
import type { NovelDtoFilterInput, NovelDtoSortInput, NovelStatus, SortEnumType } from '$lib/graphql/__generated__/graphql';
|
||||
|
||||
export type SortField = 'lastUpdatedTime' | 'createdTime' | 'name';
|
||||
export type SortDirection = SortEnumType;
|
||||
|
||||
export interface NovelSort {
|
||||
field: SortField;
|
||||
direction: SortDirection;
|
||||
}
|
||||
|
||||
export interface NovelFilters {
|
||||
search: string;
|
||||
statuses: NovelStatus[];
|
||||
tags: string[];
|
||||
authorName: string;
|
||||
sort: NovelSort;
|
||||
}
|
||||
|
||||
export const DEFAULT_SORT: NovelSort = {
|
||||
field: 'lastUpdatedTime',
|
||||
direction: 'DESC'
|
||||
};
|
||||
|
||||
export const EMPTY_FILTERS: NovelFilters = {
|
||||
search: '',
|
||||
statuses: [],
|
||||
tags: [],
|
||||
authorName: ''
|
||||
authorName: '',
|
||||
sort: DEFAULT_SORT
|
||||
};
|
||||
|
||||
const VALID_STATUSES: NovelStatus[] = ['ABANDONED', 'COMPLETED', 'HIATUS', 'IN_PROGRESS', 'UNKNOWN'];
|
||||
const VALID_SORT_FIELDS: SortField[] = ['lastUpdatedTime', 'createdTime', 'name'];
|
||||
const VALID_SORT_DIRECTIONS: SortDirection[] = ['ASC', 'DESC'];
|
||||
|
||||
/**
|
||||
* Parse filter state from URL search parameters
|
||||
@@ -34,7 +51,15 @@ export function parseFiltersFromURL(searchParams?: URLSearchParams): NovelFilter
|
||||
|
||||
const authorName = params.get('author') ?? '';
|
||||
|
||||
return { search, statuses, tags, authorName };
|
||||
// Parse sort parameters
|
||||
const sortField = params.get('sortBy') as SortField | null;
|
||||
const sortDir = params.get('sortDir') as SortDirection | null;
|
||||
const sort: NovelSort = {
|
||||
field: sortField && VALID_SORT_FIELDS.includes(sortField) ? sortField : DEFAULT_SORT.field,
|
||||
direction: sortDir && VALID_SORT_DIRECTIONS.includes(sortDir) ? sortDir : DEFAULT_SORT.direction
|
||||
};
|
||||
|
||||
return { search, statuses, tags, authorName, sort };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,6 +84,12 @@ export function filtersToURLParams(filters: NovelFilters): string {
|
||||
params.set('author', filters.authorName.trim());
|
||||
}
|
||||
|
||||
// Only include sort params if different from default
|
||||
if (filters.sort.field !== DEFAULT_SORT.field || filters.sort.direction !== DEFAULT_SORT.direction) {
|
||||
params.set('sortBy', filters.sort.field);
|
||||
params.set('sortDir', filters.sort.direction);
|
||||
}
|
||||
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
@@ -135,3 +166,10 @@ export function hasActiveFilters(filters: NovelFilters): boolean {
|
||||
filters.authorName.trim().length > 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert sort state to GraphQL order input
|
||||
*/
|
||||
export function sortToGraphQLOrder(sort: NovelSort): NovelDtoSortInput[] {
|
||||
return [{ [sort.field]: sort.direction }];
|
||||
}
|
||||
|
||||
@@ -1,12 +1,42 @@
|
||||
import DOMPurify from 'isomorphic-dompurify';
|
||||
|
||||
/**
|
||||
* Splits plain text into paragraphs based on newlines.
|
||||
* Double newlines create new paragraphs, single newlines become <br>.
|
||||
* If the content already contains HTML block elements, returns as-is.
|
||||
*/
|
||||
function wrapInParagraphs(text: string): string {
|
||||
// Check if content already has block-level HTML elements
|
||||
const hasBlockElements = /<(p|div|h[1-6]|ul|ol|blockquote|pre|table|hr)[>\s]/i.test(text);
|
||||
if (hasBlockElements) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// Split on double newlines (paragraph breaks)
|
||||
const paragraphs = text.split(/\n\s*\n/);
|
||||
|
||||
return paragraphs
|
||||
.map((para) => {
|
||||
const trimmed = para.trim();
|
||||
if (!trimmed) return '';
|
||||
// Convert single newlines to <br> within paragraphs
|
||||
const withBreaks = trimmed.replace(/\n/g, '<br>');
|
||||
return `<p>${withBreaks}</p>`;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes chapter HTML content with extended allowed tags.
|
||||
* More permissive than the description sanitizer to support
|
||||
* formatted novel content including headings, lists, and images.
|
||||
* Also wraps plain text in paragraph tags for better browser translate support.
|
||||
*/
|
||||
export function sanitizeChapterHtml(html: string): string {
|
||||
return DOMPurify.sanitize(html, {
|
||||
// First wrap in paragraphs if needed, then sanitize
|
||||
const wrapped = wrapInParagraphs(html);
|
||||
return DOMPurify.sanitize(wrapped, {
|
||||
ALLOWED_TAGS: [
|
||||
// Basic formatting
|
||||
'b',
|
||||
|
||||
Reference in New Issue
Block a user