@@ -2,7 +2,7 @@ import React from "react";
2
2
import { AbstractListViewItem , AbstractListViewItemProps , ListViewTagProps } from "./AbstractListViewItem" ;
3
3
import { ShortcutResponse , ViewingContext } from "../../../../IsaacAppTypes" ;
4
4
import { determineAudienceViews } from "../../../services/userViewingContext" ;
5
- import { DOCUMENT_TYPE , documentTypePathPrefix , getThemeFromContextAndTags , PATHS , SEARCH_RESULT_TYPE , siteSpecific , Subject , TAG_ID , TAG_LEVEL , tags } from "../../../services" ;
5
+ import { DOCUMENT_TYPE , documentTypePathPrefix , getThemeFromContextAndTags , ISAAC_BOOKS , PATHS , SEARCH_RESULT_TYPE , siteSpecific , Subject , TAG_ID , TAG_LEVEL , tags } from "../../../services" ;
6
6
import { ListGroup , ListGroupItem , ListGroupProps } from "reactstrap" ;
7
7
import { TitleIconProps } from "../PageTitle" ;
8
8
import { AffixButton } from "../AffixButton" ;
@@ -216,6 +216,42 @@ export const ShortcutListViewItem = ({item, ...rest}: ShortcutListViewItemProps)
216
216
/> ;
217
217
} ;
218
218
219
+ interface BookIndexListViewItemProps extends Omit < AbstractListViewItemProps , "icon" | "url" > {
220
+ item : ShortcutResponse ;
221
+ }
222
+
223
+ export const BookIndexListViewItem = ( { item, ...rest } : BookIndexListViewItemProps ) => {
224
+ const itemSubject = tags . getSpecifiedTag ( TAG_LEVEL . subject , item . tags as TAG_ID [ ] ) ?. id as Subject ;
225
+
226
+ return < AbstractListViewItem
227
+ { ...item }
228
+ icon = { { type : "hex" , icon : "icon-book" , size : "lg" } }
229
+ url = { `/${ documentTypePathPrefix [ DOCUMENT_TYPE . BOOK_INDEX_PAGE ] } /${ item . id ?. slice ( "book_" . length ) } ` }
230
+ subject = { itemSubject }
231
+ { ...rest }
232
+ /> ;
233
+ } ;
234
+
235
+ interface BookDetailListViewItemProps extends AbstractListViewItemProps {
236
+ item : ShortcutResponse ;
237
+ }
238
+
239
+ export const BookDetailListViewItem = ( { item, ...rest } : BookDetailListViewItemProps ) => {
240
+ const itemSubject = tags . getSpecifiedTag ( TAG_LEVEL . subject , item . tags as TAG_ID [ ] ) ?. id as Subject ;
241
+ const itemBook = ISAAC_BOOKS . find ( ( book ) => item . tags ?. includes ( book . tag ) ) ;
242
+ const itemLabel = itemBook ? item . id ?. slice ( `book_${ itemBook . tag } _` . length ) : undefined ;
243
+
244
+ return < AbstractListViewItem
245
+ { ...item }
246
+ icon = { { type : "hex" , icon : "icon-generic" , size : "lg" } }
247
+ title = { `${ itemLabel ? ( itemLabel ?. toUpperCase ( ) + " " ) : "" } ${ item . title } ` }
248
+ subtitle = { itemBook ?. title }
249
+ url = { itemBook ? `/${ documentTypePathPrefix [ DOCUMENT_TYPE . BOOK_INDEX_PAGE ] } /${ itemBook . tag } /${ itemLabel } ` : undefined }
250
+ subject = { itemSubject }
251
+ { ...rest }
252
+ /> ;
253
+ } ;
254
+
219
255
export const ListViewCards = ( props : { cards : ( ListViewCardProps | null ) [ ] } & { showBlanks ?: boolean } & ListGroupProps ) => {
220
256
const { cards, showBlanks, ...rest } = props ;
221
257
return < ListGroup { ...rest } className = { classNames ( "list-view-card-container link-list list-group-links p-0 m-0 flex-row row-cols-1 row-cols-lg-2 row" , rest . className ) } >
@@ -258,6 +294,10 @@ export const ListView = ({items, className, ...rest}: ListViewProps & ListViewIt
258
294
return < QuizListViewItem key = { index } { ...rest } item = { item } /> ;
259
295
case SEARCH_RESULT_TYPE . GAMEBOARD :
260
296
return < QuestionDeckListViewItem key = { index } { ...rest } item = { item } /> ;
297
+ case DOCUMENT_TYPE . BOOK_INDEX_PAGE :
298
+ return < BookIndexListViewItem key = { index } { ...rest } item = { item } /> ;
299
+ case SEARCH_RESULT_TYPE . BOOK_DETAIL_PAGE :
300
+ return < BookDetailListViewItem key = { index } { ...rest } item = { item } /> ;
261
301
default :
262
302
// Do not render this item if there is no matching DOCUMENT_TYPE
263
303
console . error ( "Not able to display item as a ListViewItem: " , item ) ;
0 commit comments