Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

QMAPS-2532 don't mix favorites with hisory in suggest #1297

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/adapters/suggest_sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ export function suggestResults(
// - get all the history items
// - ignore the items that are already present in the favourites list
// - keep the N first items (where N = maxHistoryItems)
const historyItems =
maxHistoryItems > 0
? getHistoryItems(term, { withIntentions: withCategories })
.slice(0, maxHistoryItems)
.map(item => {
item._suggestSource = 'history';
if (favoriteItems.find(favorite => favorite.id === item.id)) {
item._isFavorite = true;
}
return item;
})
: [];
let historyItems =
maxHistoryItems > 0 ? getHistoryItems(term, { withIntentions: withCategories }) : [];

if (term !== '') {
historyItems = historyItems.filter(
item => !favoriteItems.find(favorite => favorite.id === item.id)
);
}
historyItems = historyItems.slice(0, maxHistoryItems).map(item => {
item._suggestSource = 'history';
return item;
});

// Field focused and empty: get history + favourite items, but no favourites if history items are present
if (term === '') {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/SuggestItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const SuggestItem = ({ item }) => {
const props = {};
const variants = [];
const isHistory = item._suggestSource === 'history';
const isFavorite = item instanceof PoiStore || item._isFavorite === true;
const isFavorite = item instanceof PoiStore === true;
if (isFavorite) {
variants.push('favorite');
} else if (isHistory) {
Expand Down