mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-27 11:03:23 +03:00
made some edits to make the new get image url work
This commit is contained in:
parent
d12520455f
commit
33f92ca56f
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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.type) ||
|
||||
(coverImage.coverImage && Validations.isPreviewableImage(coverImage.coverImage.type));
|
||||
if (!coverImage) return { type: "EMPTY" };
|
||||
|
||||
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;
|
||||
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;
|
||||
|
@ -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++) {
|
||||
|
Loading…
Reference in New Issue
Block a user