diff --git a/chat/CharacterSearch.vue b/chat/CharacterSearch.vue index 74cc13a..92523ff 100644 --- a/chat/CharacterSearch.vue +++ b/chat/CharacterSearch.vue @@ -15,7 +15,12 @@ Searching for {{searchString}} - +
+ + +
+ +

@@ -44,21 +49,20 @@ import Modal from '../components/Modal.vue'; import {characterImage} from './common'; import core from './core'; - import {Character, Connection} from './interfaces'; + import { Character, Connection, SearchData, SearchKink } from './interfaces'; import l from './localize'; import UserView from './UserView.vue'; import * as _ from 'lodash'; import {EventBus} from './preview/event-bus'; + import CharacterSearchHistory from './CharacterSearchHistory.vue'; type Options = { - kinks: Kink[], + kinks: SearchKink[], listitems: {id: string, name: string, value: string}[] }; let options: Options | undefined; - type Kink = {id: number, name: string, description: string}; - function sort(x: Character, y: Character): number { if(x.status === 'looking' && y.status !== 'looking') return -1; if(x.status !== 'looking' && y.status === 'looking') return 1; @@ -87,18 +91,9 @@ return 0; } - interface Data { - kinks: Kink[] - genders: string[] - orientations: string[] - languages: string[] - furryprefs: string[] - roles: string[] - positions: string[] - } @Component({ - components: {modal: Modal, user: UserView, 'filterable-select': FilterableSelect, bbcode: BBCodeView(core.bbCodeParser)} + components: {modal: Modal, user: UserView, 'filterable-select': FilterableSelect, bbcode: BBCodeView(core.bbCodeParser), 'search-history': CharacterSearchHistory} }) export default class CharacterSearch extends CustomDialog { l = l; @@ -107,9 +102,9 @@ results: Character[] | undefined; resultsComplete = false; characterImage = characterImage; - options!: Data; - data: Data = {kinks: [], genders: [], orientations: [], languages: [], furryprefs: [], roles: [], positions: []}; - listItems: ReadonlyArray = ['genders', 'orientations', 'languages', 'furryprefs', 'roles', 'positions']; + options!: SearchData; + data: SearchData = {kinks: [], genders: [], orientations: [], languages: [], furryprefs: [], roles: [], positions: []}; + listItems: ReadonlyArray = ['genders', 'orientations', 'languages', 'furryprefs', 'roles', 'positions']; searchString = ''; @@ -216,7 +211,7 @@ } - filterKink(filter: RegExp, kink: Kink): boolean { + filterKink(filter: RegExp, kink: SearchKink): boolean { if(this.data.kinks.length >= 5) return this.data.kinks.indexOf(kink) !== -1; return filter.test(kink.name); @@ -232,6 +227,13 @@ } + updateSearch(data?: SearchData): void { + if (data) { + this.data = data; + } + } + + submit(): void { if(this.results !== undefined) { this.results = undefined; @@ -240,11 +242,29 @@ this.error = ''; const data: Connection.ClientCommands['FKS'] & {[key: string]: (string | number)[]} = {kinks: []}; for(const key in this.data) { - const item = this.data[key]; + const item = this.data[key]; if(item.length > 0) - data[key] = key === 'kinks' ? (item).map((x) => x.id) : (item); + data[key] = key === 'kinks' ? (item).map((x) => x.id) : (item); } core.connection.send('FKS', data); + + // tslint:disable-next-line + this.updateSearchHistory(this.data); + } + + + showHistory(): void { + (this.$refs.searchHistory).show(); + } + + + async updateSearchHistory(data: SearchData): Promise { + const history = (await core.settingsStore.get('searchHistory')) || []; + const dataStr = JSON.stringify(data, null, 0); + const filteredHistory = _.reject(history, (h: SearchData) => (JSON.stringify(h, null, 0) === dataStr)); + const newHistory: SearchData[] = _.take(_.concat([data], filteredHistory), 15); + + await core.settingsStore.set('searchHistory', newHistory); } } diff --git a/chat/CharacterSearchHistory.vue b/chat/CharacterSearchHistory.vue new file mode 100644 index 0000000..37c7186 --- /dev/null +++ b/chat/CharacterSearchHistory.vue @@ -0,0 +1,130 @@ + + + + + diff --git a/chat/Chat.vue b/chat/Chat.vue index a886787..4a401bb 100644 --- a/chat/Chat.vue +++ b/chat/Chat.vue @@ -185,4 +185,10 @@ import {InlineDisplayMode} from '../interfaces'; core.connection.connect(this.selectedCharacter.name); } } - \ No newline at end of file + + + diff --git a/chat/StatusPicker.vue b/chat/StatusPicker.vue index 36bc7ed..a5cc60e 100644 --- a/chat/StatusPicker.vue +++ b/chat/StatusPicker.vue @@ -1,12 +1,12 @@