-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9e11ee
commit d09ab7c
Showing
10 changed files
with
160 additions
and
144 deletions.
There are no files selected for viewing
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
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,48 +1,56 @@ | ||
/* eslint-disable no-console */ | ||
import { defineStore } from 'pinia' | ||
|
||
export const useSearchStore = defineStore('search', { | ||
state: () => ({ | ||
search: '', | ||
searchResults: '', | ||
searchError: '', | ||
}), | ||
actions: { | ||
setSearch(search) { | ||
this.search = search | ||
console.log('Active search set to ' + search) | ||
}, | ||
setSearchResults(searchResults) { | ||
this.searchResults = searchResults | ||
console.log('Active search set to ' + searchResults) | ||
}, | ||
/* istanbul ignore next */ // ignore this for Jest until moved into a service | ||
getSearchResults() { | ||
fetch( | ||
'/index.php/apps/opencatalogi/api/search?_search=' + this.search, | ||
{ | ||
method: 'GET', | ||
}, | ||
) | ||
.then((response) => { | ||
response.json().then((data) => { | ||
if (data?.code === 403 && data?.message) { | ||
this.searchError = data.message | ||
console.log(this.searchError) | ||
} else { | ||
this.searchError = '' // Clear any previous errors | ||
} | ||
this.searchResults = data | ||
}) | ||
}) | ||
.catch((err) => { | ||
this.searchError = err.message || 'An error occurred' | ||
console.error(err.message ?? err) | ||
}) | ||
}, | ||
clearSearch() { | ||
this.search = '' | ||
this.searchError = '' | ||
}, | ||
}, | ||
}) | ||
export const useSearchStore = defineStore( | ||
'search', { | ||
state: () => ({ | ||
search: '', | ||
searchResults: '', | ||
searchError: '', | ||
}), | ||
actions: { | ||
setSearch(search) { | ||
this.search = search | ||
console.log('Active search set to ' + search) | ||
}, | ||
setSearchResults(searchResults) { | ||
this.searchResults = searchResults | ||
console.log('Active search set to ' + searchResults) | ||
}, | ||
/* istanbul ignore next */ // ignore this for Jest until moved into a service | ||
getSearchResults() { | ||
fetch( | ||
'/index.php/apps/opencatalogi/api/search?_search=' + this.search, | ||
{ | ||
method: 'GET', | ||
}, | ||
) | ||
.then( | ||
(response) => { | ||
response.json().then( | ||
(data) => { | ||
if (data?.code === 403 && data?.message) { | ||
this.searchError = data.message | ||
console.log(this.searchError) | ||
} else { | ||
this.searchError = '' // Clear any previous errors | ||
} | ||
this.searchResults = data | ||
} | ||
) | ||
} | ||
) | ||
.catch( | ||
(err) => { | ||
this.searchError = err.message || 'An error occurred' | ||
console.error(err.message ?? err) | ||
} | ||
) | ||
}, | ||
clearSearch() { | ||
this.search = '' | ||
this.searchError = '' | ||
}, | ||
}, | ||
} | ||
) |
Oops, something went wrong.