fixed showing zero counts for slate preview blocks

This commit is contained in:
Martina 2021-05-31 22:14:22 -07:00
parent 25ee79dd0c
commit c9c148adc9
9 changed files with 38 additions and 20 deletions

View File

@ -87,8 +87,8 @@ export default class SlateMediaObjectPreview extends React.Component {
};
setImage = () => {
let type = this.props.file.data.type;
let coverImage = this.props.file.data.coverImage;
let type = this.props.file.data?.type;
let coverImage = this.props.file.data?.coverImage;
let url;
if (type && Validations.isPreviewableImage(type)) {
url = Strings.getURLfromCID(this.props.file.cid);
@ -104,8 +104,8 @@ export default class SlateMediaObjectPreview extends React.Component {
render() {
const file = this.props.file;
const type = this.props.file.data.type;
const coverImage = this.props.file.data.coverImage;
const type = this.props.file.data?.type;
const coverImage = this.props.file.data?.coverImage;
let url;
if (type && Validations.isPreviewableImage(type)) {
url = Strings.getURLfromCID(this.props.file.cid);
@ -115,8 +115,8 @@ export default class SlateMediaObjectPreview extends React.Component {
if (url) {
const blurhash =
file.data.blurhash && isBlurhashValid(file.data.blurhash)
? file.data.blurhash
file.data.blurhash && isBlurhashValid(file.data?.blurhash)
? file.data?.blurhash
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash)
? coverImage?.data.blurhash
: null;
@ -185,14 +185,14 @@ export default class SlateMediaObjectPreview extends React.Component {
);
}
let name = (file.data.name || file.filename).substring(0, this.charCap);
let name = (file.data?.name || file.filename).substring(0, this.charCap);
let extension = Strings.getFileExtension(file.filename);
if (extension && extension.length) {
extension = extension.toUpperCase();
}
let element = (
<FileTypeIcon
type={file.data.type}
type={file.data?.type}
height={this.props.previewPanel ? "26px" : "20px"}
style={{ color: Constants.system.textGray }}
/>

View File

@ -272,6 +272,9 @@ export class SlatePreviewBlock extends React.Component {
if (objects.length >= 4) break;
}
}
if (!objects.length && slate.objects?.length) {
objects = [slate.objects[0]];
}
let contextMenu = (
<React.Fragment>
@ -306,6 +309,7 @@ export class SlatePreviewBlock extends React.Component {
/>
</React.Fragment>
);
console.log(slate);
return (
<div css={STYLES_BLOCK}>
@ -334,8 +338,8 @@ export class SlatePreviewBlock extends React.Component {
</div>
) : (
<div css={STYLES_OBJECT_COUNT}>
{objects.length} file
{objects.length > 1 ? "s" : ""}
{slate.objects.length} file
{slate.objects.length !== 1 ? "s" : ""}
</div>
)}
</div>

View File

@ -44,4 +44,5 @@ export const fileProperties = [
"files.createdAt",
"files.likeCount",
"files.downloadCount",
"files.saveCount",
];

View File

@ -4,6 +4,8 @@ import * as Constants from "~/node_common/constants";
import { runQuery } from "~/node_common/data/utilities";
export default async ({ ownerId, sanitize = false, includeFiles = false, publicOnly = false }) => {
console.log("inside get slates by user id");
console.log(Constants.slateProperties);
return await runQuery({
label: "GET_SLATES_BY_USER_ID",
queryFn: async (DB) => {
@ -25,7 +27,6 @@ export default async ({ ownerId, sanitize = false, includeFiles = false, publicO
]);
let query;
if (includeFiles) {
if (publicOnly) {
query = await DB.select(...Constants.slateProperties, slateFiles())
@ -57,7 +58,9 @@ export default async ({ ownerId, sanitize = false, includeFiles = false, publicO
.orderBy("updatedAt", "desc");
}
}
console.log("STARTS HERE");
console.log(query[0]);
console.log("ENDS HERE");
if (!query || query.error) {
return [];
}

View File

@ -16,6 +16,9 @@ export const sanitizeUser = (entity) => {
photo: entity.data?.photo,
body: entity.data?.body,
},
fileCount: entity.fileCount,
followerCount: entity.followerCount,
slateCount: entity.slateCount,
};
};
@ -34,6 +37,8 @@ export const sanitizeSlate = (entity) => {
layouts: entity.data?.layouts,
tags: entity.data?.tags,
},
fileCount: entity.fileCount,
subscriberCount: entity.subscriberCount,
};
};
@ -59,6 +64,9 @@ export const sanitizeFile = (entity) => {
unity: entity.data?.unity, //NOTE(martina): newly added
link: entity.data?.link, //NOTE(martina): newly added
},
likeCount: entity.likeCount,
downloadCount: entity.downloadCount,
saveCount: entity.saveCount,
};
};

View File

@ -183,6 +183,7 @@ export const getBucketAPIFromUserToken = async ({ user, bucketName, encrypted =
if (!root) {
NodeLogging.error(`buckets.getOrCreate() failed for ${name}`);
console.log(user);
return { buckets: null, bucketKey: null, bucketRoot: null };
}

View File

@ -39,7 +39,7 @@ export default async (req, res) => {
error: true,
});
}
console.log("before get slates by user id");
let slates = await Data.getSlatesByUserId({
ownerId: user.id,
includeFiles: true,

View File

@ -7,7 +7,7 @@ import * as Data from "~/node_common/data";
import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
const envConfig = configs["development"];
const envConfig = configs["production"];
const DB = knex(envConfig);
@ -28,9 +28,11 @@ const saveCopyReposts = async () => {
.join("files", "files.id", "=", "slate_files.fileId")
.join("users", "users.id", "=", "slates.ownerId")
.whereRaw("?? != ??", ["files.ownerId", "slates.ownerId"]);
// console.log(repostedFiles.length);
for (let item of repostedFiles) {
console.log(item);
// continue;
let user = { data: item.data };
let { buckets, bucketKey, bucketRoot } = await Utilities.getBucketAPIFromUserToken({
user,
@ -40,7 +42,7 @@ const saveCopyReposts = async () => {
let response = await Utilities.addExistingCIDToData({
buckets,
key: bucketKey,
path: bucketRoot.path,
path: bucketRoot?.path,
cid: item.cid,
});
} catch (e) {
@ -65,7 +67,6 @@ const saveCopyReposts = async () => {
isPublic: item.isPublic,
data: item.fileData,
};
// console.log(file);
await DB.insert(file).into("files");
}
}
@ -80,7 +81,9 @@ const removeReposts = async () => {
.join("files", "files.id", "=", "slate_files.fileId")
.whereRaw("?? != ??", ["files.ownerId", "slates.ownerId"]);
})
.del();
.del()
.returning("*");
console.log(repostedFiles);
};
const runScript = async () => {

View File

@ -304,11 +304,9 @@ app.prepare().then(async () => {
id,
});
}
console.log(req.query);
let { page } = NavigationData.getByHref(req.path, viewer);
console.log(page);
page = { ...page, params: req.query };
console.log(page);
let user = await Data.getUserByUsername({
username,