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 site logo issue #6591

Merged
merged 9 commits into from
Jan 17, 2025
Merged
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
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
Loading