Skip to content

Commit

Permalink
feat: add multiple tag campaign (#2053)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melisa Anabella Rossi authored Nov 16, 2023
1 parent c5f38bb commit 68f44f8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const mapState = (state: RootState): MapStateProps => ({
})

const mapDispatch = (dispatch: MapDispatch) => ({
onFetchEventContracts: (tag: string) => dispatch(fetchEventRequest(tag))
onFetchEventContracts: (eventTag: string, additionalSearchTags: string[] = []) =>
dispatch(fetchEventRequest(eventTag, additionalSearchTags))
})

export default connect(mapState, mapDispatch)(BrowsePage)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Navigation } from '../../Navigation'
import { AssetBrowse } from '../../AssetBrowse'
import { CampaignBrowserBanner } from '../banners/CampaignBrowserBanner'
import { CampaignBanner } from '../CampaignBanner'
import { CAMPAIGN_TAG } from '../config'
import { ADDITIONAL_CAMPAIGN_BROWSE_TAGS, CAMPAIGN_TAG } from '../config'
import { Props } from './CampaignBrowserPage.types'
import './CampaignBrowserPage.css'

Expand All @@ -27,7 +27,7 @@ const CampaignBrowserPage = (props: Props) => {
const vendor = isVendor(props.vendor) ? props.vendor : VendorName.DECENTRALAND

useEffect(() => {
onFetchEventContracts(CAMPAIGN_TAG)
onFetchEventContracts(CAMPAIGN_TAG, ADDITIONAL_CAMPAIGN_BROWSE_TAGS)
}, [onFetchEventContracts])

const activeTab = NavigationTab.CAMPAIGN_BROWSER
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/Campaign/config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const CAMPAIGN_TAG = 'DCLMF23'
export const ADDITIONAL_CAMPAIGN_BROWSE_TAGS = ['MVMF22']
export const CAMPAING_TAB_ANIMATION_ENABLED = true
46 changes: 33 additions & 13 deletions webapp/src/modules/event/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,56 @@ import {
} from './actions'

const anErrorMessage = 'An error'
let eventTag: string
let additionalTags: string[]

describe('when creating the action to signal the start of the events request', () => {
let tag: string
beforeEach(() => {
tag = 'a tag'
eventTag = 'eventTag'
})
it('should return an object representing the action', () => {
expect(fetchEventRequest(tag)).toEqual({
type: FETCH_EVENT_REQUEST,
meta: undefined,
payload: {
tag
}

describe('and there are not additional searchTags', () => {
it('should return an object representing the action', () => {
expect(fetchEventRequest(eventTag)).toEqual({
type: FETCH_EVENT_REQUEST,
meta: undefined,
payload: {
eventTag,
additionalSearchTags: []
}
})
})
})

describe('and there are additional search tags', () => {
beforeEach(() => {
additionalTags = ['tag1', 'tag2']
})
it('should return an object representing the action', () => {
expect(fetchEventRequest(eventTag, additionalTags)).toEqual({
type: FETCH_EVENT_REQUEST,
meta: undefined,
payload: {
eventTag,
additionalSearchTags: additionalTags
}
})
})
})
})

describe('when creating the action to signal a success in the events request', () => {
let tag: string
let contracts: string[]
beforeEach(() => {
tag = 'a tag'
eventTag = 'a tag'
contracts = ['0x1', '0x2']
})

it('should return an object representing the action', () => {
expect(fetchEventSuccess(tag, contracts)).toEqual({
expect(fetchEventSuccess(eventTag, contracts)).toEqual({
type: FETCH_EVENT_SUCCESS,
meta: undefined,
payload: { tag, contracts }
payload: { eventTag, contracts }
})
})
})
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/modules/event/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export const FETCH_EVENT_REQUEST = '[Request] Fetch event'
export const FETCH_EVENT_SUCCESS = '[Success] Fetch event'
export const FETCH_EVENT_FAILURE = '[Failure] Fetch event'

export const fetchEventRequest = (tag: string) =>
action(FETCH_EVENT_REQUEST, { tag })
export const fetchEventSuccess = (tag: string, contracts: string[]) =>
action(FETCH_EVENT_SUCCESS, { tag, contracts })
export const fetchEventRequest = (eventTag: string, additionalSearchTags: string[] = []) =>
action(FETCH_EVENT_REQUEST, { eventTag, additionalSearchTags })
export const fetchEventSuccess = (eventTag: string, contracts: string[]) =>
action(FETCH_EVENT_SUCCESS, { eventTag, contracts })
export const fetchEventFailure = (error: string) =>
action(FETCH_EVENT_FAILURE, { error })

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/modules/event/reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('when reducing the successful action of fetching an event addresses by

const initialState = {
...INITIAL_STATE,
data: { evnet1: ['0x1', '0x2'] },
data: { event1: ['0x1', '0x2'] },
loading: loadingReducer([], requestAction)
}

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/modules/event/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export function eventReducer(
loading: loadingReducer(state.loading, action)
}
case FETCH_EVENT_SUCCESS:
const { tag, contracts } = action.payload
const { eventTag, contracts } = action.payload
return {
...state,
loading: loadingReducer(state.loading, action),
error: null,
data: {
...state.data,
[tag]: contracts
[eventTag]: contracts
}
}
case FETCH_EVENT_FAILURE:
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/modules/event/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export function* eventSaga() {
}

export function* handleFetchEventRequest(action: FetchEventRequestAction) {
const { tag } = action.payload
const { eventTag, additionalSearchTags } = action.payload

try {
const addresses: string[] = yield call(
[builderAPI, builderAPI.fetchAddressesByTag],
[tag]
[eventTag, ...additionalSearchTags]
)

yield put(fetchEventSuccess(tag, addresses))
yield put(fetchEventSuccess(eventTag, addresses))
} catch (error) {
yield put(
fetchEventFailure(
Expand Down

0 comments on commit 68f44f8

Please sign in to comment.