From 20fa80370b60089cbaebf3dc6ab8288c2613fc6b Mon Sep 17 00:00:00 2001 From: Ardeman Date: Sun, 2 Mar 2025 12:37:19 +0800 Subject: [PATCH] refactor: replace hardcoded descriptions with a constant for consistency --- app/data/contents.ts | 11 +++++------ app/pages/news-categories/data.ts | 4 ++-- app/pages/news-categories/index.tsx | 17 ++++++++++++++++- app/pages/news-detail/data.ts | 4 ++-- app/types/news.ts | 1 - 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/data/contents.ts b/app/data/contents.ts index 2606211..9fcd64a 100644 --- a/app/data/contents.ts +++ b/app/data/contents.ts @@ -1,9 +1,10 @@ import type { TNews } from '~/types/news' +export const DUMMY_DESCRIPTION = 'Berita Terhangat hari ini' + export const SPOTLIGHT: TNews = { title: 'SPOTLIGHT', - description: 'Berita Terhangat hari ini', - type: 'hero', + description: DUMMY_DESCRIPTION, items: [ { title: '01 Hotman Paris Membuka Perpustakaan di tengah Diskotik', @@ -31,8 +32,7 @@ export const SPOTLIGHT: TNews = { export const BERITA: TNews = { title: 'BERITA', - description: 'Berita Terhangat hari ini', - type: 'grid', + description: DUMMY_DESCRIPTION, items: [ { title: '01 Travelling as a way of self-discovery and progress ', @@ -89,8 +89,7 @@ export const BERITA: TNews = { export const KAJIAN: TNews = { title: 'KAJIAN', - description: 'Berita Terhangat hari ini', - type: 'grid', + description: DUMMY_DESCRIPTION, items: [ { title: 'Travelling as a way of self-discovery and progress', diff --git a/app/pages/news-categories/data.ts b/app/pages/news-categories/data.ts index af44db7..a640e10 100644 --- a/app/pages/news-categories/data.ts +++ b/app/pages/news-categories/data.ts @@ -1,9 +1,9 @@ +import { DUMMY_DESCRIPTION } from '~/data/contents' import type { TNews } from '~/types/news' export const BERITA: TNews = { title: 'BERITA', - description: 'Berita Terhangat hari ini', - type: 'grid', + description: DUMMY_DESCRIPTION, items: [ { title: 'Travelling as a way of self-discovery and progress', diff --git a/app/pages/news-categories/index.tsx b/app/pages/news-categories/index.tsx index 1e8768d..9e66742 100644 --- a/app/pages/news-categories/index.tsx +++ b/app/pages/news-categories/index.tsx @@ -1,13 +1,28 @@ +import { useLocation, useRouteLoaderData } from 'react-router' + import { Card } from '~/components/ui/card' import { CategorySection } from '~/components/ui/category-section' +import { DUMMY_DESCRIPTION } from '~/data/contents' +import type { loader } from '~/routes/_layout' import { BERITA } from './data' export const NewsCategoriesPage = () => { + const { pathname } = useLocation() + const code = pathname.split('/')[2] + const loaderData = useRouteLoaderData('routes/_layout') + const { name } = + loaderData?.categoriesData.find((item) => item.code === code) || {} + const { items } = BERITA + return (
- +
) diff --git a/app/pages/news-detail/data.ts b/app/pages/news-detail/data.ts index cb61d9b..92f69b4 100644 --- a/app/pages/news-detail/data.ts +++ b/app/pages/news-detail/data.ts @@ -1,3 +1,4 @@ +import { DUMMY_DESCRIPTION } from '~/data/contents' import type { TNews, TNewsDetail } from '~/types/news' export const CONTENT: TNewsDetail = { @@ -40,8 +41,7 @@ export const CONTENT: TNewsDetail = { export const BERITA: TNews = { title: 'BERITA', - description: 'Berita Terhangat hari ini', - type: 'grid', + description: DUMMY_DESCRIPTION, items: [ { title: 'Travelling as a way of self-discovery and progress', diff --git a/app/types/news.ts b/app/types/news.ts index bb9ff12..d04e998 100644 --- a/app/types/news.ts +++ b/app/types/news.ts @@ -1,7 +1,6 @@ export type TNews = { title: string description: string - type: 'hero' | 'grid' items: Pick< TNewsDetail, 'title' | 'content' | 'featured' | 'slug' | 'tags' | 'isPremium'