From 8bb5f8c0e4a00583f70094589e1e818523a51f23 Mon Sep 17 00:00:00 2001 From: janpoem Date: Tue, 17 Jan 2023 16:22:39 +0800 Subject: [PATCH 1/2] init --- .gitignore | 1 + src/hooks/index.ts | 0 2 files changed, 1 insertion(+) create mode 100644 src/hooks/index.ts diff --git a/.gitignore b/.gitignore index 6007098..bd4cd23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Logs logs yarn.lock +pnpm-lock.yaml *.log npm-debug.log* yarn-debug.log* diff --git a/src/hooks/index.ts b/src/hooks/index.ts new file mode 100644 index 0000000..e69de29 -- Gitee From ccc9e29f1f7f39ba851715b0bf4b999d265bc652 Mon Sep 17 00:00:00 2001 From: janpoem Date: Tue, 17 Jan 2023 20:10:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E7=BB=93=E6=9E=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/components/aggregation.tsx | 2 +- src/components/aggregations.tsx | 2 +- src/components/home.tsx | 52 +++---- src/components/hotwords.tsx | 51 ++++--- src/components/index.tsx | 97 ++---------- src/components/input.tsx | 60 ++++---- src/components/queries.tsx | 68 +++++++-- src/components/render.tsx | 71 ++++----- src/components/results.tsx | 4 +- src/hooks/index.ts | 1 + src/hooks/useIndexeaSearch.ts | 261 ++++++++++++++++++++++++++++++++ 12 files changed, 443 insertions(+), 228 deletions(-) create mode 100644 src/hooks/useIndexeaSearch.ts diff --git a/package.json b/package.json index c6c8a68..3b41f32 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "preview": "vite preview" }, "dependencies": { - "@indexea/sdk": "^1.3.26", + "@indexea/sdk": "^1.3.27", "@popperjs/core": "^2.11.6", "@types/uuid": "^8.3.4", "bootstrap": "^5.2.3", diff --git a/src/components/aggregation.tsx b/src/components/aggregation.tsx index b355a16..d5d75f0 100644 --- a/src/components/aggregation.tsx +++ b/src/components/aggregation.tsx @@ -1,3 +1,3 @@ -export default function (props: any) { +export default function () { return
aggregation
} diff --git a/src/components/aggregations.tsx b/src/components/aggregations.tsx index 92abd77..41c9ee4 100644 --- a/src/components/aggregations.tsx +++ b/src/components/aggregations.tsx @@ -1,5 +1,5 @@ import Aggregation from './aggregation' -export default function (props: any) { +export default function () { return } diff --git a/src/components/home.tsx b/src/components/home.tsx index 4d55832..a0df942 100644 --- a/src/components/home.tsx +++ b/src/components/home.tsx @@ -1,13 +1,15 @@ -import { WidgetLayout } from '@indexea/sdk/layout' -import { SearchContext } from '@indexea/sdk/context' +import { WidgetLayout } from '@indexea/sdk/layout'; +import { SearchContext } from '@indexea/sdk/context'; +import { useIndexeaSearch } from '../hooks'; -import Input from './input' -import Hotwords from './hotwords' +import Input from './input'; +import Hotwords from './hotwords'; +import Render from './render'; -export type HomeProps = { - context: SearchContext - search: (q: string) => void -} +// export type HomeProps = { +// context: SearchContext +// search: (q: string) => void +// } /** * 搜索脚手架的首页 @@ -15,31 +17,25 @@ export type HomeProps = { * @param context * @returns */ -export default function ({ context, search }: HomeProps) { - //@ts-ignore - const logo: string = context?.widget?.settings?.logo || '/static/indexea.png' - const layout = WidgetLayout.parse(context.widget.layout || '') +export default function () { + const { defaultLogo: logo, inQuery } = useIndexeaSearch(); + + if (inQuery) { + return + } + return (
-
-
- ... +
+
+ ...
- - + +
- ) + ); } diff --git a/src/components/hotwords.tsx b/src/components/hotwords.tsx index 37d65ae..cc1d10c 100644 --- a/src/components/hotwords.tsx +++ b/src/components/hotwords.tsx @@ -1,16 +1,17 @@ -import { useEffect, useState, SyntheticEvent } from 'react' -import { SearchWord } from '@indexea/sdk' -import { SearchContext } from '@indexea/sdk/context' -import config from '../../config.json' -import { Indexea } from '../openapi' +import { useEffect, useState, SyntheticEvent } from 'react'; +import { SearchWord } from '@indexea/sdk'; +import { SearchContext } from '@indexea/sdk/context'; +import config from '../../config.json'; +import { useIndexeaSearch } from '../hooks'; +import { Indexea } from '../openapi'; -const indexea = new Indexea(config.api, '', config.widget) +const indexea = new Indexea(config.api, '', config.widget); -export type HotwordsProps = { - context: SearchContext - attrs: any - search: (q: string) => void -} +// export type HotwordsProps = { +// context: SearchContext +// attrs: any +// search: (q: string) => void +// } /** * 显示搜索热词 @@ -19,21 +20,22 @@ export type HotwordsProps = { * @param search * @returns */ -export default function ({ context, attrs, search }: HotwordsProps) { - const query: number = context.query - const count: number = attrs.show_count || 5 - const [words, setWords] = useState([]) +export default function () { + const { context, layout, search } = useIndexeaSearch(); + + const [words, setWords] = useState([]); useEffect(() => { - indexea.hotwords(query, 'year', count).then(setWords) - }, [query]) + // @ts-ignore show_count maybe string or number, should convert to number as safe + indexea.hotwords(context.query, 'year', layout.hotWords.show_count || 5).then(setWords); + }, [context.query]); return ( -