Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#230/ 검색 기능 수정 및 검색 페이지 최적화 #231

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
62 changes: 30 additions & 32 deletions src/feature/ttabong/TTaBongModal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import React, { useState, useEffect, useCallback } from 'react';
import * as S from './style';
import Modal, { useModal } from '../../../components/Modal';
import Modal from '../../../components/Modal';
import BaseCardContainer from '../../../components/BaseCardContainer';
import InputForm from '../../../components/InputForm';
import UserInfoItem from '../../../components/UserInfoItem';
import theme from '../../../commons/style/themes';
import useForm from '../../../hooks/useForm';
import { getAllUsers, searchUser } from '../../../apis';
import { getAllUsers } from '../../../apis';
import { useAuthContext } from '../../../contexts/UserProvider';

const TTaBongModal = ({ checkedUsers, setCheckedUsers, modalProps }) => {
const TTaBongModal = ({ setCheckedUsers, modalProps }) => {
const { isModalOn, backgroundRef, handleCloseModal } = modalProps;

const { authUser } = useAuthContext();
Expand All @@ -31,35 +28,38 @@ const TTaBongModal = ({ checkedUsers, setCheckedUsers, modalProps }) => {
fetchAllUsers();
}, []);

const handleSearchSubmit = (e) => {
e.preventDefault();
const handleSearchSubmit = useCallback(
(e) => {
const keyword = e;

const keyword = e.target.search.value;

setUsers(
users.map((user) =>
user.fullName.startsWith(keyword)
? { ...user, searched: true }
: { ...user, searched: false },
),
);
};

const handleUserCheck = (e, userId) => {
e.preventDefault(); // 5명까지만
setUsers(
users.map((user) =>
user.fullName.indexOf(keyword) >= 0
? { ...user, searched: true }
: { ...user, searched: false },
),
);
},
[users],
);

const newUsers = users.map((user) =>
user._id !== userId ? user : { ...user, checked: !user.checked },
);
const handleUserCheck = useCallback(
(e, userId) => {
e.preventDefault();

const newCheckdUsers = newUsers.filter((user) => user.checked);
const newUsers = users.map((user) =>
user._id !== userId ? user : { ...user, checked: !user.checked },
);

if (newCheckdUsers.length > 5) return;
const newCheckdUsers = newUsers.filter((user) => user.checked);

setUsers(newUsers);
if (newCheckdUsers.length > 5) return;

setCheckedUsers(newCheckdUsers);
};
setUsers(newUsers);
setCheckedUsers(newCheckdUsers);
},
[users],
);

return (
<Modal
Expand Down Expand Up @@ -104,6 +104,4 @@ const TTaBongModal = ({ checkedUsers, setCheckedUsers, modalProps }) => {
);
};

TTaBongModal.propTypes = {};

export default TTaBongModal;
4 changes: 2 additions & 2 deletions src/pages/SearchPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const SearchPage = () => {
const handleSubmit = (keyword) => {
const { users, posts } = items;

const searchedUsers = users.filter((user) =>
user.fullName.startsWith(keyword),
const searchedUsers = users.filter(
(user) => user.fullName.indexOf(keyword) >= 0,
);

const searchedPosts = posts.filter((post) =>
Expand Down