Skip to content

Commit

Permalink
Merge branch 'develop' into pause-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
dzonidoo committed Jun 11, 2024
2 parents 319acb8 + 08ab4ff commit 32afcbe
Show file tree
Hide file tree
Showing 79 changed files with 2,608 additions and 1,955 deletions.
19 changes: 15 additions & 4 deletions assets/agenda/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
IAgendaItem,
IAgendaListGroup,
IAgendaState,
AgendaThunkAction, ISearchState,
AgendaThunkAction,
ISearchState,
ISearchParams,
} from 'interfaces';
import server from 'server';
import analytics from 'analytics';
Expand Down Expand Up @@ -235,6 +237,7 @@ function search(state: IAgendaState, fetchFrom: number): Promise<IRestApiRespons
} = getAgendaSearchParamsFromState(state);

const params: any = {
sort: searchParams.sortQuery == null ? null : searchParams.sortQuery,
q: searchParams.query,
bookmarks: state.bookmarks && state.user,
navigation: getNavigationUrlParam(searchParams.navigation, true, false),
Expand Down Expand Up @@ -283,7 +286,7 @@ export function fetchItems(): AgendaThunkAction {

interface AgendaSearchParams {
itemType: IAgendaState['agenda']['itemType'];
searchParams: any;
searchParams: ISearchParams;
featured: boolean;
fromDate?: string;
toDate?: string;
Expand Down Expand Up @@ -329,10 +332,12 @@ function getAgendaSearchParamsFromState(state: IAgendaState): AgendaSearchParams

function setListGroupsAndLoadHiddenItems(items: Array<IAgendaItem>, next?: boolean): AgendaThunkAction {
return (dispatch, getState) => {

// If there are groups shown, then load the hidden items for those groups
const state = getState();
const {activeGrouping, featuredOnly} = state.agenda;
const {fromDate, toDate} = getAgendaSearchParamsFromState(state);
const {fromDate, toDate, searchParams} = getAgendaSearchParamsFromState(state);

let minDate: moment.Moment | undefined;
let maxDate: moment.Moment | undefined;

Expand Down Expand Up @@ -361,7 +366,13 @@ function setListGroupsAndLoadHiddenItems(items: Array<IAgendaItem>, next?: boole
}
}

const groups = groupItems(items, minDate, maxDate, activeGrouping, featuredOnly);
const groups: Array<IAgendaListGroup> = (searchParams.sortQuery ?? '_score') === '_score' ?
groupItems(items, minDate, maxDate, activeGrouping, featuredOnly) :
[{
date: '',
items: items.map((item) => item._id),
hiddenItems: [],
}];

next === true ?
dispatch(addItemsToListGroups(groups)) :
Expand Down
17 changes: 6 additions & 11 deletions assets/agenda/components/AgendaApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import {connect} from 'react-redux';
import {get, isEmpty} from 'lodash';

import {ISearchSortValue} from 'interfaces';
import {getItemFromArray, gettext} from 'utils';

Check warning on line 8 in assets/agenda/components/AgendaApp.tsx

View workflow job for this annotation

GitHub Actions / client

'getItemFromArray' is defined but never used
import {noNavigationSelected} from 'search/utils';

Expand All @@ -22,6 +23,7 @@ import {
setView,
setQuery,
saveMyTopic,
setSortQuery,
} from 'search/actions';

import {
Expand Down Expand Up @@ -124,25 +126,15 @@ class AgendaApp extends SearchBase<any> {
!this.props.featuredOnly;
let showTotalItems = false;
let showTotalLabel = false;
let totalItemsLabel: any;

if (get(this.props, 'activeTopic.label')) {
totalItemsLabel = this.props.activeTopic.label;
showTotalItems = showTotalLabel = true;
} else if (numNavigations === 1) {
totalItemsLabel = get(getItemFromArray(
this.props.searchParams.navigation[0],
this.props.navigations
), 'name') || '';
showTotalItems = showTotalLabel = true;
} else if (numNavigations > 1) {
totalItemsLabel = gettext('Custom View');
showTotalItems = showTotalLabel = true;
} else if (this.props.showSaveTopic) {
showTotalItems = showTotalLabel = true;
if (this.props.bookmarks && get(this.props, 'searchParams.query.length', 0) > 0) {
totalItemsLabel = this.props.searchParams.query;
}
}

const showFilters = Object.values(this.props.searchParams ?? {}).find((val) => val != null) != null ||
Expand Down Expand Up @@ -253,12 +245,14 @@ class AgendaApp extends SearchBase<any> {
this.props.toggleDropdownFilter('itemType', null);
}}
totalItems={this.props.totalItems}
totalItemsLabel={totalItemsLabel}
saveMyTopic={saveMyTopic}
activeTopic={this.props.activeTopic}
topicType="agenda"
refresh={this.props.fetchItems}
setQuery={this.props.setQuery}
setSortQuery={this.props.setSortQuery}
showSortDropdown={true}
defaultSortValue="_score"
/>
)
}
Expand Down Expand Up @@ -431,6 +425,7 @@ const mapDispatchToProps = (dispatch: any) => ({
requestCoverage: (item: any, message: any) => dispatch(requestCoverage(item, message)),
toggleFeaturedFilter: (fetch: any) => dispatch(toggleFeaturedFilter(fetch)),
setQuery: (query: any) => dispatch(setQuery(query)),
setSortQuery: (query: ISearchSortValue) => dispatch(setSortQuery(query)),
});

const component: React.ComponentType<any> = connect(mapStateToProps, mapDispatchToProps)(AgendaApp);
Expand Down
61 changes: 31 additions & 30 deletions assets/agenda/components/AgendaItemTimeUpdater.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import {get} from 'lodash';
import classNames from 'classnames';

import {IAgendaItem} from 'interfaces';
import {bem} from 'ui/utils';
import {gettext} from 'utils';

class AgendaItemTimeUpdater extends React.Component<any, any> {
static propTypes: any;
static defaultProps: any;
interface IProps {
item: IAgendaItem;
borderRight?: boolean;
alignCenter?: boolean;
}

interface IState {
timeText: string;
}

class AgendaItemTimeUpdater extends React.Component<IProps, IState> {
interval: number;
timerIntervalId: any;
timerIntervalId: number;

constructor(props: any) {
super(props);
Expand All @@ -24,22 +30,24 @@ class AgendaItemTimeUpdater extends React.Component<any, any> {
this.updateState = this.updateState.bind(this);
}

componentWillMount() {
componentDidMount() {
this.activateTimer(this.props.item);
}

componentWillReceiveProps(nextProps: any) {
if (get(this.props, 'item._created') !== get(nextProps, 'item._created') ||
get(this.props, 'item._updated') !== get(nextProps, 'item._updated')) {
this.activateTimer(nextProps.item);
componentDidUpdate(prevProps: Readonly<IProps>) {
if (
this.props.item._created !== prevProps.item._created ||
this.props.item._updated !== prevProps.item._updated
) {
this.activateTimer(this.props.item);
}
}

componentWillUnmount() {
this.deactivateTimer();
}

activateTimer(item: any) {
activateTimer(item: IAgendaItem) {
// Deactivate if a timer already exits
this.deactivateTimer();

Expand All @@ -51,7 +59,7 @@ class AgendaItemTimeUpdater extends React.Component<any, any> {
this.updateState(item, false);

// timer set for minute interval
this.timerIntervalId = setInterval(this.updateState, 60000, item);
this.timerIntervalId = window.setInterval(this.updateState, 60000, item);
}

deactivateTimer() {
Expand All @@ -67,14 +75,14 @@ class AgendaItemTimeUpdater extends React.Component<any, any> {
moment().diff(moment(item._updated), 'minutes') >= this.interval);
}

updateState(item: any, checkPastTime: any = true) {
updateState(item: IAgendaItem, checkPastTime = true) {
if (checkPastTime && this.isItemPastTime(item)) {
this.deactivateTimer();
return;
}

const created = moment(item._created);
const updated = moment(item._updated);
const created = moment(item.firstcreated);
const updated = moment(item.versioncreated);
const createdDiff = moment().diff(created, 'minutes');
const updatedDiff = moment().diff(updated, 'minutes');

Expand All @@ -97,13 +105,17 @@ class AgendaItemTimeUpdater extends React.Component<any, any> {
}

render() {
if (get(this.state.timeText, 'length', 0) <= 0) {
if (this.state.timeText.length === 0) {
return null;
}

const className = classNames(
bem('wire-articles__item', 'meta-time', {'border-right': this.props.borderRight}),
{'align-self-center': this.props.alignCenter}
bem(
'wire-articles__item',
'meta-time',
{'border-right': this.props.borderRight === true}
),
{'align-self-center': this.props.alignCenter === true}
);

return(
Expand All @@ -114,15 +126,4 @@ class AgendaItemTimeUpdater extends React.Component<any, any> {
}
}

AgendaItemTimeUpdater.propTypes = {
item: PropTypes.object,
borderRight: PropTypes.bool,
alignCenter: PropTypes.bool,
};

AgendaItemTimeUpdater.defaultProps = {
alignCenter: false,
borderRight: false,
};

export default AgendaItemTimeUpdater;
53 changes: 29 additions & 24 deletions assets/agenda/components/AgendaList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ class AgendaList extends React.Component<IProps, IState> {

render() {
const lastGroupWithItems = this.props.groupedItems.findLastIndex((group) => group.items.length > 0);
const groupedItems = this.props.groupedItems.slice(0, lastGroupWithItems + 1);

return (
<div
className={classNames('wire-articles wire-articles--list', {
Expand All @@ -429,30 +431,33 @@ class AgendaList extends React.Component<IProps, IState> {
}}
onScroll={this.props.onScroll}
>
{this.props.groupedItems.filter((group, index) => lastGroupWithItems >= index).map((group) => (
<React.Fragment key={group.date}>
<div className='wire-articles__header' key={`${group.date}header`}>
{this.getListGroupDate(group)}
</div>

{group.hiddenItems.length === 0 ? null : (
<AgendaListGroupHeader
group={group.date}
itemIds={group.hiddenItems}
itemsById={this.props.itemsById}
itemsShown={this.props.hiddenGroupsShown[group.date] === true}
toggleHideItems={this.props.toggleHiddenGroupItems}
/>
)}

{this.props.hiddenGroupsShown[group.date] !== true ?
null :
this.renderGroupItems(group, true)
}
{this.renderGroupItems(group, false)}
</React.Fragment>
))}
{!this.props.groupedItems.length &&
{groupedItems.length === 1 ?
this.renderGroupItems(groupedItems[0], false) :
groupedItems.map((group) => (
<React.Fragment key={group.date}>
<div className='wire-articles__header' key={`${group.date}header`}>
{this.getListGroupDate(group)}
</div>

{group.hiddenItems.length === 0 ? null : (
<AgendaListGroupHeader
group={group.date}
itemIds={group.hiddenItems}
itemsById={this.props.itemsById}
itemsShown={this.props.hiddenGroupsShown[group.date] === true}
toggleHideItems={this.props.toggleHiddenGroupItems}
/>
)}

{this.props.hiddenGroupsShown[group.date] !== true ?
null :
this.renderGroupItems(group, true)
}
{this.renderGroupItems(group, false)}
</React.Fragment>
))
}
{!groupedItems.length &&
<div className="wire-articles__item-wrap col-12">
<div className="alert alert-secondary">{gettext('No items found.')}</div>
</div>
Expand Down
Loading

0 comments on commit 32afcbe

Please sign in to comment.