diff --git a/package-lock.json b/package-lock.json
index a74d7749..2b8696c7 100644
Binary files a/package-lock.json and b/package-lock.json differ
diff --git a/package.json b/package.json
index f5cb10f6..67688484 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,6 @@
"@welshman/lib": "^0.0.8",
"@welshman/net": "^0.0.11",
"@welshman/util": "^0.0.11",
- "autobind-decorator": "^2.4.0",
"classnames": "^2.5.1",
"compressorjs": "^1.2.1",
"date-picker-svelte": "^2.12.0",
diff --git a/src/app/shared/FeedFormSectionKinds.svelte b/src/app/shared/FeedFormSectionKinds.svelte
index 423e5baf..f17ab84f 100644
--- a/src/app/shared/FeedFormSectionKinds.svelte
+++ b/src/app/shared/FeedFormSectionKinds.svelte
@@ -58,6 +58,8 @@
{label: "Image", kind: FILE_METADATA},
{label: "Relay selections", kind: RELAYS},
])
+
+ console.log(helper)
What kind of content do you want to see?
diff --git a/src/domain/handler.ts b/src/domain/handler.ts
index a54eca99..9f43d4c5 100644
--- a/src/domain/handler.ts
+++ b/src/domain/handler.ts
@@ -45,14 +45,8 @@ export const displayHandler = (handler?: Handler) => handler?.name || "[no name]
export class HandlerSearch extends SearchHelper {
config = {keys: ["name", "about"]}
-
- getValue(option: Handler) {
- return getAddress(option.event)
- }
-
- displayValue(address: string) {
- return displayHandler(this.getOption(address))
- }
+ getValue = (option: Handler) => getAddress(option.event)
+ displayValue = (address: string) => displayHandler(this.getOption(address))
}
export const getHandlerAddress = (event: TrustedEvent) => {
diff --git a/src/domain/kind.ts b/src/domain/kind.ts
index 0644e69b..9d9f7f01 100644
--- a/src/domain/kind.ts
+++ b/src/domain/kind.ts
@@ -8,11 +8,9 @@ export type KindOption = {
export class KindSearch extends SearchHelper {
config = {keys: ["kind", "label"]}
- getValue(option: KindOption) {
- return option.kind
- }
+ getValue = (option: KindOption) => option.kind
- displayValue(kind: number) {
+ displayValue = (kind: number) => {
const option = this.getOption(kind)
return option ? `${option.label} (kind ${kind})` : `Kind ${kind}`
diff --git a/src/engine/state.ts b/src/engine/state.ts
index decb9e04..5f3313ce 100644
--- a/src/engine/state.ts
+++ b/src/engine/state.ts
@@ -353,17 +353,7 @@ export class ProfileSearch extends SearchHelper {
score: getWotScore($pubkey, profile.event.pubkey),
}))
- const fuse = new Fuse(options, {
- keys: [
- "profile.name",
- "profile.display_name",
- {name: "profile.nip05", weight: 0.5},
- {name: "profile.about", weight: 0.1},
- ],
- threshold: 0.3,
- shouldSort: false,
- includeScore: true,
- })
+ const fuse = new Fuse(options, this.config)
return (term: string) => {
if (!term) {
diff --git a/src/util/misc.ts b/src/util/misc.ts
index 695bf07f..b3a8e1d1 100644
--- a/src/util/misc.ts
+++ b/src/util/misc.ts
@@ -344,47 +344,37 @@ export const getStringWidth = (text: string) => {
}
export class SearchHelper {
- config: any
+ config: Record = {}
_optionsByValue = new Map()
_search?: (term: string) => T[]
- constructor(readonly options: T[]) {
- for (const option of options) {
- this._optionsByValue.set(this.getValue(option), option)
- }
- }
+ constructor(readonly options: T[]) {}
- getSearch() {
- return fuzzy(this.options, this.config)
- }
-
- getOption(value: V): T {
- return this._optionsByValue.get(value)
- }
-
- getValue(option: T): V {
- return option as unknown as V
- }
-
- displayValue(value: V) {
- return String(value)
- }
-
- displayOption(option: T) {
- return this.displayValue(this.getValue(option))
- }
-
- searchOptions(term: string) {
+ _setup() {
if (!this._search) {
+ for (const option of this.options) {
+ this._optionsByValue.set(this.getValue(option), option)
+ }
+
this._search = this.getSearch()
}
- return this._search(term)
+ return this
}
- searchValues(term: string) {
- return this.searchOptions(term).map(this.getValue)
- }
+ getSearch = () => fuzzy(this.options, this.config)
+
+ getOption = (value: V) => this._optionsByValue.get(value)
+
+ getValue = (option: T) => option as unknown as V
+
+ displayValue = (value: V) => String(value)
+
+ displayOption = (option: T) => this.displayValue(this.getValue(option))
+
+ searchOptions = (term: string) => this._setup()._search(term)
+
+ searchValues = (term: string) => this.searchOptions(term).map(this.getValue)
}
export const fromCsv = s => (s || "").split(",").filter(identity)