Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft/vil 641 #1021

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/components/activities/content/editors/H5pEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from 'next/link';
import React from 'react';

import { Button, Divider, FormControl, InputLabel, MenuItem, Select } from '@mui/material';
import { Autocomplete, Button, Divider, FormControl } from '@mui/material';
import TextField from '@mui/material/TextField';

import type { EditorProps } from '../content.types';
Expand All @@ -13,6 +13,7 @@ import { Modal } from 'src/components/Modal';
import H5pPlayer from 'src/components/h5p/H5pPlayer';
import { UserContext } from 'src/contexts/userContext';
import { fontDetailColor } from 'src/styles/variables.const';
import { normalizeString } from 'src/utils/isNormalizedStringEqual';
import { UserType } from 'types/user.type';

const IFRAME_REGEX = /<\s*iframe([^>]*)>.*?<\s*\/\s*iframe>/im;
Expand Down Expand Up @@ -87,22 +88,22 @@ export const H5pEditor = ({ id, value = '', onChange = () => {}, onDelete = () =
<h3>Choisissez le contenu H5P :</h3>
{h5pContent && h5pContent.length > 0 ? (
<FormControl fullWidth>
<InputLabel id="select-h5p">Contenu H5P</InputLabel>
<Select
labelId="select-h5p"
<Autocomplete
id="select-h5p"
label="Contenu H5P"
onChange={(event) => {
onChange(`/h5p/data/${event.target.value}/play`);
onChange={(_e, value) => {
if (!value) return;
onChange(`/h5p/data/${value.contentId}/play`);
setIsModalOpen(false);
}}
>
{h5pContent.map((h5p) => (
<MenuItem key={h5p.contentId} value={h5p.contentId}>
{h5p.title}
</MenuItem>
))}
</Select>
options={h5pContent.sort((a, b) => (a.title > b.title ? 1 : -1))}
getOptionLabel={(option) => option.title}
filterOptions={(options, state) => {
return options.filter((option) =>
normalizeString(option.title).toLowerCase().includes(normalizeString(state.inputValue).toLowerCase()),
);
}}
renderInput={(params) => <TextField {...params} label="Contenu H5P" />}
/>
</FormControl>
) : (
<>
Expand Down
9 changes: 5 additions & 4 deletions src/pages/admin/newportal/h5p/edit/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const H5pEditContentPage = () => {

const contentId = React.useMemo(() => getQueryString(router.query.id), [router]);
const content = (h5pContent || []).find((h5p) => h5p.contentId === contentId);
const redirectPath = `/admin/newportal/h5p`;

if (h5pContent && !content) {
router.push(`/admin/h5p`);
router.push(redirectPath);
}
if (!content) {
return null;
Expand All @@ -32,7 +33,7 @@ const H5pEditContentPage = () => {
return (
<div>
<Breadcrumbs separator={<NavigateNextIcon fontSize="large" color="primary" />} aria-label="breadcrumb" style={{ marginBottom: '1rem' }}>
<Link href="/admin/h5p" passHref>
<Link href={redirectPath} passHref>
<MaterialLink>
<h1>Contenu H5P</h1>
</MaterialLink>
Expand All @@ -48,7 +49,7 @@ const H5pEditContentPage = () => {
variant: 'success',
});
queryClient.invalidateQueries('h5p');
router.push(`/admin/h5p`);
router.push(redirectPath);
}}
onError={(message) => {
enqueueSnackbar(message, {
Expand All @@ -58,7 +59,7 @@ const H5pEditContentPage = () => {
></H5pEditor>
</div>
</AdminTile>
<Link href="/admin/h5p" passHref>
<Link href={redirectPath} passHref>
<Button variant="outlined" style={{ margin: '1rem 0' }} component="a">
Retour
</Button>
Expand Down
Loading