Skip to content

Commit

Permalink
Update accounts map after successful autocomplete request
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Jul 12, 2024
1 parent 9e7269b commit 2baace7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.134.0] - Not released
### Fixed
- Autocomplete menu did not update properly after the server autocomplete
response.

## [1.133.0] - 2024-07-04
### Added
Expand Down
8 changes: 6 additions & 2 deletions src/components/autocomplete/selector.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDispatch, useStore } from 'react-redux';
import { useDispatch, useSelector, useStore } from 'react-redux';
import cn from 'classnames';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useEvent } from 'react-use-event-hook';
Expand Down Expand Up @@ -105,6 +105,7 @@ function Item({ account, match, isCurrent, onClick }) {
}

function useAccountsMap({ context }) {
const lastAutocompleteQuery = useSelector((state) => state.lastAutocompleteQuery);
const store = useStore();
const post = usePost();

Expand All @@ -119,6 +120,9 @@ function useAccountsMap({ context }) {
}, [context, post, store]);

return useMemo(() => {
// We need to refresh this on lastAutocompleteQuery change
lastAutocompleteQuery;

const state = store.getState();
const accountsMap = new Map();
let rankedNames;
Expand Down Expand Up @@ -160,5 +164,5 @@ function useAccountsMap({ context }) {
}

return [[...accountsMap.keys()], accountsMap, compare];
}, [context, post, store]);
}, [context, post, store, lastAutocompleteQuery]);
}
7 changes: 7 additions & 0 deletions src/redux/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2184,3 +2184,10 @@ export { userStatsStatus, userStats } from './reducers/dynamic-user-stats';
export { translationStates, translationResults } from './reducers/translation';

export { unlockedCommentStates, unlockedComments } from './reducers/unlocked-comments';

export function lastAutocompleteQuery(state = '', action) {
if (action.type === response(ActionTypes.GET_MATCHED_USERS)) {
return action.request.query;
}
return state;
}

0 comments on commit 2baace7

Please sign in to comment.