Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update review TP items #3228

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions src/components/ItemEditorPage/LeftPanel/Items/Items.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import equal from 'fast-deep-equal'
import { T, t } from 'decentraland-dapps/dist/modules/translation/utils'
import { getAnalytics } from 'decentraland-dapps/dist/modules/analytics/utils'
import {
Expand Down Expand Up @@ -42,6 +43,23 @@ export default class Items extends React.PureComponent<Props, State> {

analytics = getAnalytics()

componentDidMount() {
this.handleReviewItemsTrigger()
}

componentDidUpdate(prevProps: Props) {
this.handleReviewItemsTrigger(prevProps)
}

handleReviewItemsTrigger = (prevProps?: Props) => {
const { items, onReviewItems } = this.props
const { currentTab } = this.state

if (this.getIsReviewingTPItems() && currentTab === ItemPanelTabs.TO_REVIEW && !equal(items, prevProps?.items)) {
onReviewItems()
}
}

isVisible = (item: Item) => {
const { visibleItems } = this.props
return visibleItems.some(_item => _item.id === item.id)
Expand Down Expand Up @@ -81,30 +99,32 @@ export default class Items extends React.PureComponent<Props, State> {
}

handleTabChange = (targetTab: ItemPanelTabs) => {
const { onLoadPage, onResetReviewedItems } = this.props
const { currentPages, currentTab } = this.state
const { onLoadPage, onReviewItems, onResetReviewedItems } = this.props
const { currentPages } = this.state

if (targetTab === ItemPanelTabs.ALL_ITEMS) {
this.setState({ showAllItemsTabChangeModal: false }, () => onLoadPage(currentPages[ItemPanelTabs.ALL_ITEMS]))
} else if (targetTab === ItemPanelTabs.TO_REVIEW && currentTab === ItemPanelTabs.ALL_ITEMS) {
onResetReviewedItems()
onLoadPage(1)
this.setState({ showAllItemsTabChangeModal: false }, () => {
onResetReviewedItems()
onLoadPage(currentPages[ItemPanelTabs.ALL_ITEMS])
})
} else if (targetTab === ItemPanelTabs.TO_REVIEW) {
onReviewItems()
}
this.setState({ currentTab: targetTab })
}

handleGetRandomSampleClick = () => {
const { showSamplesModalAgain, onReviewItems } = this.props
const { showSamplesModalAgain, onLoadRandomPage } = this.props
if (!showSamplesModalAgain) {
onReviewItems()
onLoadRandomPage()
} else {
this.setState({ showGetMoreSamplesModal: true })
}
}

handleModalProceed = () => {
const { onReviewItems } = this.props
onReviewItems()
const { onLoadRandomPage } = this.props
onLoadRandomPage()
this.setState({ showGetMoreSamplesModal: false })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ export type Props = {
onSetItems: typeof setItems
onReviewItems: () => void
onLoadPage: (page: number) => void
onSetReviewedItems: (itemIds: Item[]) => void
onLoadRandomPage: () => void
}
8 changes: 4 additions & 4 deletions src/components/ItemEditorPage/LeftPanel/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ export default class LeftPanel extends React.PureComponent<Props, State> {
const totalPages = Math.ceil(totalResources! / LEFT_PANEL_PAGE_SIZE)
if (pages.length !== totalPages) {
let randomPage: number | undefined
while (randomPage !== undefined) {
while (randomPage === undefined) {
randomPage = this.getRandomPage(1, totalPages)
if (pages.includes(randomPage)) {
randomPage = undefined
}
}
onSetReviewedItems(currentItems)
if (randomPage !== undefined) {
this.setState(prevState => ({ pages: [...prevState.pages, randomPage] }), this.fetchResource)
this.setState(prevState => ({ pages: [...prevState.pages, randomPage as number] }), this.fetchResource)
}
} else {
onSetReviewedItems(currentItems)
Expand Down Expand Up @@ -273,9 +273,9 @@ export default class LeftPanel extends React.PureComponent<Props, State> {
isLoading={isLoadingCollectionItems || isLoadingOrphanItems}
onToggleShowSamplesModalAgain={this.handleToggleShowSamplesModalAgain}
showSamplesModalAgain={showSamplesModalAgain}
onReviewItems={() => this.loadRandomPage(items)}
onReviewItems={() => onSetReviewedItems(items)}
onLoadRandomPage={() => this.loadRandomPage(items)}
onLoadPage={this.loadPage}
onSetReviewedItems={onSetReviewedItems}
/>
<ItemAddedToast collectionId={selectedCollectionId} />
</>
Expand Down
Loading