1- import type { SpotlightTemplateName } from '../types/spotlight' ;
1+ import type {
2+ SpotlightCategory ,
3+ SpotlightCategoryName ,
4+ SpotlightTemplateName ,
5+ } from '../types/spotlight' ;
26
3- import type { SpotlightItem } from '@/types/api' ;
7+ import type { SpotlightItem , SpotlightItemWithDetails } from '@/types/api' ;
48
59/**
610 * Build a lookup object, that maps spotlight template names to category names
711 * @param categories - array of category objects
812 * @returns lookup object
913 */
1014export const buildCategoryLookup = (
11- categories : Array < { name : string ; templates : SpotlightTemplateName [ ] } > ,
12- ) : Record < SpotlightTemplateName , string > => {
13- const lookup : Record < SpotlightTemplateName , string > = { } as Record < SpotlightTemplateName , string > ;
15+ categories : Array < SpotlightCategory > ,
16+ ) : Record < SpotlightTemplateName , SpotlightCategoryName > => {
17+ const lookup : Record < SpotlightTemplateName , SpotlightCategoryName > = { } as Record <
18+ SpotlightTemplateName ,
19+ SpotlightCategoryName
20+ > ;
1421
1522 categories . forEach ( ( category ) => {
1623 category . templates . forEach ( ( template ) => {
@@ -29,9 +36,12 @@ export const buildCategoryLookup = (
2936 */
3037export const groupSpotlightData = (
3138 spotlightData : SpotlightItem [ ] ,
32- templateLookup : Record < SpotlightTemplateName , string > ,
33- ) : Record < string , SpotlightItem [ ] > => {
34- const groupedData : Record < string , SpotlightItem [ ] > = { } ;
39+ templateLookup : Record < SpotlightTemplateName , SpotlightCategoryName > ,
40+ ) : Record < SpotlightCategoryName , SpotlightItem [ ] > => {
41+ const groupedData : Record < SpotlightCategoryName , SpotlightItem [ ] > = { } as Record <
42+ SpotlightCategoryName ,
43+ SpotlightItem [ ]
44+ > ;
3545
3646 spotlightData . forEach ( ( item ) => {
3747 if ( ! item || item . total === 0 ) {
@@ -44,7 +54,8 @@ export const groupSpotlightData = (
4454 return ;
4555 }
4656
47- const categoryName : string | undefined = templateLookup [ template as SpotlightTemplateName ] ;
57+ const categoryName : SpotlightCategoryName | undefined =
58+ templateLookup [ template as SpotlightTemplateName ] ;
4859
4960 if ( categoryName === undefined || categoryName === null ) {
5061 return ;
@@ -67,16 +78,19 @@ export const groupSpotlightData = (
6778 * @returns spotlight data ordered same as categories object order
6879 */
6980export const orderSpotlightData = (
70- groupedData : Record < string , SpotlightItem [ ] > ,
71- categories : Array < { name : string ; templates : SpotlightTemplateName [ ] } > ,
72- ) : Record < string , SpotlightItem [ ] > => {
73- const orderedData : Record < string , SpotlightItem [ ] > = { } ;
81+ groupedData : Record < SpotlightCategoryName , SpotlightItem [ ] > ,
82+ categories : Array < SpotlightCategory > ,
83+ ) : Record < string , SpotlightItemWithDetails [ ] > => {
84+ const orderedData : Record < string , SpotlightItemWithDetails [ ] > = { } ;
7485
7586 categories . forEach ( ( category ) => {
7687 const items = groupedData [ category . name ] ;
7788
78- if ( items !== undefined && items !== null ) {
79- orderedData [ category . name ] = items ;
89+ if ( items && items . length > 0 ) {
90+ orderedData [ category . name ] = items . map ( ( item ) => ( {
91+ ...item ,
92+ detailsScreenName : category . detailsScreenName ,
93+ } ) ) ;
8094 }
8195 } ) ;
8296
@@ -91,8 +105,8 @@ export const orderSpotlightData = (
91105 */
92106export const arrangeSpotlightData = (
93107 spotlightData : SpotlightItem [ ] ,
94- categories : Array < { name : string ; templates : SpotlightTemplateName [ ] } > ,
95- ) : Record < string , SpotlightItem [ ] > => {
108+ categories : Array < SpotlightCategory > ,
109+ ) : Record < string , SpotlightItemWithDetails [ ] > => {
96110 const templateLookup = buildCategoryLookup ( categories ) ;
97111 const groupedData = groupSpotlightData ( spotlightData , templateLookup ) ;
98112 const orderedData = orderSpotlightData ( groupedData , categories ) ;
0 commit comments