diff --git a/src/components/SlateEditor/plugins/uuDisclaimer/DisclaimerForm.tsx b/src/components/SlateEditor/plugins/uuDisclaimer/DisclaimerForm.tsx index e3408f2ab5..2ecd1b1b8e 100644 --- a/src/components/SlateEditor/plugins/uuDisclaimer/DisclaimerForm.tsx +++ b/src/components/SlateEditor/plugins/uuDisclaimer/DisclaimerForm.tsx @@ -164,6 +164,7 @@ const DisclaimerForm = ({ initialData, onOpenChange, onSave }: DisclaimerFormPro title={item.title.title} description={item.metaDescription?.metaDescription} image={item.metaImage} + useFallbackImage /> )} > diff --git a/src/components/abstractions/Combobox.tsx b/src/components/abstractions/Combobox.tsx index 6ef9b892fa..b9b57ca2b3 100644 --- a/src/components/abstractions/Combobox.tsx +++ b/src/components/abstractions/Combobox.tsx @@ -80,6 +80,7 @@ interface GenericComboboxItemProps { title: string; description?: string; fallbackImageElement?: ReactNode; + useFallbackImage?: boolean; image?: { url?: string; alt?: string; @@ -99,12 +100,12 @@ const StyledListItemRoot = styled(ListItemRoot, { }); export const GenericComboboxItemContent = forwardRef( - ({ title, image, description, fallbackImageElement, ...props }, ref) => ( + ({ title, image, description, fallbackImageElement, useFallbackImage, ...props }, ref) => ( - {!!image && ( + {(!!image || useFallbackImage) && ( } /> )} diff --git a/src/containers/ArticlePage/components/ConceptsField.tsx b/src/containers/ArticlePage/components/ConceptsField.tsx index a7550a6b8e..0fe43c303d 100644 --- a/src/containers/ArticlePage/components/ConceptsField.tsx +++ b/src/containers/ArticlePage/components/ConceptsField.tsx @@ -92,7 +92,9 @@ const ConceptsField = ({ field, form }: Props) => { paginationData={searchQuery.data} onInputValueChange={(details) => setQuery(details.inputValue)} onPageChange={(details) => setPage(details.page)} - renderItem={(item) => } + renderItem={(item) => ( + + )} > {t("form.relatedConcepts.articlesTitle")} diff --git a/src/containers/NdlaFilm/components/NdlaFilmAccordionPanels.tsx b/src/containers/NdlaFilm/components/NdlaFilmAccordionPanels.tsx index 1193667eb7..62cc90c7eb 100644 --- a/src/containers/NdlaFilm/components/NdlaFilmAccordionPanels.tsx +++ b/src/containers/NdlaFilm/components/NdlaFilmAccordionPanels.tsx @@ -43,19 +43,6 @@ const SubjectpageAccordionPanels = ({ errors, selectedLanguage }: ComponentProps }, }); }; - const onUpdateArticle = ( - field: FieldProps["field"], - form: FormikHelpers, - article?: string, - ) => { - form.setFieldTouched(field.name, true, false); - field.onChange({ - target: { - name: field.name, - value: article, - }, - }); - }; return ( @@ -69,7 +56,7 @@ const SubjectpageAccordionPanels = ({ errors, selectedLanguage }: ComponentProps - + { +const NdlaFilmArticle = ({ fieldName }: Props) => { const { t } = useTranslation(); - const form = useFormikContext(); - const [field] = useField(fieldName); + const [field, _, helpers] = useField(fieldName); const [selectedArticle, setSelectedArticle] = useState(undefined); + const [query, setQuery] = useState(""); + const [page, setPage] = useState(1); + const delayedQuery = useDebounce(query, 300); + + const searchQuery = useArticleSearch({ + articleTypes: ["frontpage-article"], + page, + query: delayedQuery, + }); useEffect(() => { const initSelectedArticle = async () => { @@ -53,43 +50,42 @@ const NdlaFilmArticle = ({ fieldName, onUpdateArticle }: Props) => { initSelectedArticle(); }, [field.value]); - const onSearch = useCallback((query: string, page?: number) => { - return searchArticles({ articleTypes: ["frontpage-article"], page, query }); - }, []); - return ( - <> - - {selectedArticle && ( - - - {selectedArticle.title.title} - - onUpdateArticle(field, form, null)} - > - - - + + item.title.title} + itemToValue={(item) => getUrnFromId(item.id.toString())} + inputValue={query} + isSuccess={searchQuery.isSuccess} + paginationData={searchQuery.data} + onInputValueChange={(details) => setQuery(details.inputValue)} + onPageChange={(details) => setPage(details.page)} + value={field.value ? [field.value?.toString()] : undefined} + onValueChange={(details) => helpers.setValue(getUrnFromId(details.items[0].id))} + renderItem={(item) => ( + + )} + > + {t("ndlaFilm.editor.moreInfoTitle")} + {t("ndlaFilm.editor.moreInfoSubTitle")} + + + {!!selectedArticle && ( + helpers.setValue(null)} + removeElementTranslation={t("ndlaFilm.editor.removeArticleFromMoreInformation")} + /> )} - - idField="id" - labelField="title" - placeholder={t("frontpageForm.search")} - apiAction={onSearch} - disableSelected - onChange={(article: IArticleSummaryV2) => onUpdateArticle(field, form, getUrnFromId(article.id))} - startOpen={!field.value} - showPagination - initialSearch={!field.value} - clearInputField - /> - + ); }; diff --git a/src/containers/Podcast/components/PodcastSeries.tsx b/src/containers/Podcast/components/PodcastSeries.tsx index 76f04cb4f6..59436ee9cc 100644 --- a/src/containers/Podcast/components/PodcastSeries.tsx +++ b/src/containers/Podcast/components/PodcastSeries.tsx @@ -101,6 +101,7 @@ const PodcastSeries = () => { title={item.title.title} description={item.description.description} image={item.coverPhoto} + useFallbackImage /> )} >