edits to fix the functioning of getImageUrlIfExists

This commit is contained in:
Martina 2021-11-16 13:20:29 -08:00
parent 64956cc1aa
commit dd386ba452
4 changed files with 23 additions and 38 deletions

View File

@ -10,29 +10,6 @@ import moment from "moment";
//For API related utility functions, see common/user-behaviors.js
//And for uploading related utility functions, see common/file-utilities.js
export const getImageUrlIfExists = (file, sizeLimit = null) => {
if (!file) return;
const coverImage = file.coverImage;
if (coverImage) {
if (sizeLimit && coverImage.size && coverImage.size > sizeLimit) {
return;
}
if (coverImage.url) {
return coverImage.url;
}
if (coverImage.cid) {
return Strings.getURLfromCID(coverImage.cid);
}
}
if (Validations.isPreviewableImage(file.type)) {
if (sizeLimit && file.size > sizeLimit) {
return;
}
return Strings.getURLfromCID(file.cid);
}
};
export const generateNumberByStep = ({ min, max, step = 1 }) => {
var numbers = [];
for (var n = min; n <= max; n += step) {
@ -170,15 +147,22 @@ export const clamp = (value, min, max) => {
return value;
};
export const getCoverImageUrlIfExists = (coverImage) => {
if (!coverImage) return;
if (Validations.isPreviewableImage(coverImage.type)) {
export const getImageUrlIfExists = (file, sizeLimit = null) => {
if (!file) return;
if (Validations.isPreviewableImage(file.type)) {
if (sizeLimit && file.size && file.size > sizeLimit) {
return;
}
return Strings.getURLfromCID(file.cid);
}
let coverImage = file.coverImage;
if (coverImage) {
if (sizeLimit && coverImage.size && coverImage.size > sizeLimit) {
return;
}
return Strings.getURLfromCID(coverImage.cid);
}
if (coverImage.coverImage) {
return Strings.getURLfromCID(coverImage.coverImage.cid);
}
if (coverImage.linkImage) {
return coverImage.linkImage;
if (file.linkImage) {
return file.linkImage;
}
};

View File

@ -3,6 +3,7 @@ import * as Styles from "~/common/styles";
import * as Constants from "~/common/constants";
import * as SVG from "~/common/svg";
import * as Validations from "~/common/validations";
import * as Utilities from "~/common/utilities";
import { css } from "@emotion/react";
import { FollowButton, ShareButton } from "~/components/core/CollectionPreviewBlock/components";
@ -333,9 +334,9 @@ const useAnimateDescription = ({
};
const getObjectToPreview = (coverImage) => {
let isImage =
Validations.isPreviewableImage(coverImage) ||
(coverImage.coverImage && Validations.isPreviewableImage(coverImage.coverImage));
if (!coverImage) return { type: "EMPTY" };
return { object: coverImage, type: isImage ? "IMAGE" : "PLACEHOLDER" };
let coverImageUrl = Utilities.getImageUrlIfExists(coverImage);
return { object: coverImage, type: coverImageUrl ? "IMAGE" : "PLACEHOLDER" };
};

View File

@ -411,7 +411,7 @@ export const selectSlateCoverImage = (objects) => {
let selectedObject;
if (!objects.length) return null;
for (let object of objects) {
if (Utilities.getCoverImageUrlIfExists(object)) {
if (Utilities.getImageUrlIfExists(object)) {
selectedObject = object;
break;
}
@ -422,7 +422,7 @@ export const selectSlateCoverImage = (objects) => {
};
export const addToSlateCheckCoverImage = async (slate, filesAdded) => {
if (Utilities.getCoverImageUrlIfExists(slate.coverImage)) {
if (Utilities.getImageUrlIfExists(slate.coverImage)) {
return;
}
if (!filesAdded) return;

View File

@ -230,7 +230,7 @@ export default class SceneSlate extends React.Component {
description = `View the collection ${name} on Slate`;
}
title = `${name} • Slate`;
imageUrl = slate.coverImage?.cid ? Strings.getURLfromCID(slate.coverImage.cid) : null;
image = Utilities.getImageUrlIfExists(slate.coverImage);
// const objects = slate.objects;
// if (!image && objects) {
// for (let i = 0; i < objects.length; i++) {