Skip to content

Commit c947299

Browse files
Feat: Load item when upserting (#3156)
* feat: Load upserted item when upserting * feat: Load item when upserting
1 parent cfb309f commit c947299

File tree

14 files changed

+145
-109
lines changed

14 files changed

+145
-109
lines changed

src/components/CollectionsPage/CollectionCard/CollectionCard.container.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { connect } from 'react-redux'
22

33
import { RootState } from 'modules/common/types'
44
import { getCollectionItemCount } from 'modules/collection/selectors'
5-
import { setCollection } from 'modules/item/actions'
65
import { deleteCollectionRequest } from 'modules/collection/actions'
76
import { MapStateProps, MapDispatchProps, MapDispatch, OwnProps } from './CollectionCard.types'
87
import CollectionCard from './CollectionCard'
@@ -12,7 +11,6 @@ const mapState = (state: RootState, ownProps: OwnProps): MapStateProps => ({
1211
})
1312

1413
const mapDispatch = (dispatch: MapDispatch, ownProps: OwnProps): MapDispatchProps => ({
15-
onSetCollection: (item, collectionId) => dispatch(setCollection(item, collectionId)),
1614
onDeleteCollection: () => dispatch(deleteCollectionRequest(ownProps.collection))
1715
})
1816

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { Dispatch } from 'redux'
22
import { Collection } from 'modules/collection/types'
3-
import { setCollection, SetCollectionAction } from 'modules/item/actions'
3+
import { SetCollectionAction } from 'modules/item/actions'
44
import { DeleteCollectionRequestAction } from 'modules/collection/actions'
55

66
export type Props = {
77
collection: Collection
88
itemCount: number
9-
onSetCollection: typeof setCollection
109
onDeleteCollection: () => ReturnType<Dispatch<DeleteCollectionRequestAction>>
1110
}
1211

1312
export type MapStateProps = Pick<Props, 'itemCount'>
14-
export type MapDispatchProps = Pick<Props, 'onSetCollection' | 'onDeleteCollection'>
13+
export type MapDispatchProps = Pick<Props, 'onDeleteCollection'>
1514
export type MapDispatch = Dispatch<SetCollectionAction | DeleteCollectionRequestAction>
1615
export type OwnProps = Pick<Props, 'collection'>

src/components/ItemEditorPage/LeftPanel/Collections/Collections.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class Collections extends React.PureComponent<Props, State> {
1717
}
1818

1919
render() {
20-
const { collections, isLoading, items, onSetCollection, selectedCollectionId, totalCollections } = this.props
20+
const { collections, isLoading, items, selectedCollectionId, totalCollections } = this.props
2121
const { currentPage } = this.state
2222
if (collections.length === 0) return null
2323

@@ -34,7 +34,6 @@ export default class Collections extends React.PureComponent<Props, State> {
3434
collection={collection}
3535
items={items}
3636
isSelected={collection.id === selectedCollectionId}
37-
onSetCollection={onSetCollection}
3837
/>
3938
))}
4039
{totalPages > 1 ? (

src/components/ItemEditorPage/LeftPanel/Collections/Collections.types.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Collection } from 'modules/collection/types'
2-
import { setCollection } from 'modules/item/actions'
32
import { Item } from 'modules/item/types'
43

54
export type State = {
@@ -13,6 +12,5 @@ export type Props = {
1312
totalCollections: number
1413
items: Item[]
1514
hasHeader: boolean
16-
onSetCollection: typeof setCollection
1715
onLoadPage: (page: number) => void
1816
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Collection } from 'modules/collection/types'
2-
import { setCollection } from 'modules/item/actions'
32
import { Item } from 'modules/item/types'
43

54
export type Props = {
65
collection: Collection
76
items: Item[]
87
isSelected: boolean
9-
onSetCollection: typeof setCollection
108
}

src/components/ItemEditorPage/LeftPanel/LeftPanel.container.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ import {
1616
import { fetchCollectionsRequest } from 'modules/collection/actions'
1717
import { getAuthorizedCollections, getPaginationData as getCollectionsPaginationData } from 'modules/collection/selectors'
1818
import { setItems } from 'modules/editor/actions'
19-
import {
20-
fetchItemsRequest,
21-
fetchOrphanItemRequest,
22-
FETCH_ITEMS_REQUEST,
23-
FETCH_ORPHAN_ITEM_REQUEST,
24-
setCollection
25-
} from 'modules/item/actions'
19+
import { fetchItemsRequest, fetchOrphanItemRequest, FETCH_ITEMS_REQUEST, FETCH_ORPHAN_ITEM_REQUEST } from 'modules/item/actions'
2620
import { MapStateProps, MapDispatchProps, MapDispatch } from './LeftPanel.types'
2721
import LeftPanel from './LeftPanel'
2822

@@ -64,7 +58,6 @@ const mapState = (state: RootState): MapStateProps => {
6458

6559
const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
6660
onSetItems: items => dispatch(setItems(items)),
67-
onSetCollection: (item, collectionId) => dispatch(setCollection(item, collectionId)),
6861
onFetchCollections: (address, params) => dispatch(fetchCollectionsRequest(address, params)),
6962
onFetchOrphanItems: (address, params) => dispatch(fetchItemsRequest(address, params)),
7063
onFetchOrphanItem: address => dispatch(fetchOrphanItemRequest(address))

src/components/ItemEditorPage/LeftPanel/LeftPanel.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export default class LeftPanel extends React.PureComponent<Props, State> {
181181
isLoading: isLoadingOrphanItems,
182182
hasUserOrphanItems,
183183
onSetItems,
184-
onSetCollection,
185184
onSetReviewedItems
186185
} = this.props
187186
const { pages } = this.state
@@ -250,7 +249,6 @@ export default class LeftPanel extends React.PureComponent<Props, State> {
250249
items={allItems}
251250
hasHeader={items.length > 0}
252251
selectedCollectionId={selectedCollectionId}
253-
onSetCollection={onSetCollection}
254252
onLoadPage={this.loadPage}
255253
isLoading={isLoading}
256254
/>

src/components/ItemEditorPage/LeftPanel/LeftPanel.types.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import {
99
fetchItemsRequest,
1010
FetchItemsRequestAction,
1111
fetchOrphanItemRequest,
12-
FetchOrphanItemRequestAction,
13-
setCollection,
14-
SetCollectionAction
12+
FetchOrphanItemRequestAction
1513
} from 'modules/item/actions'
1614

1715
export enum ItemEditorTabs {
@@ -38,7 +36,6 @@ export type Props = {
3836
wearableController: IPreviewController | null
3937
hasUserOrphanItems: boolean | undefined
4038
onSetItems: typeof setItems
41-
onSetCollection: typeof setCollection
4239
onFetchOrphanItems: typeof fetchItemsRequest
4340
onFetchCollections: typeof fetchCollectionsRequest
4441
onSetReviewedItems: (itemIds: Item[]) => void
@@ -71,13 +68,9 @@ export type MapStateProps = Pick<
7168
| 'isPlayingEmote'
7269
| 'hasUserOrphanItems'
7370
>
74-
export type MapDispatchProps = Pick<
75-
Props,
76-
'onSetItems' | 'onSetCollection' | 'onFetchOrphanItems' | 'onFetchCollections' | 'onFetchOrphanItem'
77-
>
71+
export type MapDispatchProps = Pick<Props, 'onSetItems' | 'onFetchOrphanItems' | 'onFetchCollections' | 'onFetchOrphanItem'>
7872
export type MapDispatch = Dispatch<
7973
| SetItemsAction
80-
| SetCollectionAction
8174
| FetchCollectionItemsRequestAction
8275
| FetchItemsRequestAction
8376
| FetchCollectionsRequestAction

src/components/ItemEditorPage/RightPanel/RightPanel.container.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { connect } from 'react-redux'
22
import { getAddress, isConnected } from 'decentraland-dapps/dist/modules/wallet/selectors'
33
import { RootState } from 'modules/common/types'
44
import { getItem, getError as getItemError, getStatusByItemId, isDownloading } from 'modules/item/selectors'
5-
import { deleteItemRequest, downloadItemRequest, saveItemRequest, setCollection } from 'modules/item/actions'
5+
import { deleteItemRequest, downloadItemRequest, saveItemRequest } from 'modules/item/actions'
66
import { openModal } from 'decentraland-dapps/dist/modules/modal/actions'
77
import { isOwner } from 'modules/item/utils'
88
import { getSelectedItemId } from 'modules/location/selectors'
@@ -44,7 +44,6 @@ const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
4444
onSaveItem: (item, contents) => dispatch(saveItemRequest(item, contents)),
4545
onDeleteItem: item => dispatch(deleteItemRequest(item)),
4646
onOpenModal: (name, metadata) => dispatch(openModal(name, metadata)),
47-
onSetCollection: (item, collectionId) => dispatch(setCollection(item, collectionId)),
4847
onDownload: itemId => dispatch(downloadItemRequest(itemId))
4948
})
5049

src/components/ItemEditorPage/RightPanel/RightPanel.types.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
DeleteItemRequestAction,
66
saveItemRequest,
77
SaveItemRequestAction,
8-
setCollection,
9-
SetCollectionAction,
108
downloadItemRequest,
119
DownloadItemRequestAction
1210
} from 'modules/item/actions'
@@ -31,7 +29,6 @@ export type Props = {
3129
onSaveItem: typeof saveItemRequest
3230
onDeleteItem: typeof deleteItemRequest
3331
onOpenModal: typeof openModal
34-
onSetCollection: typeof setCollection
3532
onDownload: typeof downloadItemRequest
3633
}
3734

@@ -64,7 +61,5 @@ export type MapStateProps = Pick<
6461
| 'isVrmOptOutEnabled'
6562
| 'isWearableUtilityEnabled'
6663
>
67-
export type MapDispatchProps = Pick<Props, 'onSaveItem' | 'onDeleteItem' | 'onOpenModal' | 'onSetCollection' | 'onDownload'>
68-
export type MapDispatch = Dispatch<
69-
SaveItemRequestAction | DeleteItemRequestAction | OpenModalAction | SetCollectionAction | DownloadItemRequestAction
70-
>
64+
export type MapDispatchProps = Pick<Props, 'onSaveItem' | 'onDeleteItem' | 'onOpenModal' | 'onDownload'>
65+
export type MapDispatch = Dispatch<SaveItemRequestAction | DeleteItemRequestAction | OpenModalAction | DownloadItemRequestAction>

src/lib/api/builder.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,12 @@ export class BuilderAPI extends BaseAPI {
792792
return remoteResponse.map(fromRemoteItem) as Item[]
793793
}
794794

795-
saveItem = async (item: Item, contents: Record<string, Blob>) => {
796-
await this.request('put', `/items/${item.id}`, { params: { item: toRemoteItem(item) } })
795+
saveItem = async (item: Item, contents: Record<string, Blob>): Promise<Item> => {
796+
const savedItemResponse = await this.request('put', `/items/${item.id}`, { params: { item: toRemoteItem(item) } })
797+
const remoteSavedItem = fromRemoteItem(savedItemResponse)
797798
// This has to be done after the PUT above, otherwise it will fail when creating an item, since it wont find it in the DB and return a 404
798799
await this.saveItemContents(item, contents)
800+
return remoteSavedItem
799801
}
800802

801803
saveItemContents = async (item: Item, contents: Record<string, Blob>) => {

0 commit comments

Comments
 (0)