mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 23:06:11 +00:00
Merge pull request #383 from zurdi15/romm-378
[ROMM-378] Fixes to search and pinia store
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { uniqBy } from "lodash";
|
||||
import { defineStore } from "pinia";
|
||||
|
||||
export default defineStore("roms", {
|
||||
@@ -23,20 +24,27 @@ export default defineStore("roms", {
|
||||
},
|
||||
|
||||
actions: {
|
||||
_reorder() {
|
||||
// Sort roms by name and remove duplicates
|
||||
this._all = uniqBy(
|
||||
this._all.sort((a, b) =>
|
||||
a.file_name_no_tags.localeCompare(b.file_name_no_tags)
|
||||
),
|
||||
"id"
|
||||
);
|
||||
},
|
||||
// All roms
|
||||
set(roms) {
|
||||
this._all = roms;
|
||||
this._reorder();
|
||||
},
|
||||
add(roms) {
|
||||
this._all = this._all.concat(roms);
|
||||
this._reorder();
|
||||
},
|
||||
update(rom) {
|
||||
this._all = this._all.map((value) => {
|
||||
if (value.id === rom.id) {
|
||||
return rom;
|
||||
}
|
||||
return value;
|
||||
});
|
||||
this._all = this._all.map((value) => (value.id === rom.id ? rom : value));
|
||||
this._reorder();
|
||||
},
|
||||
remove(roms) {
|
||||
this._all = this._all.filter((value) => {
|
||||
|
||||
@@ -64,14 +64,19 @@ async function fetchRoms(platform) {
|
||||
searchTerm: normalizeString(galleryFilter.filter),
|
||||
})
|
||||
.then((response) => {
|
||||
// Add any new roms to the store
|
||||
const allRomsSet = [...allRoms.value, ...response.data.items];
|
||||
romsStore.set(allRomsSet);
|
||||
romsStore.setFiltered(allRomsSet);
|
||||
|
||||
if (isFiltered) {
|
||||
searchCursor.value = response.data.next_page;
|
||||
romsStore.setSearch([...searchRoms.value, ...response.data.items]);
|
||||
romsStore.setFiltered(searchRoms.value);
|
||||
|
||||
const serchedRomsSet = [...searchRoms.value, ...response.data.items];
|
||||
romsStore.setSearch(serchedRomsSet);
|
||||
romsStore.setFiltered(serchedRomsSet);
|
||||
} else {
|
||||
cursor.value = response.data.next_page;
|
||||
romsStore.set([...allRoms.value, ...response.data.items]);
|
||||
romsStore.setFiltered(allRoms.value);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user