Skip to content

Commit e5fc6fb

Browse files
committed
Add ALVIs for both types of book page
1 parent b133798 commit e5fc6fb

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/app/components/elements/list-groups/ListView.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { AbstractListViewItem, AbstractListViewItemProps, ListViewTagProps } from "./AbstractListViewItem";
33
import { ShortcutResponse, ViewingContext } from "../../../../IsaacAppTypes";
44
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";
66
import { ListGroup, ListGroupItem, ListGroupProps } from "reactstrap";
77
import { TitleIconProps } from "../PageTitle";
88
import { AffixButton } from "../AffixButton";
@@ -216,6 +216,42 @@ export const ShortcutListViewItem = ({item, ...rest}: ShortcutListViewItemProps)
216216
/>;
217217
};
218218

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+
219255
export const ListViewCards = (props: {cards: (ListViewCardProps | null)[]} & {showBlanks?: boolean} & ListGroupProps) => {
220256
const { cards, showBlanks, ...rest } = props;
221257
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
258294
return <QuizListViewItem key={index} {...rest} item={item}/>;
259295
case SEARCH_RESULT_TYPE.GAMEBOARD:
260296
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}/>;
261301
default:
262302
// Do not render this item if there is no matching DOCUMENT_TYPE
263303
console.error("Not able to display item as a ListViewItem: ", item);

src/app/services/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ export enum DOCUMENT_TYPE {
913913
CONCEPT = "isaacConceptPage",
914914
QUESTION = "isaacQuestionPage",
915915
FAST_TRACK_QUESTION = "isaacFastTrackQuestionPage",
916+
BOOK_INDEX_PAGE = "isaacBookIndexPage",
916917
EVENT = "isaacEventPage",
917918
TOPIC_SUMMARY = "isaacTopicSummaryPage",
918919
GENERIC = "page",
@@ -925,12 +926,14 @@ export function isAQuestionLikeDoc(doc: ContentDTO): doc is IsaacQuestionPageDTO
925926
export enum SEARCH_RESULT_TYPE {
926927
SHORTCUT = "shortcut",
927928
GAMEBOARD = "gameboard",
929+
BOOK_DETAIL_PAGE = "isaacBookDetailPage",
928930
}
929931

930932
export const documentDescription: {[documentType in DOCUMENT_TYPE]: string} = {
931933
[DOCUMENT_TYPE.CONCEPT]: "Concepts",
932934
[DOCUMENT_TYPE.QUESTION]: "Questions",
933935
[DOCUMENT_TYPE.FAST_TRACK_QUESTION]: "Questions",
936+
[DOCUMENT_TYPE.BOOK_INDEX_PAGE]: "Books",
934937
[DOCUMENT_TYPE.EVENT]: "Events",
935938
[DOCUMENT_TYPE.TOPIC_SUMMARY]: "Topics",
936939
[DOCUMENT_TYPE.GENERIC]: "Other pages",
@@ -942,6 +945,7 @@ export const documentTypePathPrefix: {[documentType in DOCUMENT_TYPE]: string} =
942945
[DOCUMENT_TYPE.CONCEPT]: "concepts",
943946
[DOCUMENT_TYPE.QUESTION]: "questions",
944947
[DOCUMENT_TYPE.FAST_TRACK_QUESTION]: "questions",
948+
[DOCUMENT_TYPE.BOOK_INDEX_PAGE]: "books",
945949
[DOCUMENT_TYPE.EVENT]: "events",
946950
[DOCUMENT_TYPE.TOPIC_SUMMARY]: "topics",
947951
[DOCUMENT_TYPE.QUIZ]: "quiz",

0 commit comments

Comments
 (0)