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

Fix videogallery us50330 #461

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
### Fix

- Risolto il problema di layout nelle card che indicano dei luoghi.
- Risolto un problema nel blocco Video Gallery, per cui alcuni video di youtube non erano riproducibili.
pnicolli marked this conversation as resolved.
Show resolved Hide resolved

## Versione 11.1.1 (22/12/2023)

Expand Down
70 changes: 33 additions & 37 deletions src/components/ItaliaTheme/Blocks/VideoGallery/Block/ViewBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Embed } from 'semantic-ui-react';
import {
isInternalURL,
getParentUrl,
flattenToAppURL,
} from '@plone/volto/helpers';
import { isInternalURL, getParentUrl } from '@plone/volto/helpers';
import { ConditionalEmbed } from 'volto-gdpr-privacy';
import { FontAwesomeIcon } from 'design-comuni-plone-theme/components/ItaliaTheme';
import { videoUrlHelper } from 'design-comuni-plone-theme/helpers';
import { useIntl, defineMessages } from 'react-intl';
import config from '@plone/volto/registry';

Expand All @@ -34,23 +31,36 @@ const messages = defineMessages({
*/
const ViewBlock = ({ data, index, isEditMode = false }) => {
const intl = useIntl();
let placeholder = data.preview_image
? isInternalURL(data.preview_image)
? `${flattenToAppURL(data.preview_image)}/@@images/image`
: data.preview_image
: null;

if (!placeholder && data.url) {
if (data.url.match('youtu')) {
//load video preview image from youtube
let placeholder = null;
let videoID = null;
let listID = null;

const videoID = data.url.match(/.be\//)
? data.url.match(/^.*\.be\/(.*)/)?.[1]
: data.url.match(/^.*\?v=(.*)$/)?.[1];
placeholder = 'https://img.youtube.com/vi/' + videoID + '/hqdefault.jpg';
} else if (data.url.match('vimeo')) {
const videoID = data.url.match(/^.*\.com\/(.*)/)[1];
placeholder = 'https://vumbnail.com/' + videoID + '.jpg';
if (data.url) {
const [computedID, computedPlaceholder] = videoUrlHelper(
data.url,
data?.preview_image,
);
if (computedID) {
videoID = computedID;
}
if (computedPlaceholder) {
placeholder = computedPlaceholder;
}

if (data.url.match('list')) {
const matches = data.url.match(/^.*\?list=(.*)|^.*&list=(.*)$/);
listID = matches[1] || matches[2];

let thumbnailID = null;
if (data.url.match(/\?v=(.*)&list/)) {
thumbnailID = data.url.match(/^.*\?v=(.*)&list(.*)/)[1];
}
if (data.url.match(/\?v=(.*)\?list/)) {
thumbnailID = data.url.match(/^.*\?v=(.*)\?list(.*)/)[1];
}
placeholder =
'https://img.youtube.com/vi/' + thumbnailID + '/hqdefault.jpg';
}
}

Expand Down Expand Up @@ -90,31 +100,17 @@ const ViewBlock = ({ data, index, isEditMode = false }) => {
<>
{data.url.match('list') ? (
<Embed
url={`https://www.youtube.com/embed/videoseries?list=${
data.url.match(/^.*\?list=(.*)$/)[1]
}`}
url={`https://www.youtube.com/embed/videoseries?list=${listID}`}
{...embedSettings}
/>
) : (
<Embed
id={
data.url.match(/.be\//)
? data.url.match(/^.*\.be\/(.*)/)?.[1]
: data.url.match(/^.*\?v=(.*)$/)?.[1]
}
source="youtube"
{...embedSettings}
/>
<Embed id={videoID} source="youtube" {...embedSettings} />
)}
</>
) : (
<>
{data.url.match('vimeo') ? (
<Embed
id={data.url.match(/^.*\.com\/(.*)/)[1]}
source="vimeo"
{...embedSettings}
/>
<Embed id={videoID} source="vimeo" {...embedSettings} />
) : (
<>
{data.url.match('.mp4') ? (
Expand Down