Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into refactor/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Aug 7, 2024
2 parents d01d4ad + ff54ab1 commit 771ee77
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 79 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"release:packages": "pnpm --filter \"./packages/**\" release"
},
"devDependencies": {
"@halo-dev/api-client": "2.17.0",
"@rushstack/eslint-patch": "^1.10.4",
"@types/node": "^18.19.43",
"@typescript-eslint/eslint-plugin": "^6.21.0",
Expand Down
1 change: 0 additions & 1 deletion packages/search-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"prettier": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.gitignore --write"
},
"dependencies": {
"@halo-dev/api-client": "2.17.0",
"lit": "^3.2.0",
"lodash-es": "^4.17.21"
},
Expand Down
26 changes: 13 additions & 13 deletions packages/search-widget/src/search-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import varStyles from './styles/var';

@customElement('search-form')
export class SearchForm extends LitElement {
constructor() {
super();
this.addEventListener('keydown', this.handleKeydown);
}

@property({ type: String })
baseUrl = '';

@property({ type: Object })
options = {};

@state()
private searchResult?: SearchResult;

Expand All @@ -30,6 +28,12 @@ export class SearchForm extends LitElement {

inputRef: Ref<HTMLInputElement> = createRef<HTMLInputElement>();

constructor() {
super();

this.addEventListener('keydown', this.handleKeydown);
}

override render() {
return html`
<div class="search-form__input">
Expand Down Expand Up @@ -117,25 +121,21 @@ export class SearchForm extends LitElement {

fetchHits: DebouncedFunc<(keyword: string) => Promise<void>> = debounce(
async (keyword: string) => {
const options: SearchOption = {
annotations: {},
const searchOptions: SearchOption = {
...this.options,
highlightPostTag: '</mark>',
highlightPreTag: '<mark>',
includeCategoryNames: [],
includeOwnerNames: [],
includeTagNames: [],
includeTypes: [],
keyword,
limit: 20,
};

const response = await fetch(
`/apis/api.halo.run/v1alpha1/indices/-/search?keyword=${keyword}`,
`/apis/api.halo.run/v1alpha1/indices/-/search`,
{
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(options),
body: JSON.stringify(searchOptions),
method: 'post',
}
);
Expand Down
8 changes: 7 additions & 1 deletion packages/search-widget/src/search-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class SearchModal extends LitElement {
@property({ type: String })
baseUrl = '';

@property({ type: Object })
options = {};

override render() {
return html`<div
class="modal__wrapper"
Expand All @@ -24,7 +27,10 @@ export class SearchModal extends LitElement {
<div class="modal__layer" @click="${this.close}"></div>
<div class="modal__content">
${this.open
? html`<search-form baseUrl=${this.baseUrl}></search-form>`
? html`<search-form
.baseUrl=${this.baseUrl}
.options=${this.options}
></search-form>`
: ''}
</div>
</div>`;
Expand Down
4 changes: 3 additions & 1 deletion packages/widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SearchModal } from '@halo-dev/search-widget';
import '@halo-dev/search-widget/var.css';
import type { SearchOption } from '@halo-dev/api-client';

export { SearchModal };

Expand All @@ -9,6 +10,7 @@ const searchModalElement = document.createElement(

document.body.append(searchModalElement);

export function open() {
export function open(options: SearchOption) {
searchModalElement.options = options;
searchModalElement.open = true;
}
93 changes: 58 additions & 35 deletions pnpm-lock.yaml

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

Loading

0 comments on commit 771ee77

Please sign in to comment.