Skip to content

Commit

Permalink
Merge branch 'main' into fix-markdown-heading
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Raghuwanshi authored Jan 18, 2025
2 parents 44b0345 + ae58c67 commit bec3a62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/6591.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed handling of the site logo preview to appear after upload. @Shyam-Raghuwanshi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @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 @@ -76,12 +76,15 @@ const RegistryImageWidget = (props) => {
const { id, value, onChange, isDisabled } = props;
const intl = useIntl();

const fileName = value?.split(';')[0];
const imgsrc = fileName
? `${toPublicURL('/')}@@site-logo/${atob(
fileName.replace('filenameb64:', ''),
)}`
: '';
// State to manage the preview image source
const [previewSrc, setPreviewSrc] = useState(() => {
const fileName = value?.split(';')[0];
return fileName
? `${toPublicURL('/')}@@site-logo/${atob(
fileName.replace('filenameb64:', ''),
)}`
: '';
});

/**
* Drop handler
Expand All @@ -102,8 +105,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;
setPreviewSrc(reader.result);
}
};
reader.readAsDataURL(files[0]);
Expand All @@ -115,12 +117,12 @@ const RegistryImageWidget = (props) => {
{({ getRootProps, getInputProps, isDragActive }) => (
<div className="file-widget-dropzone" {...getRootProps()}>
{isDragActive && <Dimmer active></Dimmer>}
{imgsrc ? (
{previewSrc ? (
<Image
className="image-preview"
id={`field-${id}-image`}
size="small"
src={imgsrc}
src={previewSrc}
/>
) : (
<div className="dropzone-placeholder">
Expand All @@ -139,7 +141,6 @@ const RegistryImageWidget = (props) => {
)}
</div>
)}

<label className="label-file-widget-input">
{value
? intl.formatMessage(messages.replaceFile)
Expand Down Expand Up @@ -168,6 +169,7 @@ const RegistryImageWidget = (props) => {
disabled={isDisabled}
onClick={() => {
onChange(id, '');
setPreviewSrc(''); // Clear the preview image
}}
>
<Icon name={deleteSVG} size="20px" />
Expand All @@ -189,10 +191,7 @@ RegistryImageWidget.propTypes = {
description: PropTypes.string,
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
value: PropTypes.shape({
'@type': PropTypes.string,
title: PropTypes.string,
}),
value: PropTypes.string,
onChange: PropTypes.func.isRequired,
wrapped: PropTypes.bool,
};
Expand Down

0 comments on commit bec3a62

Please sign in to comment.