From 4f6c0d1a116b0cc62b8bef0d8aad1e31cdd710ed Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 25 Dec 2023 02:56:24 +0300 Subject: [PATCH] gql-fix --- .../Nav/SearchModal/SearchModal.tsx | 4 ++++ .../query/core/articles-load-search.ts | 4 ++-- src/pages/search.page.tsx | 20 +++++++++---------- src/stores/ui.ts | 9 --------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/components/Nav/SearchModal/SearchModal.tsx b/src/components/Nav/SearchModal/SearchModal.tsx index 1aa33db3..55458dfa 100644 --- a/src/components/Nav/SearchModal/SearchModal.tsx +++ b/src/components/Nav/SearchModal/SearchModal.tsx @@ -5,13 +5,17 @@ import { openPage } from '@nanostores/router' import styles from './SearchModal.module.scss' import { router, useRouter } from '../../../stores/router' +import { hideModal } from '../../../stores/ui' export const SearchModal = () => { const { t } = useLocalize() + const { changeSearchParams } = useRouter() let qElement: HTMLInputElement | undefined const submitQuery = async (ev) => { ev.preventDefault() + changeSearchParams({}, true) + hideModal() openPage(router, 'search', { q: qElement.value }) } return ( diff --git a/src/graphql/query/core/articles-load-search.ts b/src/graphql/query/core/articles-load-search.ts index b99a59dd..8e36f08d 100644 --- a/src/graphql/query/core/articles-load-search.ts +++ b/src/graphql/query/core/articles-load-search.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - query LoadSearchQuery($options: LoadShoutsOptions) { - load_shouts_search(options: $options) { + query LoadSearchQuery($params: LoadShoutsOptions) { + load_shouts_search(params: $params) { score title slug diff --git a/src/pages/search.page.tsx b/src/pages/search.page.tsx index 9d1e5d2a..a14381c3 100644 --- a/src/pages/search.page.tsx +++ b/src/pages/search.page.tsx @@ -1,6 +1,6 @@ import type { PageProps } from './types' -import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js' +import { createEffect, createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js' import { Loading } from '../components/_shared/Loading' import { PageLayout } from '../components/_shared/PageLayout' @@ -12,20 +12,18 @@ import { loadShoutsSearch, resetSortedArticles } from '../stores/zine/articles' export const SearchPage = (props: PageProps) => { const [isLoaded, setIsLoaded] = createSignal(Boolean(props.searchResults)) - const { t } = useLocalize() - - const { page } = useRouter() - + const { page, searchParams } = useRouter() const q = createMemo(() => page().params['q'] as string) - onMount(async () => { - if (isLoaded()) { - return + createEffect(async () => { + if (isLoaded()) return + else if (q() && window) { + const text = q() || window.location.href.split('/').pop() + // TODO: pagination, load more + await loadShoutsSearch({ text, limit: 50, offset: 0 }) + setIsLoaded(true) } - - await loadShoutsSearch({ text: q(), limit: 50, offset: 0 }) - setIsLoaded(true) }) onCleanup(() => resetSortedArticles()) diff --git a/src/stores/ui.ts b/src/stores/ui.ts index 174f5822..10180858 100644 --- a/src/stores/ui.ts +++ b/src/stores/ui.ts @@ -67,15 +67,6 @@ export const hideModal = () => { source: null, } - if (searchParams().modal === 'auth') { - if (searchParams().mode === 'confirm-email') { - newSearchParams.token = null - } - newSearchParams.mode = null - } - - changeSearchParams(newSearchParams, true) - setModal(null) }