-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding import statements and updating dependencies
- Loading branch information
Showing
8 changed files
with
1,796 additions
and
1,759 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,60 @@ | ||
import { Model } from '@vuex-orm/core' | ||
import { Model } from "@vuex-orm/core"; | ||
import { IHint } from "../types"; | ||
|
||
export interface ISearchHistoryState { | ||
} | ||
export interface ISearchHistoryState {} | ||
|
||
export interface ISearch { | ||
key: string | ||
date: number | ||
key: string; | ||
date: number; | ||
} | ||
|
||
export default class SearchHistory extends Model implements ISearch { | ||
static entity = 'search-history' | ||
static primaryKey = 'key' | ||
public readonly key!: string | ||
public readonly date!: number | ||
static entity = "search-history"; | ||
static primaryKey = "key"; | ||
public readonly key!: string; | ||
public readonly date!: number; | ||
|
||
static fields() { | ||
return { | ||
key: this.attr(''), | ||
date: this.attr(0) | ||
} | ||
key: this.attr(""), | ||
date: this.attr(0), | ||
}; | ||
} | ||
|
||
static get $state(): ISearchHistoryState { | ||
return this.store().state.entities[this.entity] | ||
return this.store().state.entities[this.entity]; | ||
} | ||
|
||
static state(): ISearchHistoryState { | ||
return { | ||
} | ||
return {}; | ||
} | ||
|
||
public static log(key: string) { | ||
SearchHistory.insert({ data: { key, date: Date.now() } }) | ||
SearchHistory.insert({ data: { key, date: Date.now() } }); | ||
} | ||
|
||
public static searchHints(searchString: string): IHint[] { | ||
if (!(searchString?.trim())) { | ||
if (!searchString?.trim()) { | ||
return this.all() | ||
.sort((a, b) => b.date - a.date) | ||
.map(entry => ({ type: 'local', key: entry.key })) | ||
.slice(0, 10) as IHint[] | ||
.map((entry) => ({ type: "local", key: entry.key })) | ||
.slice(0, 10) as IHint[]; | ||
} | ||
|
||
const str = searchString.trim() | ||
const str = searchString.trim(); | ||
|
||
return this.all() | ||
.filter((entry: ISearch) => { | ||
const val = entry.key.toLowerCase() | ||
return val.includes(str.toLowerCase()) && | ||
val.length > str.length | ||
}) | ||
.sort((a, b) => b.date - a.date) | ||
.map(entry => ({ type: 'local', key: entry.key })) || [] | ||
return ( | ||
this.all() | ||
.filter((entry: ISearch) => { | ||
const val = entry.key.toLowerCase(); | ||
return val.includes(str.toLowerCase()) && val.length > str.length; | ||
}) | ||
.sort((a, b) => b.date - a.date) | ||
.map((entry) => ({ type: "local", key: entry.key })) || [] | ||
); | ||
} | ||
|
||
public static deleteHint(key: string) { | ||
this.delete(key) | ||
this.delete(key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.