Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 675a5e9

Browse files
committed
chore(client/ts): port search_string
1 parent 8ab0084 commit 675a5e9

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/public/app/components/app_context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ class AppContext extends Component {
369369
layout?: Layout;
370370
noteTreeWidget?: NoteTreeWidget;
371371

372+
lastSearchString?: string;
373+
372374
constructor(isMainWindow: boolean) {
373375
super();
374376

src/public/app/widgets/search_options/abstract_search_option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { AttributeType } from "../../entities/fattribute.js";
1010
export default abstract class AbstractSearchOption extends Component {
1111

1212
private attribute: FAttribute;
13-
private note: FNote;
13+
protected note: FNote;
1414

1515
constructor(attribute: FAttribute, note: FNote) {
1616
super();

src/public/app/widgets/search_options/search_string.js renamed to src/public/app/widgets/search_options/search_string.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AbstractSearchOption from "./abstract_search_option.js";
22
import SpacedUpdate from "../../services/spaced_update.js";
33
import server from "../../services/server.js";
44
import shortcutService from "../../services/shortcuts.js";
5-
import appContext from "../../components/app_context.js";
5+
import appContext, { type EventData } from "../../components/app_context.js";
66
import { t } from "../../services/i18n.js";
77
import { Tooltip } from "bootstrap";
88

@@ -29,20 +29,24 @@ const TPL = `
2929
</ul>
3030
</div>
3131
</div>
32-
32+
3333
<span class="bx bx-x icon-action search-option-del"></span>
3434
</td>
3535
</tr>`;
3636

3737
export default class SearchString extends AbstractSearchOption {
38+
39+
private $searchString!: JQuery<HTMLElement>;
40+
private spacedUpdate!: SpacedUpdate;
41+
3842
static get optionName() {
3943
return "searchString";
4044
}
4145
static get attributeType() {
4246
return "label";
4347
}
4448

45-
static async create(noteId) {
49+
static async create(noteId: string) {
4650
await AbstractSearchOption.setAttribute(noteId, "label", "searchString");
4751
}
4852

@@ -61,7 +65,7 @@ export default class SearchString extends AbstractSearchOption {
6165
});
6266

6367
this.spacedUpdate = new SpacedUpdate(async () => {
64-
const searchString = this.$searchString.val();
68+
const searchString = String(this.$searchString.val());
6569
appContext.lastSearchString = searchString;
6670

6771
await this.setAttribute("label", "searchString", searchString);
@@ -73,13 +77,13 @@ export default class SearchString extends AbstractSearchOption {
7377
}
7478
}, 1000);
7579

76-
this.$searchString.val(this.note.getLabelValue("searchString"));
80+
this.$searchString.val(this.note.getLabelValue("searchString") ?? "");
7781

7882
return $option;
7983
}
8084

81-
showSearchErrorEvent({ error }) {
82-
let tooltip = new Tooltip(this.$searchString, {
85+
showSearchErrorEvent({ error }: EventData<"showSearchError">) {
86+
let tooltip = new Tooltip(this.$searchString[0], {
8387
trigger: "manual",
8488
title: `${t("search_string.error", { error })}`,
8589
placement: "bottom"
@@ -92,7 +96,7 @@ export default class SearchString extends AbstractSearchOption {
9296

9397
focusOnSearchDefinitionEvent() {
9498
this.$searchString
95-
.val(this.$searchString.val().trim() || appContext.lastSearchString)
99+
.val(String(this.$searchString.val()).trim() ?? appContext.lastSearchString)
96100
.focus()
97101
.select();
98102
this.spacedUpdate.scheduleUpdate();

0 commit comments

Comments
 (0)