mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-27 01:03:08 +03:00
edits to fix the functioning of getImageUrlIfExists
This commit is contained in:
parent
64956cc1aa
commit
dd386ba452
@ -10,29 +10,6 @@ import moment from "moment";
|
|||||||
//For API related utility functions, see common/user-behaviors.js
|
//For API related utility functions, see common/user-behaviors.js
|
||||||
//And for uploading related utility functions, see common/file-utilities.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 }) => {
|
export const generateNumberByStep = ({ min, max, step = 1 }) => {
|
||||||
var numbers = [];
|
var numbers = [];
|
||||||
for (var n = min; n <= max; n += step) {
|
for (var n = min; n <= max; n += step) {
|
||||||
@ -170,15 +147,22 @@ export const clamp = (value, min, max) => {
|
|||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCoverImageUrlIfExists = (coverImage) => {
|
export const getImageUrlIfExists = (file, sizeLimit = null) => {
|
||||||
if (!coverImage) return;
|
if (!file) return;
|
||||||
if (Validations.isPreviewableImage(coverImage.type)) {
|
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);
|
return Strings.getURLfromCID(coverImage.cid);
|
||||||
}
|
}
|
||||||
if (coverImage.coverImage) {
|
if (file.linkImage) {
|
||||||
return Strings.getURLfromCID(coverImage.coverImage.cid);
|
return file.linkImage;
|
||||||
}
|
|
||||||
if (coverImage.linkImage) {
|
|
||||||
return coverImage.linkImage;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@ import * as Styles from "~/common/styles";
|
|||||||
import * as Constants from "~/common/constants";
|
import * as Constants from "~/common/constants";
|
||||||
import * as SVG from "~/common/svg";
|
import * as SVG from "~/common/svg";
|
||||||
import * as Validations from "~/common/validations";
|
import * as Validations from "~/common/validations";
|
||||||
|
import * as Utilities from "~/common/utilities";
|
||||||
|
|
||||||
import { css } from "@emotion/react";
|
import { css } from "@emotion/react";
|
||||||
import { FollowButton, ShareButton } from "~/components/core/CollectionPreviewBlock/components";
|
import { FollowButton, ShareButton } from "~/components/core/CollectionPreviewBlock/components";
|
||||||
@ -333,9 +334,9 @@ const useAnimateDescription = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getObjectToPreview = (coverImage) => {
|
const getObjectToPreview = (coverImage) => {
|
||||||
let isImage =
|
if (!coverImage) return { type: "EMPTY" };
|
||||||
Validations.isPreviewableImage(coverImage) ||
|
|
||||||
(coverImage.coverImage && Validations.isPreviewableImage(coverImage.coverImage));
|
|
||||||
|
|
||||||
return { object: coverImage, type: isImage ? "IMAGE" : "PLACEHOLDER" };
|
let coverImageUrl = Utilities.getImageUrlIfExists(coverImage);
|
||||||
|
|
||||||
|
return { object: coverImage, type: coverImageUrl ? "IMAGE" : "PLACEHOLDER" };
|
||||||
};
|
};
|
||||||
|
@ -411,7 +411,7 @@ export const selectSlateCoverImage = (objects) => {
|
|||||||
let selectedObject;
|
let selectedObject;
|
||||||
if (!objects.length) return null;
|
if (!objects.length) return null;
|
||||||
for (let object of objects) {
|
for (let object of objects) {
|
||||||
if (Utilities.getCoverImageUrlIfExists(object)) {
|
if (Utilities.getImageUrlIfExists(object)) {
|
||||||
selectedObject = object;
|
selectedObject = object;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ export const selectSlateCoverImage = (objects) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const addToSlateCheckCoverImage = async (slate, filesAdded) => {
|
export const addToSlateCheckCoverImage = async (slate, filesAdded) => {
|
||||||
if (Utilities.getCoverImageUrlIfExists(slate.coverImage)) {
|
if (Utilities.getImageUrlIfExists(slate.coverImage)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!filesAdded) return;
|
if (!filesAdded) return;
|
||||||
|
@ -230,7 +230,7 @@ export default class SceneSlate extends React.Component {
|
|||||||
description = `View the collection ${name} on Slate`;
|
description = `View the collection ${name} on Slate`;
|
||||||
}
|
}
|
||||||
title = `${name} • Slate`;
|
title = `${name} • Slate`;
|
||||||
imageUrl = slate.coverImage?.cid ? Strings.getURLfromCID(slate.coverImage.cid) : null;
|
image = Utilities.getImageUrlIfExists(slate.coverImage);
|
||||||
// const objects = slate.objects;
|
// const objects = slate.objects;
|
||||||
// if (!image && objects) {
|
// if (!image && objects) {
|
||||||
// for (let i = 0; i < objects.length; i++) {
|
// for (let i = 0; i < objects.length; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user