Skip to content

Commit

Permalink
improve single page app
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofox3 committed Mar 21, 2024
1 parent ecc14fa commit 7a3bf62
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apps/restaurant-cashier/cart/cart-product-item.component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { compose } from '../utils/functions.js';
import { reactiveProps } from '../utils/components.js';
import { withView } from '@cofn/view';
import { withProps } from '@cofn/controllers';

const compositionPipeline = compose([reactiveProps(['product']), withView]);
const compositionPipeline = compose([withProps(['product']), withView]);

export const CartProductItem = compositionPipeline(({ html, $host }) => {
return ({ properties: { product } }) => {
Expand Down
5 changes: 4 additions & 1 deletion apps/restaurant-cashier/cart/cart.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ export const loadPage = ({ define }) => {
'app-cart-product-list',
withCartController(withView(CartProductList)),
);
return template.content.cloneNode(true);
return {
title: 'Current cart',
content: template.content.cloneNode(true),
};
};
1 change: 1 addition & 0 deletions apps/restaurant-cashier/components/ui-icon.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ svg {
</svg>
`;

// todo add script to cherry pick the icons used
const spriteURL = `/node_modules/bootstrap-icons/bootstrap-icons.svg`;

export const UIIcon = function* ({ $host, $root }) {
Expand Down
5 changes: 4 additions & 1 deletion apps/restaurant-cashier/dashboard/dashboard.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ export const loadPage = ({ define }) => {
define('app-top-items-chart', chart(TopItemsChart));
define('app-top-items-revenue-chart', chart(TopItemsRevenueChart));

return template.content.cloneNode(true);
return {
title: 'Dashboard',
content: template.content.cloneNode(true),
};
};
9 changes: 6 additions & 3 deletions apps/restaurant-cashier/products/edit/edit-product.page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createElement } from '../../utils/dom.js';
import { productListService } from '../product-list.service.js';
import { fromForm } from '../product-list.model.js';
import { reactiveProps } from '../../utils/components.js';
import { withView } from '@cofn/view';
import { ImageUploader } from '../image-uploader/image-uploader.component.js';
import { compose } from '../../utils/functions.js';
import { withProps } from '@cofn/controllers';
export const loadPage = async ({ define, state }) => {
define('app-edit-product', EditProductForm);
define('app-image-uploader', ImageUploader, {
Expand All @@ -23,10 +23,13 @@ export const loadPage = async ({ define, state }) => {
});
const el = createElement('app-edit-product');
el.product = product;
return el;
return {
title: `Edit ${product.title}`,
content: el,
};
};

const wrapComponent = compose([reactiveProps(['product']), withView]);
const wrapComponent = compose([withProps(['product']), withView]);

const EditProductForm = wrapComponent(({ html, router, $host }) => {
return ({ properties: { product } }) => html`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { withView } from '@cofn/view';
import { compose } from '../../utils/functions.js';
import { reactiveProps } from '../../utils/components.js';
import { withProps } from '@cofn/controllers';

const compositionPipeline = compose([reactiveProps(['product']), withView]);
const compositionPipeline = compose([withProps(['product']), withView]);

export const ProductListItem = compositionPipeline(({ html, $host }) => {
const onclickHandler = (ev) => {
Expand Down
5 changes: 4 additions & 1 deletion apps/restaurant-cashier/products/list/product-list.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ export const loadPage = async ({ define, state }) => {
if (state?.sku) {
element.setAttribute('target-sku', state.sku);
}
return element;
return {
title: 'Products',
content: element,
};
};
5 changes: 4 additions & 1 deletion apps/restaurant-cashier/products/new/new-product.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,8 @@ export const loadPage = async ({ router }) => {
'image-uploaded',
({ detail }) => (form.querySelector('[name=image]').value = detail.url),
);
return page;
return {
title: 'New product',
content: page,
};
};
1 change: 0 additions & 1 deletion apps/restaurant-cashier/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ It solves most of the problematics you can get while building a single page app:
* form and custom validation
* user preferences management (theme, animation)
* advanced components (select list, file upload with drag and drop)

5 changes: 3 additions & 2 deletions apps/restaurant-cashier/router/page-outlet.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const PageOutlet = pageOutlet(function* ({ $host, preferencesService }) {
const { page } = yield;
if (page) {
const { motion } = preferencesService.getState();
const autofocusElement = page.querySelector('[autofocus]');
const autofocusElement = page.content.querySelector('[autofocus]');
if (
!document.startViewTransition ||
motion?.computed === motionSettings.reduced
Expand All @@ -44,6 +44,7 @@ export const PageOutlet = pageOutlet(function* ({ $host, preferencesService }) {
}

function updateDOM({ page }) {
$host.replaceChildren(page);
$host.replaceChildren(page.content);
document.title = page.title;
}
});
5 changes: 4 additions & 1 deletion apps/restaurant-cashier/users/me.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ export const loadPage = async ({ define, preferencesService }) => {
withPreferencesController(withView(PreferencesComponent)),
);

return template.content.cloneNode(true);
return {
title: 'Settings',
content: template.content.cloneNode(true),
};
};
2 changes: 0 additions & 2 deletions apps/restaurant-cashier/utils/components.js

This file was deleted.

0 comments on commit 7a3bf62

Please sign in to comment.