From faa8f45985519402d0d4f0971c852d94dfb2e7e4 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 10 Sep 2023 17:07:42 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactor=20code=20for=20better?= =?UTF-8?q?=20readability=20=F0=9F=93=A6=20Imported=20=5F=5Fposts=20and=20?= =?UTF-8?q?necessary=20dependencies=20=F0=9F=A7=A9=20Transformed=20=5F=5Fp?= =?UTF-8?q?osts=20data=20for=20main=20demo=20=F0=9F=93=9A=20Set=20up=20cat?= =?UTF-8?q?egories=20and=20authors=20=F0=9F=9A=80=20Ready=20to=20showcase?= =?UTF-8?q?=20the=20main=20demo!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/posts.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/data/posts.ts diff --git a/src/data/posts.ts b/src/data/posts.ts new file mode 100644 index 0000000..7dd1393 --- /dev/null +++ b/src/data/posts.ts @@ -0,0 +1,20 @@ +import __posts from "./jsons/__posts.json"; +import { DEMO_CATEGORIES } from "./taxonomies"; +import { PostDataType } from "./types"; +import { DEMO_AUTHORS } from "./authors"; + +// FOR MAIN DEMO +const DEMO_POSTS = __posts.map((post): PostDataType => { + // ########## GET CATEGORY BY CAT ID ######## // + const categories = post.categoriesId.map( + (id) => DEMO_CATEGORIES.filter((taxonomy) => taxonomy.id === id)[0] + ); + + return { + ...post, + author: DEMO_AUTHORS.filter((user) => user.id === post.authorId)[0], + categories: [categories[0]], + } as PostDataType; +}); + +export { DEMO_POSTS };