Skip to content

Commit

Permalink
refactor: show empty course notice in Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
hejtful committed Jan 13, 2025
1 parent a0d27f4 commit 5bec2f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
18 changes: 16 additions & 2 deletions apps/web/src/components/entity/entity.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
EditorPluginType,
isArticleDocument,
isCourseDocument,
isEmptyArticle,
} from '@editor/package'
import {
Expand Down Expand Up @@ -43,7 +44,7 @@ export function Entity({ data }: EntityProps) {
const { strings } = useInstanceData()
return wrapWithSchema(
<>
{renderNotices()}
{renderNotices(data.content)}
{renderStyledH1()}
{renderUserTools({ aboveContent: true })}
<div className="min-h-[25vh]" key={data.id}>
Expand Down Expand Up @@ -144,7 +145,7 @@ export function Entity({ data }: EntityProps) {
)
}

function renderNotices() {
function renderNotices(document: EntityData['content']) {
if (data.trashed)
return (
<InfoPanel icon={faTrash} doNotIndex>
Expand Down Expand Up @@ -180,5 +181,18 @@ export function Entity({ data }: EntityProps) {
</InfoPanel>
)
}

const isCourse =
document &&
!Array.isArray(document) &&
document.plugin === EditorPluginType.Course &&
isCourseDocument(document)
if (isCourse && !document.state.pages.length) {
return (
<InfoPanel icon={faExclamationCircle} type="warning" doNotIndex>
{strings.content.courseNoPagesWarning}
</InfoPanel>
)
}
}
}
2 changes: 2 additions & 0 deletions apps/web/src/data/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export const instanceData = {
picture: 'Picture',
previewImage: 'Preview Image',
task: 'Task',
courseNoPagesWarning:
'Sorry there seem to be no reviewed pages in this course yet.',
},
consent: {
title: 'Consent for external Content',
Expand Down
2 changes: 0 additions & 2 deletions packages/editor/src/i18n/strings/de/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const staticStrings = {
pages: 'Kursübersicht',
next: 'Weiter',
back: 'Zurück',
noPagesWarning:
'Leider gibt es für diesen Kurs noch keine akzeptierten Seiten.',
noRevisionForPage: 'Ungegeprüfte Seite',
},
exercise: {
Expand Down
2 changes: 0 additions & 2 deletions packages/editor/src/i18n/strings/en/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export const staticStrings = {
pages: 'Course overview',
next: 'Next',
back: 'Back',
noPagesWarning:
'Sorry there seem to be no reviewed pages in this course yet.',
noRevisionForPage: 'unreviewed page',
},
exercise: {
Expand Down
10 changes: 0 additions & 10 deletions packages/editor/src/plugins/course/static/static.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { SerloOnlyFeaturesContext } from '@editor/core/contexts/serlo-only-features-context'
import { FaIcon } from '@editor/editor-ui/fa-icon'
import { useStaticStrings } from '@editor/i18n/static-strings-provider'
import { StaticRenderer } from '@editor/static-renderer/static-renderer'
import { EditorCourseDocument } from '@editor/types/editor-plugins'
import { cn } from '@editor/utils/cn'
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons'
import { useState, MouseEvent, useContext } from 'react'

import { CourseFooter } from './course-footer'
Expand All @@ -17,7 +14,6 @@ export function CourseStaticRenderer({
}: EditorCourseDocument) {
const { pages } = state

const courseStrings = useStaticStrings().plugins.course
const { isRevisionView } = useContext(SerloOnlyFeaturesContext)

let asPath = ''
Expand Down Expand Up @@ -53,12 +49,6 @@ export function CourseStaticRenderer({

return (
<>
{pages.length ? null : (
<div className="my-12 rounded-2xl bg-orange-200 p-4 font-bold">
<FaIcon icon={faExclamationCircle} />
{courseStrings.noPagesWarning}
</div>
)}
<CourseNavigation
{...state}
activePageId={activePage?.id}
Expand Down

0 comments on commit 5bec2f8

Please sign in to comment.