mirror of
https://github.com/strapi/strapi.git
synced 2025-08-02 13:58:18 +00:00
Search refacto ip
This commit is contained in:
parent
c06b0d9031
commit
1a1809006b
@ -15,7 +15,8 @@ import InputSearchLi from '../InputSearchLi';
|
|||||||
import { Addon, List, Wrapper } from './Components';
|
import { Addon, List, Wrapper } from './Components';
|
||||||
|
|
||||||
function InputSearchContainer({
|
function InputSearchContainer({
|
||||||
didDeleteUser,
|
didFetchUsers,
|
||||||
|
getUser,
|
||||||
label,
|
label,
|
||||||
name,
|
name,
|
||||||
onClickAdd,
|
onClickAdd,
|
||||||
@ -23,27 +24,50 @@ function InputSearchContainer({
|
|||||||
values,
|
values,
|
||||||
}) {
|
}) {
|
||||||
const searchInput = useRef(null);
|
const searchInput = useRef(null);
|
||||||
console.log(values);
|
|
||||||
|
|
||||||
const [filteredUsers, setFilteredUsers] = useState(values);
|
const [filteredUsers, setFilteredUsers] = useState(values);
|
||||||
const [isAdding, setIsAdding] = useState(false);
|
const [isAdding, setIsAdding] = useState(false);
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
const [isFocused, setIsFocused] = useState(false);
|
||||||
const [errors, setErrors] = useState([]);
|
const [errors, setErrors] = useState([]);
|
||||||
|
const [users, setUsers] = useState(values);
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (values !== filteredUsers) {
|
if (values !== filteredUsers) {
|
||||||
|
setUsers(values);
|
||||||
setFilteredUsers(values);
|
setFilteredUsers(values);
|
||||||
}
|
}
|
||||||
}, [values]);
|
}, [values]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (users !== filteredUsers) {
|
||||||
|
setFilteredUsers(users);
|
||||||
|
setIsAdding(true);
|
||||||
|
}
|
||||||
|
}, [didFetchUsers]);
|
||||||
|
|
||||||
const handleBlur = () => setIsFocused(prev => !prev);
|
const handleBlur = () => setIsFocused(prev => !prev);
|
||||||
|
|
||||||
const handleChange = () => {};
|
const handleChange = ({ target: value }) => {
|
||||||
|
const filteredUsers = isEmpty(value)
|
||||||
|
? users
|
||||||
|
: users.filter(user => includes(toLower(user.name), toLower(value)));
|
||||||
|
|
||||||
|
if (isEmpty(filteredUsers) && !isEmpty(value)) {
|
||||||
|
getUser(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEmpty(value)) {
|
||||||
|
setValue(value);
|
||||||
|
setFilteredUsers(values);
|
||||||
|
setIsAdding(false);
|
||||||
|
setUsers(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(value);
|
||||||
|
setFilteredUsers(filteredUsers);
|
||||||
|
};
|
||||||
|
|
||||||
const handleClick = item => {
|
const handleClick = item => {
|
||||||
console.log(item);
|
|
||||||
console.log(isAdding);
|
|
||||||
if (isAdding) {
|
if (isAdding) {
|
||||||
const id = has(item, '_id') ? '_id' : 'id';
|
const id = has(item, '_id') ? '_id' : 'id';
|
||||||
const users = values;
|
const users = values;
|
||||||
@ -115,7 +139,6 @@ InputSearchContainer.defaultProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
InputSearchContainer.propTypes = {
|
InputSearchContainer.propTypes = {
|
||||||
didDeleteUser: PropTypes.bool.isRequired,
|
|
||||||
didFetchUsers: PropTypes.bool.isRequired,
|
didFetchUsers: PropTypes.bool.isRequired,
|
||||||
didGetUsers: PropTypes.bool.isRequired,
|
didGetUsers: PropTypes.bool.isRequired,
|
||||||
getUser: PropTypes.func.isRequired,
|
getUser: PropTypes.func.isRequired,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user