Skip to content

Commit

Permalink
chore: initial search store created
Browse files Browse the repository at this point in the history
  • Loading branch information
stritti committed Jan 22, 2024
1 parent cb540d7 commit 4bba053
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/models/SearchItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export default interface SearchItem{
id: string;
type: string;
title: string;
searchContent: string;
}
2 changes: 2 additions & 0 deletions src/stores/eventItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import type EventItem from '@/models/EventItem'
import eventService from '@/services/event.service'
import { useLoadingStore } from './loading'
import { useSeachStore } from './search'

interface State {
eventItemList: EventItem[]
Expand Down Expand Up @@ -31,6 +32,7 @@ export const useEventItemStore = defineStore('event', {
loadingStore.updateLoading(true);
eventService.getList().then((result) => {
this.eventItemList = result as Array<EventItem>;
useSeachStore().addEventList(this.eventItemList)
loadingStore.updateLoading(false);
})

Expand Down
36 changes: 36 additions & 0 deletions src/stores/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type EventItem from "@/models/EventItem"
import type SearchItem from "@/models/SearchItem"
import { defineStore } from "pinia"

interface State {
searchList: SearchItem[]
}

export const useSeachStore = defineStore('search', {
state: (): State => {
return {
searchList: []
}
},
getters: {
getAll: (state) => state.searchList
},
actions: {
reset() {
this.searchList = []
},
addEventList(list: EventItem[]) {
let searchItem: SearchItem
list.forEach(eventItem => {
searchItem.id = eventItem.id
searchItem.type = 'event'
searchItem.title = eventItem.name
searchItem.searchContent = eventItem.name.toLocaleLowerCase()
+ ' ' + eventItem.beschreibung.toLocaleLowerCase()
+ ' ' + eventItem.ort.toLocaleLowerCase()
this.searchList.push(searchItem)
});
}

}
})

0 comments on commit 4bba053

Please sign in to comment.