diff --git a/common/actions.js b/common/actions.js index b5fa79c0..a4c7565a 100644 --- a/common/actions.js +++ b/common/actions.js @@ -259,6 +259,13 @@ export const addCIDToData = async (data) => { }); }; +export const updateData = async (data) => { + return await returnJSON(`/api/data/update`, { + ...DEFAULT_OPTIONS, + body: JSON.stringify({ data }), + }); +}; + export const deleteBucketItems = async (data) => { return await returnJSON(`/api/data/remove`, { ...DEFAULT_OPTIONS, diff --git a/components/core/Application.js b/components/core/Application.js index 1ee16e08..bb17f553 100644 --- a/components/core/Application.js +++ b/components/core/Application.js @@ -977,6 +977,7 @@ export default class ApplicationPage extends React.Component { {scene} diff --git a/components/core/SlateMediaObjectPreview.js b/components/core/SlateMediaObjectPreview.js index 34280ad8..951d3654 100644 --- a/components/core/SlateMediaObjectPreview.js +++ b/components/core/SlateMediaObjectPreview.js @@ -99,7 +99,6 @@ export default class SlateMediaObjectPreview extends React.Component { if (this.props.type && Validations.isPreviewableImage(this.props.type)) { let blurhash = this.props.blurhash && isBlurhashValid(this.props.blurhash); - console.log("check"); if (this.props.centeredImage) { return ( diff --git a/components/system/components/GlobalCarousel.js b/components/system/components/GlobalCarousel.js index acb28176..5fe97cf0 100644 --- a/components/system/components/GlobalCarousel.js +++ b/components/system/components/GlobalCarousel.js @@ -414,6 +414,7 @@ export class GlobalCarousel extends React.Component { loading={this.state.loading} slates={this.props.slates} onAction={this.props.onAction} + resources={this.props.resources} data={data} cid={data.cid} /> diff --git a/node_common/managers/library.js b/node_common/managers/library.js index 0f05f8f3..57aa4966 100644 --- a/node_common/managers/library.js +++ b/node_common/managers/library.js @@ -114,3 +114,15 @@ export const addData = ({ user, files }) => { skipped: files.length - noRepeats.length, }; }; + +export const editItem = ({ user, update }) => { + const { library } = user.data; + + for (let i = 0; i < library[0].children.length; i++) { + if (library[0].children[i].id === update.id) { + library[0].children[i] = { ...library[0].children[i], ...update }; + break; + } + } + return user.data; +}; diff --git a/pages/api/data/update.js b/pages/api/data/update.js new file mode 100644 index 00000000..67782051 --- /dev/null +++ b/pages/api/data/update.js @@ -0,0 +1,54 @@ +import * as Data from "~/node_common/data"; +import * as Utilities from "~/node_common/utilities"; +import * as LibraryManager from "~/node_common/managers/library"; + +export default async (req, res) => { + const id = Utilities.getIdFromCookie(req); + if (!id) { + return res.status(500).send({ decorator: "SERVER_EDIT_DATA", error: true }); + } + + const user = await Data.getUserById({ id }); + + if (!user || user.error) { + return res.status(403).send({ decorator: "SERVER_EDIT_DATA_USER_NOT_FOUND", error: true }); + } + + let newUserData = LibraryManager.editItem({ user, update: req.body.data.update }); + let response = await Data.updateUserById({ + id: user.id, + data: newUserData, + }); + + if (!response || response.error) { + return res.status(500).send({ decorator: "SERVER_EDIT_DATA_NOT_UPDATED", error: true }); + } + + let slates = await Data.getSlatesByUserId({ userId: id }); + for (let slate of slates) { + let edited = false; + let objects = slate.data.objects.map((obj) => { + if (obj.id === req.body.data.update.id) { + edited = true; + obj = { ...obj, ...req.body.data.update }; + } + return obj; + }); + + if (edited) { + await Data.updateSlateById({ + id: slate.id, + updated_at: new Date(), + data: { + ...slate.data, + objects, + }, + }); + } + } + + return res.status(200).send({ + decorator: "SERVER_EDIT_DATA", + data: {}, + }); +}; diff --git a/pages/api/slates/add-url.js b/pages/api/slates/add-url.js index 638faa14..e879ffe7 100644 --- a/pages/api/slates/add-url.js +++ b/pages/api/slates/add-url.js @@ -105,6 +105,7 @@ export default async (req, res) => { return { blurhash: each.blurhash, + previewImage: each.previewImage, cid: cid, size: each.size, id: each.id,