Skip to content

Commit

Permalink
fix: remove console.log and create new trimmed object
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Aug 6, 2021
1 parent 8ce95a0 commit 6b3a055
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/mutations/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,19 @@ export default (queryClient: QueryClient, queryConfig: QueryClientConfig) => {
mutationFn: (item) => Api.editItem(item.id, item, queryConfig),
// newItem contains only changed values
onMutate: async (newItem: Partial<Item>) => {
newItem = {
const trimmed = {
...newItem,
name: newItem.name?.trim()
};

console.log(newItem);

const itemKey = buildItemKey(newItem.id);
const itemKey = buildItemKey(trimmed.id);

// invalidate key
await queryClient.cancelQueries(itemKey);

// build full item with new values
const prevItem = queryClient.getQueryData(itemKey) as Record<Item>;
const newFullItem = prevItem.merge(newItem);
const newFullItem = prevItem.merge(trimmed);

const previousItems = {
parent: await mutateParentChildren({
Expand All @@ -138,7 +136,7 @@ export default (queryClient: QueryClient, queryConfig: QueryClientConfig) => {
if (!old || old.isEmpty()) {
return old;
}
const idx = old.findIndex(({ id }) => id === newItem.id);
const idx = old.findIndex(({ id }) => id === trimmed.id);
// todo: remove toJS when moving to List<Map<Item>>
return old.set(idx, newFullItem.toJS());
},
Expand Down

0 comments on commit 6b3a055

Please sign in to comment.