From 98796b5007981224516cd90846b861404b27f1de Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Sat, 14 Oct 2023 08:56:01 +0200 Subject: [PATCH] Revert "Day 3: Set up the project to illustrate error and loading templates" --- my-app/app/controllers/products/error.css | 3 --- .../app/controllers/products/error.css.d.ts | 5 ---- my-app/app/controllers/products/error.ts | 7 ------ my-app/app/controllers/products/loading.css | 3 --- .../app/controllers/products/loading.css.d.ts | 5 ---- my-app/app/controllers/products/loading.ts | 7 ------ my-app/app/routes/products/product.ts | 24 +++++++++---------- my-app/app/utils/services/experiments.ts | 4 ++-- my-app/mirage/config.js | 2 +- 9 files changed, 14 insertions(+), 46 deletions(-) delete mode 100644 my-app/app/controllers/products/error.css delete mode 100644 my-app/app/controllers/products/error.css.d.ts delete mode 100644 my-app/app/controllers/products/error.ts delete mode 100644 my-app/app/controllers/products/loading.css delete mode 100644 my-app/app/controllers/products/loading.css.d.ts delete mode 100644 my-app/app/controllers/products/loading.ts diff --git a/my-app/app/controllers/products/error.css b/my-app/app/controllers/products/error.css deleted file mode 100644 index 48d2a4e4..00000000 --- a/my-app/app/controllers/products/error.css +++ /dev/null @@ -1,3 +0,0 @@ -.container { - composes: product-details from "./product.css"; -} diff --git a/my-app/app/controllers/products/error.css.d.ts b/my-app/app/controllers/products/error.css.d.ts deleted file mode 100644 index 7f4a7895..00000000 --- a/my-app/app/controllers/products/error.css.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare const styles: { - readonly 'container': string; -}; - -export default styles; diff --git a/my-app/app/controllers/products/error.ts b/my-app/app/controllers/products/error.ts deleted file mode 100644 index 9c88f4f9..00000000 --- a/my-app/app/controllers/products/error.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Controller from '@ember/controller'; - -import styles from './error.css'; - -export default class ProductsErrorController extends Controller { - styles = styles; -} diff --git a/my-app/app/controllers/products/loading.css b/my-app/app/controllers/products/loading.css deleted file mode 100644 index 48d2a4e4..00000000 --- a/my-app/app/controllers/products/loading.css +++ /dev/null @@ -1,3 +0,0 @@ -.container { - composes: product-details from "./product.css"; -} diff --git a/my-app/app/controllers/products/loading.css.d.ts b/my-app/app/controllers/products/loading.css.d.ts deleted file mode 100644 index 7f4a7895..00000000 --- a/my-app/app/controllers/products/loading.css.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare const styles: { - readonly 'container': string; -}; - -export default styles; diff --git a/my-app/app/controllers/products/loading.ts b/my-app/app/controllers/products/loading.ts deleted file mode 100644 index 33e411b6..00000000 --- a/my-app/app/controllers/products/loading.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Controller from '@ember/controller'; - -import styles from './loading.css'; - -export default class ProductsLoadingController extends Controller { - styles = styles; -} diff --git a/my-app/app/routes/products/product.ts b/my-app/app/routes/products/product.ts index 751c0d6a..204db333 100644 --- a/my-app/app/routes/products/product.ts +++ b/my-app/app/routes/products/product.ts @@ -4,9 +4,9 @@ import { type Registry as Services, service } from '@ember/service'; import type { ModelFrom } from '../../utils/routes'; import type { Product } from '../../utils/routes/products'; +import type ProductsRoute from '../products'; export default class ProductsProductRoute extends Route { - @service declare api: Services['api']; @service declare experiments: Services['experiments']; @service declare router: Services['router']; @@ -23,23 +23,21 @@ export default class ProductsProductRoute extends Route { } } - model(params: { id: string }): Promise { + model(params: { id: string }): Product { const { id } = params; + const products = this.modelFor('products') as ModelFrom; - /* - Uncomment the next line to render products/error.hbs. - */ - // throw new Error('Some server error.'); + const product = products.find((product) => product.id === id); - return this.api.get(`/products/${id}`); - } - - @action error(error: any /*, transition */) { - console.error(error); + if (!product) { + throw new Error(`Could not find the product with ID ${id}.`); + } - return true; + return product; + } - // this.router.replaceWith('products'); + @action error(/* error, transition */) { + this.router.replaceWith('products'); } } diff --git a/my-app/app/utils/services/experiments.ts b/my-app/app/utils/services/experiments.ts index 7b661c94..01fbe5b3 100644 --- a/my-app/app/utils/services/experiments.ts +++ b/my-app/app/utils/services/experiments.ts @@ -1,7 +1,7 @@ const experimentsForProduction = { 'nest-product-details': { - control: 0, - v1: 1, + control: 0.5, + v1: 0.5, }, 'subscribe-to-ember-times': { control: 0.7, diff --git a/my-app/mirage/config.js b/my-app/mirage/config.js index 30071400..6e5bb953 100644 --- a/my-app/mirage/config.js +++ b/my-app/mirage/config.js @@ -15,7 +15,7 @@ function routes() { Uncomment the next line to make the loading spinner visible for some time. */ - this.timing = 1000; + // this.timing = 1000; /* Shorthand cheatsheet: