swyxio/swyxkit

Filter by Category results in "No blogposts found!"

Laidlaw opened this issue · 1 comments

Seen here: https://swyxkit.netlify.app/blog?show=Essay

I think filtering by category worked before the fuzzySearch integration.
Could the culprit be here?
blog/+page.svelte 49-72

let loaded = false;
	const filterCategories = async (_items, _, s) => {
		if (!$selectedCategories?.length) return _items;
		return _items
			.filter((item) => {
				return $selectedCategories
					.map((element) => {
						return element.toLowerCase();
					})
					.includes(item.category.toLowerCase());
			})
			.filter((item) => item.toString().toLowerCase().includes(s));
	};
	$: searchFn = filterCategories;
	function loadsearchFn() {
		if (loaded) return;
		import('./fuzzySearch').then((fuzzy) => {
			searchFn = fuzzy.fuzzySearch;
			loaded = true;
		});
	}
	if ($search) loadsearchFn()
	/** @type import('$lib/types').ContentItem[]  */
	let list;
	$: searchFn(items, $selectedCategories, $search).then(_items => list = _items);

yeah theres something in the logic to figure out here, i agree this is a bug. PR welcome! i doubt i will get to this in timely fashion