-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat: addgroup state추가
- Loading branch information
Showing
16 changed files
with
475 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 61 additions & 22 deletions
83
src/components/AddGroup/AddGroupMembername/membernameList/membernameList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,78 @@ | ||
import { useState } from 'react'; | ||
import React, { useState } from 'react'; | ||
import * as S from './Styles'; | ||
import { useRecoilState } from 'recoil'; | ||
import { namesState } from '../../state'; // Recoil 상태가 정의된 파일을 import | ||
|
||
interface MembernameCreateProps { | ||
addName: (name: string) => void; | ||
} | ||
|
||
const MembernameCreate: React.FC<MembernameCreateProps> = ({ addName }) => { | ||
const [newName, setNewName] = useState<string>(''); /*상태타입 정의 */ | ||
|
||
const handleAddName = () => { | ||
if (newName.trim() !== '') { | ||
addName(newName.trim()); /*새로운 이름 추가함수 호출 */ | ||
setNewName(''); /*입력 필드 초기화 */ | ||
} | ||
}; | ||
|
||
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
handleAddName(); // Enter 키로 이름 추가 | ||
} | ||
}; | ||
|
||
function MembernameCreate() { | ||
return ( | ||
<S.nameCreatelayout> | ||
<S.MemberInput /> | ||
<S.inputname type="text" placeholder="이름"></S.inputname> | ||
<S.inputplus /> | ||
<S.inputname | ||
type="text" | ||
placeholder="이름" | ||
value={newName} | ||
onChange={(e) => setNewName(e.target.value)} | ||
onKeyDown={handleKeyDown} | ||
/> | ||
<S.inputplus onClick={handleAddName}>추가</S.inputplus> | ||
</S.nameCreatelayout> | ||
); | ||
} | ||
}; | ||
|
||
const MembernameList: React.FC = () => { | ||
const [names, setNames] = useRecoilState(namesState); // Recoil 상태 사용 | ||
|
||
const addName = (name: string) => { | ||
const newNames = [...names, name]; | ||
setNames(newNames); | ||
console.log(`이름: ${newNames.join(', ')}`); // 콘솔에 이름 리스트 출력 | ||
}; | ||
|
||
const removeName = (index: number) => { | ||
const newNames = names.filter((_, i) => i !== index); /*이름 제거*/ | ||
setNames(newNames); | ||
console.log(`이름: ${newNames.join(', ')}`); // 콘솔에 이름 리스트 출력 | ||
}; | ||
|
||
const membernameList = () => { | ||
return ( | ||
<S.nameLayout> | ||
<S.nameFolder /> | ||
<S.nameList> | ||
<S.nameContainer> | ||
<S.NowImportName /> | ||
<S.name>황지원</S.name> | ||
<S.nameButton>ⓧ</S.nameButton> | ||
</S.nameContainer> | ||
<S.nameContainer> | ||
<S.NowImportName /> | ||
<S.name>박을순</S.name> | ||
<S.nameButton>ⓧ</S.nameButton> | ||
</S.nameContainer> | ||
<S.nameContainer> | ||
<S.NowImportName /> | ||
<S.name>김똘똘</S.name> | ||
</S.nameContainer> | ||
{names.map((name, index) => ( | ||
<S.nameContainer key={index}> | ||
<S.NowImportName /> | ||
<S.name>{name}</S.name> | ||
<S.nameButton | ||
className="nameButton" | ||
onClick={() => removeName(index)} | ||
> | ||
ⓧ | ||
</S.nameButton> | ||
</S.nameContainer> | ||
))} | ||
</S.nameList> | ||
<MembernameCreate /> | ||
<MembernameCreate addName={addName} /> | ||
</S.nameLayout> | ||
); | ||
}; | ||
|
||
export default membernameList; | ||
export default MembernameList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.