mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-26 13:45:30 +03:00
fix: tag deletion
This commit is contained in:
parent
d11c082f4e
commit
ce5b5b4c98
@ -498,8 +498,8 @@ class CarouselSidebarData extends React.Component {
|
||||
const response = UserBehaviors.deleteTag(tag);
|
||||
|
||||
if (response.success) {
|
||||
/* this.setState({ suggestions: response.tags }); */
|
||||
this.props.onUpdateViewer({ tags: response.tags });
|
||||
this.updateSuggestions();
|
||||
}
|
||||
|
||||
if (Events.hasError(response)) {
|
||||
|
@ -134,3 +134,19 @@ export const editItem = ({ user, update }) => {
|
||||
}
|
||||
return user.data;
|
||||
};
|
||||
|
||||
export const removeTagFromItems = ({ user, tag }) => {
|
||||
const { library } = user.data;
|
||||
for (let i = 0; i < library[0].children.length; i++) {
|
||||
let item = library[0].children[i];
|
||||
|
||||
if (!item.tags) continue;
|
||||
|
||||
let tagIndex = item.tags.indexOf(tag);
|
||||
if (tagIndex > -1) {
|
||||
item.tags.splice(tagIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return user.data;
|
||||
};
|
||||
|
@ -2,6 +2,7 @@ import * as Utilities from "~/node_common/utilities";
|
||||
import * as Data from "~/node_common/data";
|
||||
import * as ViewerManager from "~/node_common/managers/viewer";
|
||||
import * as SearchManager from "~/node_common/managers/search";
|
||||
import * as LibraryManager from "~/node_common/managers/library";
|
||||
|
||||
export default async (req, res) => {
|
||||
const id = Utilities.getIdFromCookie(req);
|
||||
@ -48,7 +49,7 @@ export default async (req, res) => {
|
||||
let tags = slate.data.tags;
|
||||
let tagIndex = tags.indexOf(tagToDelete);
|
||||
|
||||
if (tagIndex && tagIndex > -1) {
|
||||
if (tagIndex > -1) {
|
||||
tags.splice(tagIndex, 1);
|
||||
}
|
||||
|
||||
@ -67,15 +68,15 @@ export default async (req, res) => {
|
||||
SearchManager.updateSlate(newSlate, "EDIT");
|
||||
}
|
||||
|
||||
// NOTE(daniel): Remove tag from object
|
||||
for (const item of user.data.library[0].children) {
|
||||
if (!item.tags) continue;
|
||||
// NOTE(daniel): Remove tag from all data objects
|
||||
let newUserData = LibraryManager.removeTagFromItems({ user, tag: tagToDelete });
|
||||
let updateResponse = await Data.updateUserById({
|
||||
id: user.id,
|
||||
data: newUserData,
|
||||
});
|
||||
|
||||
let tags = item.tags;
|
||||
let tagIndex = tags.indexOf(tagToDelete);
|
||||
if (tagIndex > -1) {
|
||||
tags.splice(tagIndex, 1);
|
||||
}
|
||||
if (!updateResponse || updateResponse.error) {
|
||||
return res.status(500).send({ decorator: "SERVER_EDIT_DATA_NOT_UPDATED", error: true });
|
||||
}
|
||||
|
||||
let tags;
|
||||
@ -84,7 +85,6 @@ export default async (req, res) => {
|
||||
ViewerManager.hydratePartialSlates(slates, id);
|
||||
|
||||
tags = Utilities.getUserTags({ library: user.data.library[0].children, slates });
|
||||
console.log(tags);
|
||||
}
|
||||
|
||||
return res.status(200).send({ decorator: "SERVER_DELETE_TAGS", success: true, tags });
|
||||
|
Loading…
Reference in New Issue
Block a user