From 2e859a3ea123fba5765e1dd3546fa37db34faac9 Mon Sep 17 00:00:00 2001 From: Torwent Date: Tue, 13 Jun 2023 13:04:19 +0200 Subject: [PATCH] fix: search fixes - search author now works - failed searches now simply clear the search instead of redirecting you to the main page --- src/routes/devs/+page.ts | 4 ++-- src/routes/scripts/+page.ts | 8 +++----- src/routes/tutorials/+page.ts | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/routes/devs/+page.ts b/src/routes/devs/+page.ts index 0b691ed..30107b6 100644 --- a/src/routes/devs/+page.ts +++ b/src/routes/devs/+page.ts @@ -32,14 +32,14 @@ export const load: PageLoad = async ({ url, depends }) => { .select("real_name, username, description, github, paypal_id, content", { count: "exact" }) - .ilike("id_realname_username_description_content", "%" + search + "%") + .ilike("search_devs", "%" + search + "%") } const { data, count, error } = devsData if (error) { console.error(error) - throw redirect(303, "/") + throw redirect(303, "/devs") } const devs = data diff --git a/src/routes/scripts/+page.ts b/src/routes/scripts/+page.ts index 4bd9be5..b7521d7 100644 --- a/src/routes/scripts/+page.ts +++ b/src/routes/scripts/+page.ts @@ -47,13 +47,11 @@ export const load: Load = async ({ url, depends }) => { `id, title, description, content, categories, subcategories, published, min_xp, max_xp, min_gp, max_gp, scripts_protected (author, assets_path, author_id, assets_alt, revision), stats_scripts (experience, gold, runtime, levels, total_unique_users, total_current_users, total_monthly_users)`, - { - count: "exact" - } + { count: "exact" } ) .contains("categories", categoriesFilters) .contains("subcategories", subcategoriesFilters) - .ilike("scripts_public_search", "%" + search + "%") + .ilike("search_script", "%" + search + "%") } const promises = await Promise.all([ @@ -67,7 +65,7 @@ export const load: Load = async ({ url, depends }) => { if (error) { console.error(error) - throw redirect(303, "/") + throw redirect(303, "/scripts") } const scriptData = data as unknown as Script[] diff --git a/src/routes/tutorials/+page.ts b/src/routes/tutorials/+page.ts index e5432d2..f5b0eb9 100644 --- a/src/routes/tutorials/+page.ts +++ b/src/routes/tutorials/+page.ts @@ -50,14 +50,14 @@ export const load: PageLoad = async ({ url, depends, parent }) => { .select("id, created_at, user_id, author, title, description, content, level", { count: "exact" }) - .ilike("tutorials_search", "%" + search.replaceAll("%", "") + "%") + .ilike("search_tutorials", "%" + search.replaceAll("%", "") + "%") } const { data, count, error } = await postsData if (error) { console.error("tutorials SELECT failed: " + error) - throw redirect(303, "./") + throw redirect(303, "/tutorials") } const posts = data