WO8TimeSpace175ZERO2 / genma-taisen-to-the-north-of-kanamachi

0 stars 1 forks source link

コラムの作成日と更新日をURI変数に指定するのは流石におかしい #12

Closed WO8TimeSpace175ZERO2 closed 5 years ago

WO8TimeSpace175ZERO2 commented 5 years ago

コラムの詳細ページを表示させる際に、 koramudetails/${kijiId}/${title}/${createdDate}/${modifiedDate} という風にタイトルと作成日と更新日を指定しているのが蛇足に思える。

WO8TimeSpace175ZERO2 commented 5 years ago

こちらのプル・リクエストをマージ。 https://github.com/WO8TimeSpace175ZERO2/genma-taisen-to-the-north-of-kanamachi/pull/19/commits

一旦、別アプリで静的に用意したkoramus.jsonをhttpクライアントのRESTAPIで画面表示の都度にダウンロードし、 kijiId(articleId)で配列を検索して、見つかった要素のタイトルと作成日と更新日を表示するに実装した。 https://github.com/hexagonminer/kgw/commit/b11029c3976f1fc8ab44196330154dbee4f8a485

しかし、これでは、都度ダウンロードするのが冗長。 koramus.jsonをSPAの資源に組み込むように変更した。 https://github.com/hexagonminer/kgw/commit/c217c14467b788748482887edb6706a6b74ab2d1

tsconfig.jsonのcompilerOptionsセクションにて、次の3つの設定を追加。 "resolveJsonModule": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true,

その上で、 記事詳細ページで、 import KijiItemsJson from '../const/koramus.json'; という風にjsonのオブジェクトをインポートし、 ngOnInitメソッド内で this.kijiItem = KijiItemsJson.kijiItems.find((kijiItem) => kijiItem.kijiId === this.articleId); という風に、jsonから取得したJSオブジェクトを記事IDで検索して一致した要素の内容を 画面に表示するように修正した。

コラム詳細ページのngOnInitメソッド内で、