Skip to content

Commit 98674fe

Browse files
committed
fix: handle searching for undefined spaces
1 parent 93b1a07 commit 98674fe

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Home.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
22
import { connect } from 'react-redux';
33
import PropTypes from 'prop-types';
44
import { withTranslation } from 'react-i18next';
5-
import { Set, List } from 'immutable';
5+
import { List } from 'immutable';
66
import { withRouter } from 'react-router';
77
import classNames from 'classnames';
88
import { withStyles } from '@material-ui/core/styles';
@@ -66,7 +66,7 @@ class Home extends Component {
6666
history: PropTypes.shape({
6767
replace: PropTypes.func.isRequired,
6868
}).isRequired,
69-
spaces: PropTypes.instanceOf(Set).isRequired,
69+
spaces: PropTypes.instanceOf(List).isRequired,
7070
activity: PropTypes.bool,
7171
favoriteSpaces: PropTypes.instanceOf(List).isRequired,
7272
recentSpaces: PropTypes.instanceOf(List).isRequired,
@@ -80,8 +80,8 @@ class Home extends Component {
8080
};
8181

8282
state = {
83-
filteredRecentSpaces: Set(),
84-
filteredFavoriteSpaces: Set(),
83+
filteredRecentSpaces: List(),
84+
filteredFavoriteSpaces: List(),
8585
};
8686

8787
componentDidMount() {
@@ -125,9 +125,13 @@ class Home extends Component {
125125

126126
filterSpaces = spaces => {
127127
const { searchQuery, spaces: originalSpaces } = this.props;
128-
let filteredSpaces = spaces.map(id =>
129-
originalSpaces.find(({ id: spaceId }) => id === spaceId)
130-
);
128+
// get space content by id
129+
let filteredSpaces = spaces
130+
.map(id => originalSpaces.find(({ id: spaceId }) => id === spaceId))
131+
// remove undefined space
132+
// this case can happen if originalSpaces is updated before spaces
133+
.filter(space => space);
134+
131135
filteredSpaces = searchSpacesByQuery(filteredSpaces, searchQuery);
132136
return filteredSpaces;
133137
};

0 commit comments

Comments
 (0)