Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(com-pwa): sort user based last order #1211

Merged
merged 4 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions uniquely/com-pwa/src/ui/page/admin-order-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
state,
ScheduleUpdateToFrameMixin,
when,
mapObject,
mapIterable,
type PropertyValues,
} from '@alwatr/element';
import {message} from '@alwatr/i18n';
Expand Down Expand Up @@ -153,12 +153,25 @@ export class AlwatrPageAdminOrderList extends ScheduleUpdateToFrameMixin(
private _render_usersList(): unknown {
const userStorage = userListIncOrderStorageContextConsumer.getResponse();
this._logger.logMethodArgs?.('renderUsersList', {userStorage});
if (userStorage == null) return;

return mapObject(
const orderStorageList = Object.values(userStorage.data).sort((u1, u2) => {
const lastU1Order = Object.values(u1.orderList).sort((o1, o2) => {
return (o2.meta?.updated || 0) - (o1.meta?.updated || 0);
})[0];

const lastU2Order = Object.values(u2.orderList).sort((o1, o2) => {
return (o2.meta?.updated || 0) - (o1.meta?.updated || 0);
})[0];

return (lastU2Order?.meta?.updated || 0) - (lastU1Order?.meta?.updated || 0);
});

return mapIterable(
this,
userStorage?.data,
(user) => {
return html`<alwatr-user-inc-order-box .userIncOrder=${user}></alwatr-user-inc-order-box>`;
orderStorageList,
(userIncOrder) => {
return html`<alwatr-user-inc-order-box .userIncOrder=${userIncOrder}></alwatr-user-inc-order-box>`;
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion uniquely/com-pwa/src/ui/page/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AlwatrPageHome extends UnresolvedMixin(SignalMixin(AlwatrBaseElemen
if (userProfileContextConsumer.getValue()?.permissions === 'root') {
redirect({sectionList: ['admin-order-list']});
}
}));
}, {receivePrevious: 'No'}));

this._addSignalListeners(homePageContentContextConsumer.subscribe((content) => {
this.content = content;
Expand Down
22 changes: 14 additions & 8 deletions uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
css,
customElement,
html,
mapObject,
mapIterable,
property,
} from '@alwatr/element';
import {date, message} from '@alwatr/i18n';
Expand Down Expand Up @@ -103,19 +103,25 @@ export class alwatrUserIncOrderBox extends LocalizeMixin(SignalMixin(AlwatrBaseE
}

protected _renderOrderBox(): unknown {
let orderList;
if (Object.keys(this.userIncOrder!.orderList).length === 0) {
orderList = html`<span class="empty-order"
>${message('page_admin_order_list_empty_order_list')}<span></span
></span>`;
let orderListTemplate;
const orderListValues = Object.values(this.userIncOrder?.orderList ?? {});
if (orderListValues.length === 0) {
orderListTemplate = html`
<span class="empty-order">
${message('page_admin_order_list_empty_order_list')}
<span>`;
}
else {
orderList = mapObject(this, this.userIncOrder!.orderList, (order) => this._renderOrderInfo(order));
const orderList = orderListValues.sort((o1, o2) => {
return (o2.meta?.updated || 0) - (o1.meta?.updated || 0);
});

orderListTemplate = mapIterable(this, orderList, (order) => this._renderOrderInfo(order));
}

return html`
<h3>${message('page_admin_order_list_order_list')}:</h3>
<alwatr-surface class="detail-container order-container"> ${orderList} </alwatr-surface>
<alwatr-surface class="detail-container order-container"> ${orderListTemplate} </alwatr-surface>
`;
}

Expand Down