mirror of
https://github.com/Qortal/q-shop.git
synced 2025-02-01 07:42:21 +00:00
Sort stores list by most recent update
This commit is contained in:
parent
33961553a3
commit
9608e9faef
@ -48,7 +48,7 @@ export const StoreList = () => {
|
|||||||
const offset = stores.length;
|
const offset = stores.length;
|
||||||
const query = STORE_BASE;
|
const query = STORE_BASE;
|
||||||
// Fetch list of user stores' resources from Qortal blockchain
|
// Fetch list of user stores' resources from Qortal blockchain
|
||||||
const url = `/arbitrary/resources/search?service=STORE&query=${query}&limit=20&mode=ALL&prefix=true&includemetadata=false&offset=${offset}&reverse=true`;
|
const url = `/arbitrary/resources/search?service=STORE&query=${query}&limit=200&mode=ALL&prefix=true&includemetadata=false&offset=${offset}&reverse=true`;
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
@ -71,9 +71,11 @@ export const StoreList = () => {
|
|||||||
id: storeItem.identifier,
|
id: storeItem.identifier,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
// Sort the array of stores by most recent 'updated' timestamp (use 'created' as fallback if never updated)
|
||||||
|
const sortedStructureData = structureData.sort((a: Store, b: Store) => (b.updated ?? b.created) - (a.updated ?? a.created));
|
||||||
// Add stores to localstate & guard against duplicates
|
// Add stores to localstate & guard against duplicates
|
||||||
const copiedStores: Store[] = [...stores];
|
const copiedStores: Store[] = [...stores];
|
||||||
structureData.forEach((storeItem: Store) => {
|
sortedStructureData.forEach((storeItem: Store) => {
|
||||||
const index = stores.findIndex((p: Store) => p.id === storeItem.id);
|
const index = stores.findIndex((p: Store) => p.id === storeItem.id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
copiedStores[index] = storeItem;
|
copiedStores[index] = storeItem;
|
||||||
@ -83,7 +85,7 @@ export const StoreList = () => {
|
|||||||
});
|
});
|
||||||
dispatch(upsertStores(copiedStores));
|
dispatch(upsertStores(copiedStores));
|
||||||
// Get the store raw data from getStore API Call only if the hashmapStore doesn't have the store or if the store is more recently updated than the existing store
|
// Get the store raw data from getStore API Call only if the hashmapStore doesn't have the store or if the store is more recently updated than the existing store
|
||||||
for (const content of structureData) {
|
for (const content of sortedStructureData) {
|
||||||
if (content.owner && content.id) {
|
if (content.owner && content.id) {
|
||||||
const res = checkAndUpdateResource({
|
const res = checkAndUpdateResource({
|
||||||
id: content.id,
|
id: content.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user