diff --git a/src/apps/detailPages/MediaContents.tsx b/src/apps/detailPages/MediaContents.tsx index 10b5fe5a..84c7afed 100644 --- a/src/apps/detailPages/MediaContents.tsx +++ b/src/apps/detailPages/MediaContents.tsx @@ -1,15 +1,19 @@ import { useTranslations } from '@i18n/useTranslations'; +import { Button } from '@performant-software/core-data'; import Viewer from '@samvera/clover-iiif/viewer'; -import { useMemo } from 'react'; +import { useMemo, useState } from 'react'; +import _ from 'underscore'; interface Props { model: string; uuid: string; data: any; + showContentWarning?: boolean; } const MediaContents = (props: Props) => { const { t } = useTranslations(); + const [showContentWarning, setShowContentWarning] = useState(props.showContentWarning); const count = useMemo( () => props.data.items.reduce((acc, item) => acc + item.item_count, 0), @@ -22,14 +26,28 @@ const MediaContents = (props: Props) => { return (

{t('relatedMedia', { count })}

- + { showContentWarning && ( +
+

{t('contentWarningRelatedMedia')}

+ +
+ ) } + { !showContentWarning && ( + + ) }
) } diff --git a/src/apps/detailPages/RelatedMedia.astro b/src/apps/detailPages/RelatedMedia.astro index 928bd6c6..a1c34c75 100644 --- a/src/apps/detailPages/RelatedMedia.astro +++ b/src/apps/detailPages/RelatedMedia.astro @@ -1,6 +1,7 @@ --- import MediaContents from '@apps/detailPages/MediaContents'; import ServiceFactory from '@services/coreData/factory'; +import _ from 'underscore'; interface Props { model: string; @@ -11,6 +12,9 @@ const { model, uuid } = Astro.props; const service = ServiceFactory.getService(model); const manifests = await service.getRelatedManifests(uuid); +const { mediaContents } = await service.getRelatedMedia(uuid); +const showContentWarning = _.some(mediaContents, (img) => (img.content_warning)); + --- {manifests && manifests?.items?.length > 0 && ( )} diff --git a/src/apps/search/list/ListLayout.tsx b/src/apps/search/list/ListLayout.tsx index 84cad38c..47cf9932 100644 --- a/src/apps/search/list/ListLayout.tsx +++ b/src/apps/search/list/ListLayout.tsx @@ -7,6 +7,7 @@ import { useContext } from 'react'; import TranslationContext from '@contexts/TranslationContext'; import SortBy from '@apps/search/list/SortBy'; import Stats from '@apps/search/list/Stats'; +import SensitiveContentToggle from './SensitiveContentToggle'; interface Props { lang: string; @@ -42,7 +43,9 @@ const ListLayout = (props: Props) => { className='py-0' config={config} open - /> + > + +
diff --git a/src/apps/search/list/SensitiveContentToggle.tsx b/src/apps/search/list/SensitiveContentToggle.tsx new file mode 100644 index 00000000..39075372 --- /dev/null +++ b/src/apps/search/list/SensitiveContentToggle.tsx @@ -0,0 +1,41 @@ +import TranslationContext from "@contexts/TranslationContext"; +import { Checkbox } from '@performant-software/core-data'; +import { useContext } from "react"; +import { useSearchConfig } from "../SearchConfigContext"; +import { useToggleRefinement } from "react-instantsearch"; + +const SensitiveContentToggle = () => { + const { t } = useContext(TranslationContext); + const config = useSearchConfig(); + + + if (!(config.type === 'image')) { + return null; + } + + const { value, refine } = useToggleRefinement({ + attribute: 'content_warning', + on: false + }); + + return ( +
+ refine({ isRefined: !checked })} + /> + +
+ ); +} + +export default SensitiveContentToggle; \ No newline at end of file diff --git a/src/i18n/i18n.json b/src/i18n/i18n.json index 0b6e8646..cb76b05f 100644 --- a/src/i18n/i18n.json +++ b/src/i18n/i18n.json @@ -490,5 +490,17 @@ "tags": { "tinaLabel": "Tags", "defaultValue": "Tags" + }, + "content_warning": { + "tinaLabel": "Content Warning", + "defaultValue": "Content Warning" + }, + "sensitiveContentFilter": { + "tinaLabel": "Sensitive content filter for image search", + "defaultValue": "Hide sensitive content" + }, + "contentWarningRelatedMedia": { + "tinaLabel": "Sensitive content warning for related media", + "defaultValue": "This media contain sensitive content. Show anyway?" } } \ No newline at end of file