Skip to content

Commit

Permalink
Merge pull request #85 from Suwayomi/main
Browse files Browse the repository at this point in the history
some quick search stuff
  • Loading branch information
Robonau authored Nov 14, 2023
2 parents 9d30a1d + 7107711 commit dcda414
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
26 changes: 12 additions & 14 deletions src/routes/(app)/browse/source/[sourceID]/Grid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@
let page = 1;
let isLoading = true;
let all: undefined | FetchSourceMangaMutation['fetchSourceManga'];
let all: FetchSourceMangaMutation['fetchSourceManga'] = {
hasNextPage: true,
mangas: []
};
let mainerror: Error | undefined;
$: query, filters, clearAll();
function clearAll() {
all = undefined;
all = {
hasNextPage: true,
mangas: []
};
page = 1;
}
Expand All @@ -55,24 +61,16 @@
isLoading = true;
try {
const result = await Asysource;
if (result.errors) {
result.errors.forEach((e) => {
errortoast(toastStore, 'failed to load page', e.message);
});
isLoading = false;
return;
}
if (!result.data) throw new Error('Missing data');
if (!all) {
all = result.data.fetchSourceManga;
isLoading = false;
return;
}
all.hasNextPage = result.data.fetchSourceManga.hasNextPage;
all.mangas.push(...result.data.fetchSourceManga.mangas);
all = all;
} catch (error) {
if (error instanceof Error) {
console.error(error);
if (error.message.includes('Already on the Last Page!')) {
all.hasNextPage = false;
}
mainerror = error;
errortoast(toastStore, 'failed to load page', error.message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
import type { FilterChangeInput } from '$lib/generated.js';
import { filters as filtersStore } from './stores';
import type { SvelteComponent } from 'svelte';
import { queryParam, ssp } from 'sveltekit-search-params';
export let parent: SvelteComponent;
const modalStore = getModalStore();
export let data: LayoutData;
export let submit: (filterss: FilterChangeInput[], queryy: string) => void;
const sause = data.sause;
let query = '';
const queryy = queryParam('q', ssp.string(), { pushHistory: false });
let query = $queryy ?? '';
let filters: FilterChangeInput[] = $filtersStore;
function Search() {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
const modalStore = getModalStore();
function openQuickSearch(e: KeyboardEvent) {
if (e.code === 'KeyP' && e.ctrlKey) {
if ((e.code === 'Slash' || e.code === 'KeyP') && e.ctrlKey) {
e.preventDefault();
if (!$modalStore.find((e) => e.meta?.id === 'QuickSearchModal'))
modalStore.trigger({
Expand Down
30 changes: 25 additions & 5 deletions src/routes/QuickSearchModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
import { ISOLanguages } from './(app)/browse/languages';
import { goto } from '$app/navigation';
import type { SvelteComponent } from 'svelte';
import { Sourcelangfilt } from './(app)/browse/sources/SourcesStores';
import { queryParam, ssp } from 'sveltekit-search-params';
import { page } from '$app/stores';
export let parent: SvelteComponent;
const modalStore = getModalStore();
const query = queryParam('q', ssp.string(), { pushHistory: false });
let value = '';
let items: {
img?: string;
Expand Down Expand Up @@ -55,6 +60,10 @@
{
str: '#C/M:CN',
firstLine: "Go to Chapter 'CN' from Manga 'M' in Category 'C'"
},
{
str: 'X',
firstLine: 'will search, depends on context of the page'
}
];
Expand Down Expand Up @@ -166,9 +175,9 @@
const parsed = value.slice(1).split('/');
const sourceSearch: string | undefined = parsed[0];
const mangaSearch: string | undefined = parsed[1];
const includeSource = $sources.data?.sources?.nodes.filter((e) =>
e.displayName.toLowerCase().includes(sourceSearch.toLowerCase())
);
const includeSource = $sources.data?.sources?.nodes
.filter((e) => e.displayName.toLowerCase().includes(sourceSearch.toLowerCase()))
.filter((e) => $Sourcelangfilt.has(e.lang));
if (includeSource) {
items = includeSource.map((e) => {
return {
Expand All @@ -188,8 +197,19 @@
}
function handelKey(event: KeyboardEvent) {
if (event.key === 'Enter' && items[0].url) {
goto(items[0].url);
if (event.key === 'Enter') {
if (items[0].url) {
goto(items[0].url);
} else if (!['#', '@'].includes(value[0])) {
if (/(\/browse\/source\/\d*\/)popular|latest/.test($page.url.pathname)) {
goto(
$page.url.pathname.replace(
/(\/browse\/source\/\d*\/)popular|latest/,
`$1filter?q=${value}`
)
);
} else query.set(value);
}
parent.onClose();
}
}
Expand Down

0 comments on commit dcda414

Please sign in to comment.