Skip to content

Commit

Permalink
[Fixes #1022] Thumbnail placeholders (#1142) (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidQuartz authored Aug 22, 2022
1 parent e171e57 commit c5d2ff8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Spinner from '@js/components/Spinner';
import Message from '@mapstore/framework/components/I18N/Message';
import tooltip from '@mapstore/framework/components/misc/enhancers/tooltip';
import moment from 'moment';
import { getResourceTypesInfo, getMetadataDetailUrl, ResourceTypes, GXP_PTYPES } from '@js/utils/ResourceUtils';
import { getResourceTypesInfo, getMetadataDetailUrl, ResourceTypes, GXP_PTYPES, getResourceImageSource } from '@js/utils/ResourceUtils';
import debounce from 'lodash/debounce';
import CopyToClipboardCmp from 'react-copy-to-clipboard';
import { TextEditable, ThumbnailEditable } from '@js/components/ContentsEditable/';
Expand Down Expand Up @@ -82,6 +82,7 @@ function formatResourceLinkUrl(resourceUrl = '') {
function ThumbnailPreview({
src,
style,
icon,
...props
}) {

Expand All @@ -94,19 +95,29 @@ function ThumbnailPreview({
}, [src]);

return (
<img
{...props}
src={src}
onLoad={() => setLoading(false)}
onError={() => setLoading(false)}
style={{
<>
{!src ? <div className="card-img-placeholder" style={{
...style,
...(loading && {
backgroundColor: 'transparent'
}),
objectFit: 'contain'
}}
/>
width: 250,
height: 184,
outline: '1px solid #eee'
}}>
<FaIcon name={icon} />
</div>
: <img
{...props}
src={src}
onLoad={() => setLoading(false)}
onError={() => setLoading(false)}
style={{
...style,
...(loading && {
backgroundColor: 'transparent'
}),
objectFit: 'contain'
}}
/>}
</>
);
}

Expand Down Expand Up @@ -460,6 +471,7 @@ function DetailsPanel({
/>
: (!embedUrl && !editThumbnail ? (<ThumbnailPreview
src={resource?.thumbnail_url}
icon={icon}
style={{
position: 'absolute',
width: '100%',
Expand Down Expand Up @@ -490,13 +502,13 @@ function DetailsPanel({

<div className="gn-details-panel-content">
{editThumbnail && <div className="gn-details-panel-content-img">
{!activeEditMode && <ThumbnailPreview src={resource?.thumbnail_url} />}
{!activeEditMode && <ThumbnailPreview src={resource?.thumbnail_url} icon={icon} />}
{activeEditMode && <div className="gn-details-panel-preview inediting">
{!enableMapViewer ? <> <EditThumbnail
{!enableMapViewer ? <> <div {...(!resource?.thumbnail_url && {style: {outline: '1px solid #eee'}})}><EditThumbnail
onEdit={editThumbnail}
image={resource?.thumbnail_url}
image={() => getResourceImageSource(resource?.thumbnail_url)}
thumbnailUpdating={resourceThumbnailUpdating}
/>
/></div>
{
((resource.resource_type === ResourceTypes.MAP || resource.resource_type === ResourceTypes.DATASET) && (resource.ptype !== GXP_PTYPES.REST_IMG || resource.ptype !== GXP_PTYPES.REST_MAP)) &&
( <><MapThumbnailButtonToolTip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import PdfViewer from '@js/components/MediaViewer/PdfViewer';
import { determineResourceType } from '@js/utils/FileUtils';
import Loader from '@mapstore/framework/components/misc/Loader';
import MainEventView from '@js/components/MainEventView';
import { getResourceTypesInfo } from '@js/utils/ResourceUtils';
import { getResourceTypesInfo, getResourceImageSource } from '@js/utils/ResourceUtils';

const Scene3DViewer = lazy(() => import('@js/components/MediaViewer/Scene3DViewer'));

Expand Down Expand Up @@ -66,7 +66,7 @@ const Media = ({ resource, ...props }) => {
{...props[mediaType]}
description={resource.abstract}
id={resource.pk}
thumbnail={resource.thumbnail_url}
thumbnail={() => getResourceImageSource(resource?.thumbnail_url)}
src={resource.href}
/>
</Suspense>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ const ResourceCard = forwardRef(({
/>
)}
<div className={`card-resource-${layoutCardsStyle}`}>
{imgError ? (
<div className={`${imgClassName} card-img-placeholder`} />
{(imgError || !res.thumbnail_url) ? (
<div className={`${imgClassName} card-img-placeholder`}>
<FaIcon name={icon} />
</div>
) : (
<img
className={imgClassName}
Expand Down
4 changes: 2 additions & 2 deletions geonode_mapstore_client/client/js/routes/Detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import MetaTags from "@js/components/MetaTags";
import {
getThemeLayoutSize
} from '@js/utils/AppUtils';
import { resourceHasPermission } from '@js/utils/ResourceUtils';
import { resourceHasPermission, getResourceImageSource } from '@js/utils/ResourceUtils';
import { getTotalResources } from '@js/selectors/search';
import ConnectedCardGrid from '@js/routes/catalogue/ConnectedCardGrid';
import DeleteResource from '@js/plugins/DeleteResource';
Expand Down Expand Up @@ -133,7 +133,7 @@ function Detail({
return (
<>
<MetaTags
logo={resource ? resource.thumbnail_url : window.location.origin + config?.navbar?.logo[0]?.src}
logo={resource ? () => getResourceImageSource(resource?.thumbnail_url) : window.location.origin + config?.navbar?.logo[0]?.src}
title={(resource?.title) ? resource?.title + " - " + siteName : siteName }
siteName={siteName}
contentURL={resource?.detail_url}
Expand Down
3 changes: 2 additions & 1 deletion geonode_mapstore_client/client/js/routes/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { withResizeDetector } from 'react-resize-detector';

import { getCategories, getRegions, getOwners, getKeywords } from '@js/api/geonode/v2';
import MetaTags from "@js/components/MetaTags";
import { getResourceImageSource } from '@js/utils/ResourceUtils';

import {
getThemeLayoutSize
Expand Down Expand Up @@ -174,7 +175,7 @@ function Search({
return (
<>
<MetaTags
logo={resource ? resource.thumbnail_url : window.location.origin + config?.navbar?.logo[0]?.src}
logo={resource ? () => getResourceImageSource(resource?.thumbnail_url) : window.location.origin + config?.navbar?.logo[0]?.src}
title={(resource?.title) ? resource?.title + " - " + siteName : siteName }
siteName={siteName}
contentURL={resource?.detail_url}
Expand Down
3 changes: 2 additions & 1 deletion geonode_mapstore_client/client/js/routes/Viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import MetaTags from '@js/components/MetaTags';
import MainEventView from '@js/components/MainEventView';
import ViewerLayout from '@js/components/ViewerLayout';
import { createShallowSelector } from '@mapstore/framework/utils/ReselectUtils';
import { getResourceImageSource } from '@js/utils/ResourceUtils';

const urlQuery = url.parse(window.location.href, true).query;

Expand Down Expand Up @@ -123,7 +124,7 @@ function ViewerRoute({
return (
<>
{resource && <MetaTags
logo={resource.thumbnail_url}
logo={() => getResourceImageSource(resource?.thumbnail_url)}
title={(resource?.title) ? `${resource?.title} - ${siteName}` : siteName }
siteName={siteName}
contentURL={resource?.detail_url}
Expand Down
5 changes: 5 additions & 0 deletions geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,8 @@ export const parseUploadFiles = (data) => {
};
}, {});
};


export const getResourceImageSource = (image) => {
return image ? image : 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADICAIAAABZHvsFAAAACXBIWXMAAC4jAAAuIwF4pT92AAABiklEQVR42u3SAQ0AAAjDMMC/5+MAAaSVsKyTFHwxEmBoMDQYGgyNocHQYGgwNBgaQ4OhwdBgaDA0hgZDg6HB0GBoDA2GBkODocHQGBoMDYYGQ4OhMTQYGgwNhgZDY2gwNBgaDI2hwdBgaDA0GBpDg6HB0GBoMDSGBkODocHQYGgMDYYGQ4OhwdAYGgwNhgZDg6ExNBgaDA2GBkNjaDA0GBoMDYbG0GBoMDQYGkODocHQYGgwNIYGQ4OhwdBgaAwNhgZDg6HB0BgaDA2GBkODoTE0GBoMDYYGQ2NoMDQYGgwNhsbQYGgwNBgaQ4OhwdBgaDA0hgZDg6HB0GBoDA2GBkODocHQGBoMDYYGQ4OhMTQYGgwNhgZDY2gwNBgaDA2GxtBgaDA0GBoMjaHB0GBoMDSGBkODocHQYGgMDYYGQ4OhwdAYGgwNhgZDg6ExNBgaDA2GBkNjaDA0GBoMDYbG0GBoMDQYGgyNocHQYGgwNIYGQ4OhwdBgaAwNhgZDg6HB0BgaDA2GBkPDbQH4OQSN0W8qegAAAABJRU5ErkJggg==';
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
.color-var(@theme-vars[danger]);
}
}
.card-img-placeholder {
.background-color-var(@theme-vars[main-bg]);
.color-var(@theme-vars[primary]);
}
}

// **************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
.color-var(@theme-vars[main-color]);
.background-color-var(@theme-vars[main-bg]);
}
.card-img-placeholder {
.background-color-var(@theme-vars[main-variant-bg]);
}
.gn-card-options {
.border-color-var(@theme-vars[main-border-color]);
}
.card-img-placeholder {
.background-color-var(@theme-vars[main-bg]);
.color-var(@theme-vars[primary]);
}
}
}

Expand Down Expand Up @@ -297,6 +298,13 @@ button.btn.btn-default.gn-resource-status.gn-status-button {
}
}

.card-img-placeholder {
display: flex;
justify-content: center;
align-items: center;
font-size: 3rem;
}

@media screen and (min-width: 1649px) {
.gn-resource-card {
.card-resource-list {
Expand Down

0 comments on commit c5d2ff8

Please sign in to comment.