Skip to content

Commit

Permalink
Merge branch 'release' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Dec 4, 2024
2 parents 69a8d1e + d3077ff commit 0f02785
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Experimental

## [1.136.2] - 2024-12-04
### Changed
- The autocomplete is now queries server during typing. It allows to show exact
matches of private users and groups.

## [1.136.0] - 2024-11-08
### Changed
- The advanced search form is refactored to support the new search operators.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactive-pepyatka",
"version": "1.136.1",
"version": "1.136.2",
"description": "",
"main": "index.js",
"dependencies": {
Expand Down
33 changes: 20 additions & 13 deletions src/components/autocomplete/selector.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useDispatch, useSelector, useStore } from 'react-redux';
import { Link } from 'react-router';
import cn from 'classnames';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useEvent } from 'react-use-event-hook';
import { faExternalLinkAlt, faUserFriends } from '@fortawesome/free-solid-svg-icons';
import { Finder } from '../../utils/sparse-match';
Expand All @@ -23,19 +23,8 @@ import {

export function Selector({ query, events, onSelect, context, localLinks = false }) {
query = query.toLowerCase();
const dispatch = useDispatch();
const [usernames, accountsMap, compare] = useAccountsMap({ context });

// Request all users/groups when query longer than 2 chars
const lastQuery = useRef('');
useEffect(() => {
const lc = lastQuery.current;
if (query.length < 2 || (lc && query.slice(0, lc.length) === lc)) {
return;
}
lastQuery.current = query;
dispatch(getMatchedUsers(query));
}, [dispatch, query]);
useUsersRequest(query);

const matches = useMemo(() => {
const compareWithExact = (a, b) => {
Expand Down Expand Up @@ -196,3 +185,21 @@ function useAccountsMap({ context }) {
return [[...accountsMap.keys()], accountsMap, compare];
}, [context, post, store, lastAutocompleteQuery]);
}

function useUsersRequest(query) {
const dispatch = useDispatch();

useEffect(() => {
if (query.length < 2) {
return;
}

const abortController = new AbortController();
const { signal } = abortController;

const t = setTimeout(() => dispatch(getMatchedUsers(query, { signal })), 500);
signal.addEventListener('abort', () => clearTimeout(t));

return () => abortController.abort();
}, [query, dispatch]);
}
2 changes: 1 addition & 1 deletion src/components/footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Footer({ short }) {
return (
<footer className="footer">
<p role="navigation">
&copy; FreeFeed 1.136.1-beta (Nov 10, 2024)
&copy; FreeFeed 1.136.2-beta (Dec 4, 2024)
<br />
<Link to="/about">About</Link>
{' | '}
Expand Down
3 changes: 2 additions & 1 deletion src/redux/action-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,11 @@ export function unlockComment(id) {
};
}

export function getMatchedUsers(query) {
export function getMatchedUsers(query, fetchOptions) {
return {
type: ActionTypes.GET_MATCHED_USERS,
apiRequest: Api.getMatchedUsers,
payload: { query },
fetchOptions,
};
}
4 changes: 2 additions & 2 deletions src/redux/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ export const apiMiddleware = (store) => (next) => async (action) => {

//dispatch request begin action
//clean apiRequest to not get caught by this middleware
store.dispatch({ ...action, type: request(action.type), apiRequest: null });
store.dispatch({ ...action, type: request(action.type), apiRequest: null, fetchOptions: null });
try {
const apiResponse = await action.apiRequest(action.payload);
const apiResponse = await action.apiRequest(action.payload, action.fetchOptions);
const obj = await apiResponse.json();

if (apiResponse.status >= 200 && apiResponse.status < 300) {
Expand Down
10 changes: 5 additions & 5 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ export function notifyOfAllComments({ postId, enabled }) {
);
}

export function getMatchedUsers({ query }) {
return fetch(
`${apiPrefix}/users/sparseMatches?qs=${encodeURIComponent(query)}`,
getRequestOptions(),
);
export function getMatchedUsers({ query }, fetchOptions = {}) {
return fetch(`${apiPrefix}/users/sparseMatches?qs=${encodeURIComponent(query)}`, {
...getRequestOptions(),
...fetchOptions,
});
}

0 comments on commit 0f02785

Please sign in to comment.