Skip to content

Commit

Permalink
fix(events): remove dateRange workarounds and sort by time
Browse files Browse the repository at this point in the history
- with optimizing the main-server we do not need to reduce results with
  date range
- main-server is now sorting with time as well

SVAK-135
  • Loading branch information
donni106 committed Nov 27, 2024
1 parent b82fc00 commit 29394a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
8 changes: 0 additions & 8 deletions src/components/EventList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FlashList } from '@shopify/flash-list';
import _sortBy from 'lodash/sortBy';
import PropTypes from 'prop-types';
import React, { useEffect, useState } from 'react';

Expand All @@ -25,13 +24,6 @@ const sectionData = (data) => {
}
});

for (const dateKey in grouped) {
grouped[dateKey] = _sortBy(
grouped[dateKey],
(item) => item?.params?.details?.date?.timeFrom || item?.params?.details?.date?.timeTo
);
}

return grouped;
};

Expand Down
10 changes: 4 additions & 6 deletions src/components/screens/EventRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
EmptyMessage,
ListComponent,
LoadingContainer,
OptionToggle,
REFRESH_CALENDAR,
RegularText,
SafeAreaViewFlex,
Expand Down Expand Up @@ -50,8 +49,6 @@ const hasFilterSelection = (isLocationFilter, queryVariables) => {
};

const today = moment().format('YYYY-MM-DD');
// we need to set a date range to correctly sort the results by list date, so we set it far in the future
const todayIn10Years = moment().add(10, 'years').format('YYYY-MM-DD');

/* eslint-disable complexity */
/* NOTE: we need to check a lot for presence, so this is that complex */
Expand All @@ -65,9 +62,10 @@ export const EventRecords = ({ navigation, route }) => {
const { calendarToggle = false } = settings;
const { eventListIntro } = sections;
const query = route.params?.query ?? '';
const initialQueryVariables = route.params?.queryVariables || {};
const [queryVariables, setQueryVariables] = useState({
...(route.params?.queryVariables || {}),
dateRange: (route.params?.queryVariables || {}).dateRange || [today, todayIn10Years]
...initialQueryVariables,
...resourceFiltersState[query]
});
const [refreshing, setRefreshing] = useState(false);
const [showCalendar, setShowCalendar] = useState(false);
Expand Down Expand Up @@ -186,7 +184,7 @@ export const EventRecords = ({ navigation, route }) => {
});
} else {
setQueryVariables((prevQueryVariables) => {
return { ...prevQueryVariables, dateRange: [today, todayIn10Years], refetchDate: true };
return { ...prevQueryVariables, refetchDate: true };
});
}

Expand Down
14 changes: 8 additions & 6 deletions src/components/widgets/EventWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ import { DefaultWidget } from './DefaultWidget';
const { ROOT_ROUTE_NAMES } = consts;

const today = moment().format('YYYY-MM-DD');
// we need to set a date range to correctly sort the results by list date, so we set it far in the future
const todayIn10Years = moment().add(10, 'years').format('YYYY-MM-DD');

export const EventWidget = ({ text, additionalProps }: WidgetProps) => {
const navigation = useNavigation();
const { globalSettings } = useContext(SettingsContext);
const { deprecated = {}, hdvt = {} } = globalSettings;
const { events: showVolunteerEvents = false } = hdvt as { events?: boolean };
const [queryVariables] = useState<{ dateRange?: string[]; order?: string }>({
dateRange: [today, additionalProps?.noFilterByDailyEvents ? todayIn10Years : today],
order: 'listDate_ASC'
});
const [queryVariables] = useState<{ dateRange?: string[]; order?: string }>(
additionalProps?.noFilterByDailyEvents
? { order: 'listDate_ASC' }
: {
dateRange: [today, today],
order: 'listDate_ASC'
}
);

const {
data,
Expand Down
4 changes: 1 addition & 3 deletions src/screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import { ScreenName } from '../types';
const { MATOMO_TRACKING, ROOT_ROUTE_NAMES } = consts;

const today = moment().format('YYYY-MM-DD');
// we need to set a date range to correctly sort the results by list date, so we set it far in the future
const todayIn10Years = moment().add(10, 'years').format('YYYY-MM-DD');

const renderItem = ({ item }) => {
const {
Expand Down Expand Up @@ -310,7 +308,7 @@ export const HomeScreen = ({ navigation, route }) => {
navigate: 'EVENT_RECORDS_INDEX',
navigation,
query: QUERY_TYPES.EVENT_RECORDS,
queryVariables: { take: 3, order: 'listDate_ASC', dateRange: [today, todayIn10Years] },
queryVariables: { take: 3, order: 'listDate_ASC' },
showData: showEvents,
showVolunteerEvents,
title: headlineEvents
Expand Down

0 comments on commit 29394a7

Please sign in to comment.