Skip to content

Commit

Permalink
fix: preview image in RegistryImageWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed May 13, 2024
1 parent 67d80c8 commit 025600f
Show file tree
Hide file tree
Showing 3 changed files with 1,985 additions and 198 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"@plone/volto": "^17.0.0"
},
"dependencies": {
"volto-multilingual-widget": "3.0.0"
"volto-multilingual-widget": "3.2.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* CUSTOMIZATIONS:
* - customized 'imgsrc' to get url based on property filed name
* - customized onLoad to view image preview if there's no image uploaded yet.
*
* RegistryImageWidget component.
* @module components/manage/Widgets/RegistryImageWidget
*/

import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Button, Image, Dimmer } from 'semantic-ui-react';
import { readAsDataURL } from 'promise-file-reader';
Expand Down Expand Up @@ -77,14 +79,13 @@ const RegistryImageWidget = (props) => {
const intl = useIntl();

const fileName = value?.split(';')[0];
const imgsrc = fileName
? // ? `${toPublicURL('/')}@@site-logo/${atob(
// fileName.replace('filenameb64:', ''),
// )}`
`${toPublicURL('/')}registry-images/@@images/${id}/${atob(
fileName.replace('filenameb64:', ''),
)}`
: '';
const [imgsrc, setImgsrc] = useState(
fileName
? `${toPublicURL('/')}registry-images/@@images/${id}/${atob(
fileName.replace('filenameb64:', ''),
)}`
: '',
);

/**
* Drop handler
Expand All @@ -105,8 +106,7 @@ const RegistryImageWidget = (props) => {
reader.onload = function () {
const fields = reader.result.match(/^data:(.*);(.*),(.*)$/);
if (imageMimetypes.includes(fields[1])) {
let imagePreview = document.getElementById(`field-${id}-image`);
imagePreview.src = reader.result;
setImgsrc(reader.result);
}
};
reader.readAsDataURL(files[0]);
Expand Down
Loading

0 comments on commit 025600f

Please sign in to comment.