Skip to content

Commit 758afee

Browse files
[FF][UXIT-3730] Show All Events when there are no upcoming events (#2034)
* Updated EventsContent to utilize getDefaultViewConfig and getDefaultViewOption for improved sorting functionality. * Add mobile sort * Memoize default view config and extract constants --------- Co-authored-by: Charly Martin <[email protected]>
1 parent a681616 commit 758afee

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

apps/ff-site/src/app/events/components/EventSort.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { CalendarBlankIcon } from '@phosphor-icons/react'
44

55
import { useListboxQueryState } from '@filecoin-foundation/hooks/useListboxQueryState'
6+
import type { OptionType } from '@filecoin-foundation/ui/Listbox/ListboxOption'
67
import { SORT_KEY } from '@filecoin-foundation/utils/constants/urlParamsConstants'
78

89
import { getSortOptions } from '@/utils/getSortOptions'
@@ -13,10 +14,15 @@ import { eventsViewConfigs } from '../constants/viewConfigs'
1314

1415
const options = getSortOptions(eventsViewConfigs)
1516

16-
export function EventSort() {
17+
type EventSortProps = {
18+
defaultOption?: OptionType
19+
}
20+
21+
export function EventSort({ defaultOption }: EventSortProps) {
1722
const [selectedSort, setSelectedSort] = useListboxQueryState({
1823
key: SORT_KEY,
1924
options: options,
25+
defaultOption: defaultOption || options[0],
2026
})
2127

2228
return (

apps/ff-site/src/app/events/components/EventsContent.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useMemo } from 'react'
2+
13
import { MagnifyingGlassIcon } from '@phosphor-icons/react/dist/ssr'
24

35
import { useEntryView } from '@filecoin-foundation/hooks/useEntryView'
@@ -33,7 +35,10 @@ import { LocationFilter } from '@/components/LocationFilter'
3335

3436
import { EventSort } from '../components/EventSort'
3537
import { DEFAULT_CTA_TEXT, FILTERS_CONFIG } from '../constants/constants'
36-
import { eventsViewConfigs } from '../constants/viewConfigs'
38+
import {
39+
eventsViewConfigs,
40+
getDefaultViewConfig,
41+
} from '../constants/viewConfigs'
3742
import type { Event } from '../types/eventType'
3843
import { entryMatchesLocationQuery } from '../utils/filterUtils'
3944
import { getLocationListboxOptions } from '../utils/getLocationFilterOptions'
@@ -50,6 +55,16 @@ export default function EventsContent({
5055
searchParams,
5156
events,
5257
}: EventsContentProps) {
58+
const defaultViewConfig = useMemo(
59+
() => getDefaultViewConfig(events),
60+
[events],
61+
)
62+
63+
const defaultSortOption = {
64+
id: defaultViewConfig.id,
65+
name: defaultViewConfig.name,
66+
}
67+
5368
const { searchResults } = useSearch({
5469
searchQuery: normalizeQueryParam(searchParams, SEARCH_KEY),
5570
entries: events,
@@ -60,6 +75,7 @@ export default function EventsContent({
6075
query: normalizeQueryParam(searchParams, SORT_KEY),
6176
entries: searchResults,
6277
configs: eventsViewConfigs,
78+
defaultConfig: defaultViewConfig,
6379
})
6480

6581
const { filteredEntries: filteredEventsByLocation } = useFilter({
@@ -94,14 +110,14 @@ export default function EventsContent({
94110
<FilterContainer.MainWrapper>
95111
<FilterContainer.DesktopFilters
96112
searchComponent={<Search />}
97-
sortComponent={<EventSort />}
113+
sortComponent={<EventSort defaultOption={defaultSortOption} />}
98114
filterComponents={[
99115
<LocationFilter key="location" options={locationOptions} />,
100116
]}
101117
/>
102118
<FilterContainer.MobileFiltersAndResults
103119
searchComponent={<Search />}
104-
sortComponent={<EventSort />}
120+
sortComponent={<EventSort defaultOption={defaultSortOption} />}
105121
filterComponents={[
106122
<CategoryFilter
107123
key="category"

apps/ff-site/src/app/events/constants/viewConfigs.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@ import type { EntryViewConfig } from '@filecoin-foundation/hooks/useEntryView/ty
33
import { type Event } from '../types/eventType'
44

55
import {
6-
sortEventsDesc,
7-
getUpcomingEvents,
86
getPastEvents,
7+
getUpcomingEvents,
8+
sortEventsDesc,
99
} from '@/events/utils/sortEvents'
1010

11+
const upcomingEventsConfig = {
12+
id: 'upcoming-events',
13+
name: 'Upcoming Events',
14+
filterOrSortFn: getUpcomingEvents,
15+
}
16+
17+
const allEventsConfig = {
18+
id: 'all-events',
19+
name: 'All Events',
20+
filterOrSortFn: sortEventsDesc,
21+
}
22+
23+
const pastEventsConfig = {
24+
id: 'past-events',
25+
name: 'Past Events',
26+
filterOrSortFn: getPastEvents,
27+
}
28+
1129
export const eventsViewConfigs = [
12-
{
13-
id: 'upcoming-events',
14-
name: 'Upcoming Events',
15-
filterOrSortFn: getUpcomingEvents,
16-
},
17-
{
18-
id: 'all-events',
19-
name: 'All Events',
20-
filterOrSortFn: sortEventsDesc,
21-
},
22-
{
23-
id: 'past-events',
24-
name: 'Past Events',
25-
filterOrSortFn: getPastEvents,
26-
},
30+
upcomingEventsConfig,
31+
allEventsConfig,
32+
pastEventsConfig,
2733
] as const satisfies ReadonlyArray<EntryViewConfig<Event>>
34+
35+
export function getDefaultViewConfig(events: Array<Event>) {
36+
const upcomingEvents = getUpcomingEvents(events)
37+
return upcomingEvents.length === 0 ? allEventsConfig : upcomingEventsConfig
38+
}

0 commit comments

Comments
 (0)