Skip to content

Commit

Permalink
Merge pull request #614 from hearchco/as/feat/categoryless
Browse files Browse the repository at this point in the history
feat: frontend categories
  • Loading branch information
aleksasiriski authored Nov 17, 2024
2 parents ed59700 + e852a42 commit 9a6923b
Show file tree
Hide file tree
Showing 31 changed files with 805 additions and 157 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@sveltejs/kit": "^2.8.1",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@types/eslint": "^9.6.1",
"@types/node": "^22.9.0",
"autoprefixer": "^10.4.20",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
86 changes: 52 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib/components/gadgets/timer/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}
});
/** @type {number|undefined} */
/** @type {NodeJS.Timeout|undefined} */
let interval = $state(undefined);
function toggleState() {
if (beeping) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/results/general/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @property {string} query
* @property {string} category
* @property {number} currentPage
* @property {ResultType[]} results
* @property {WebResultType[]} results
*/
/** @type {Props} */
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/results/general/single.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* @typedef {object} Props
* @property {ResultType} result
* @property {WebResultType} result
*/
/** @type {Props} */
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/results/images/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @property {string} query
* @property {string} category
* @property {number} currentPage
* @property {ResultType[]} results
* @property {ResultType | undefined} imagePreview
* @property {ImagesResultType[]} results
* @property {ImagesResultType | undefined} imagePreview
*/
/** @type {Props} */
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/results/images/preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @typedef {object} Props
* @property {ResultType} result
* @property {ResultType | undefined} imagePreview
* @property {ImagesResultType} result
* @property {ImagesResultType | undefined} imagePreview
*/
/** @type {Props} */
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/results/images/single.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @typedef {object} Props
* @property {ResultType} result
* @property {ResultType | undefined} imagePreview
* @property {ImagesResultType} result
* @property {ImagesResultType | undefined} imagePreview
*/
/** @type {Props} */
Expand Down
26 changes: 19 additions & 7 deletions src/lib/components/results/infiniteloading/main.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<script>
import { concatSearchParams } from '$lib/functions/api/concatparams';
import { fetchAdditionalResults } from '$lib/functions/api/additionalresults';
import { fetchResults } from '$lib/functions/api/fetchapi';
import {
fetchAdditionalWebResults,
fetchAdditionalImagesResults
} from '$lib/functions/api/additionalresults';
import { fetchWebResults, fetchImagesResults } from '$lib/functions/api/fetchapi';
import { assertImagesResultType } from '$lib/types/search/assert';
import { getCategoryConfigBase64 } from '$lib/functions/categories/convert';
/**
* @typedef {object} Props
* @property {string} query
* @property {string} category
* @property {number} currentPage
* @property {ResultType[]} results
* @property {WebResultType[] | ImagesResultType[]} results
*/
/** @type {Props} */
Expand All @@ -20,21 +25,28 @@
event.preventDefault();
const params = concatSearchParams([
['q', query],
['category', category],
['category', getCategoryConfigBase64(category)],
['start', nextPage.toString()]
]);
const newResults = await fetchAdditionalResults(results, params);
const newResults = assertImagesResultType(results, category)
? await fetchAdditionalImagesResults(results, params)
: await fetchAdditionalWebResults(results, params);
results = newResults;
nextPage = nextPage + 1;
}
async function preloadResults() {
const params = concatSearchParams([
['q', query],
['category', category],
['category', getCategoryConfigBase64(category)],
['start', nextPage.toString()]
]);
await fetchResults(params);
if (assertImagesResultType(results, category)) {
await fetchImagesResults(params);
} else {
await fetchWebResults(params);
}
}
</script>

Expand Down
8 changes: 4 additions & 4 deletions src/lib/components/searchbox/main.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { CategoryEnum } from '$lib/types/search/category';
import { CategoryEnum } from '$lib/types/search/categoryenum';
import { getQueryWithoutCategory } from '$lib/functions/query/category';
import { fetchSuggestions } from '$lib/functions/api/fetchapi';
import { fetchSuggestionsResults } from '$lib/functions/api/fetchapi';
/**
* @typedef {object} Props
Expand Down Expand Up @@ -36,7 +36,7 @@
// Whether to show suggestions or not.
let shouldShowSuggs = $state(homepage);
/** @type {SuggestionType[]} */
/** @type {SuggestionsResultType[]} */
let suggestions = $state([]);
// Determines if the suggestions can be shown.
Expand All @@ -47,7 +47,7 @@
if (getQueryWithoutCategory(currQuery) === '') {
suggestions = [];
} else if (currentIndex === -1) {
fetchSuggestions(getQueryWithoutCategory(currQuery)).then((resp) => {
fetchSuggestionsResults(getQueryWithoutCategory(currQuery)).then((resp) => {
const maxSize = 10;
if (resp.suggestions.length > maxSize)
resp.suggestions.splice(maxSize, resp.suggestions.length - maxSize);
Expand Down
Loading

0 comments on commit 9a6923b

Please sign in to comment.