diff --git a/fakeyou/src/v2/api/category/ListTtsCategories.ts b/fakeyou/src/v2/api/category/ListTtsCategories.ts index 241350e16a..9c6ad22820 100644 --- a/fakeyou/src/v2/api/category/ListTtsCategories.ts +++ b/fakeyou/src/v2/api/category/ListTtsCategories.ts @@ -19,9 +19,9 @@ export interface TtsCategory { is_mod_approved?: boolean, - category_created_at: Date, - category_updated_at: Date, - category_deleted_at?: Date, + created_at: Date, + updated_at: Date, + deleted_at?: Date, } export interface ListTtsCategoriesErrorResponse { diff --git a/fakeyou/src/v2/view/_common/CategoryBreadcrumb.tsx b/fakeyou/src/v2/view/_common/CategoryBreadcrumb.tsx index 3184fd0871..6c65c345a8 100644 --- a/fakeyou/src/v2/view/_common/CategoryBreadcrumb.tsx +++ b/fakeyou/src/v2/view/_common/CategoryBreadcrumb.tsx @@ -4,10 +4,12 @@ import React from 'react'; import { Link } from 'react-router-dom'; import { FrontendUrlConfig } from '../../../common/FrontendUrlConfig'; import { TtsCategory } from '../../api/category/ListTtsCategories'; +import { TtsModelCategory } from '../../api/category/ListTtsCategoriesForModel'; export interface Props { // This is a list of categories in order: [grandparent/root, parent, child/leaf] - categoryHierarchy: TtsCategory[] + // Note: The two possible types differ in their timestamp names. + categoryHierarchy: (TtsCategory|TtsModelCategory)[] // Whether we're rendering for a moderator isCategoryMod: boolean, // If we're showing this on a category edit page, this is false. @@ -33,7 +35,15 @@ export function CategoryBreadcrumb(props: Props) { parentCount++; } - if (!!category.category_deleted_at) { + // We're handling a union type of JSON response payloads; each names its deleted timestamp differently. + let deleted = false; + if ('deleted_at' in category) { + deleted = !!category.deleted_at; + } else if ('category_deleted_at' in category) { + deleted = !!category.category_deleted_at; + } + + if (deleted) { deletedWarning = ( <> diff --git a/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryEditPage.tsx b/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryEditPage.tsx index 1eed0d8dd5..2baec964ff 100644 --- a/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryEditPage.tsx +++ b/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryEditPage.tsx @@ -323,6 +323,7 @@ function ModerationTtsCategoryEditPage(props: Props) { ) } +// FIXME: This has been implemented three times, slightly differently function recursiveBuildHierarchy(allCategories: TtsCategory[], currentToken: string): TtsCategory[] { let found = allCategories.find(category => category.category_token === currentToken); if (found === undefined) { diff --git a/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryListPage.tsx b/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryListPage.tsx index e8c4fc3a3a..8ba1f50835 100644 --- a/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryListPage.tsx +++ b/fakeyou/src/v2/view/moderation/categories/ModerationTtsCategoryListPage.tsx @@ -7,6 +7,7 @@ import { GravatarFc } from '../../_common/GravatarFc'; import { Link } from 'react-router-dom'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faBox, faLock } from '@fortawesome/free-solid-svg-icons'; +import { CategoryBreadcrumb } from '../../_common/CategoryBreadcrumb'; interface Props { sessionWrapper: SessionWrapper, @@ -164,6 +165,8 @@ function ModerationTtsCategoryListPage(props: Props) { {ttsCategoriesSorted.map(category => { + const categoryHierarchy = recursiveBuildHierarchy(ttsCategories, category.category_token); + let modOnlyIcon = category.can_only_mods_apply ? <>  : <>; @@ -215,6 +218,7 @@ function ModerationTtsCategoryListPage(props: Props) { return ( + {name} @@ -259,4 +263,17 @@ function StringToTriState(state: string) : ListTtsCategoriesTriState | undefined } } +// FIXME: This has been implemented three times, slightly differently +function recursiveBuildHierarchy(allCategories: ModerationTtsCategory[], currentToken: string): ModerationTtsCategory[] { + let found = allCategories.find(category => category.category_token === currentToken); + if (found === undefined) { + return []; + } + if (found.maybe_super_category_token === undefined) { + return [found]; + } + return [...recursiveBuildHierarchy(allCategories, found.maybe_super_category_token), found]; +} + + export { ModerationTtsCategoryListPage }; diff --git a/fakeyou/src/v2/view/tts/tts_model_view/TtsModelViewFc.tsx b/fakeyou/src/v2/view/tts/tts_model_view/TtsModelViewFc.tsx index 2a9582b45d..43d2231924 100644 --- a/fakeyou/src/v2/view/tts/tts_model_view/TtsModelViewFc.tsx +++ b/fakeyou/src/v2/view/tts/tts_model_view/TtsModelViewFc.tsx @@ -449,13 +449,14 @@ function TtsModelViewFc(props: Props) { ) } +// FIXME: This has been implemented three times, slightly differently function recursiveBuildHierarchy( categoryByTokenMap: Map, assignedCategoryByTokenMap: Map, currentToken: string -): TtsCategory[] { +): (TtsCategory|TtsModelCategory)[] { // NB: Using both maps should catch assigned categories that aren't public/approved. - let found = assignedCategoryByTokenMap.get(currentToken); + let found : TtsCategory | TtsModelCategory | undefined = assignedCategoryByTokenMap.get(currentToken); if (found === undefined) { found = categoryByTokenMap.get(currentToken); }