Skip to content

Commit

Permalink
feat: isSelected 상탯값 추가하여 값 변경되었을 때만 헤더 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
anyl92 committed Sep 1, 2023
1 parent 3803796 commit 170768f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { useEffect, useState } from 'react'
import { useIssueListContext } from '../../hooks/useIssueListContext'
import * as S from './Header.styled'

export default function Header() {
const { owner, repo } = useIssueListContext()
const { owner, repo, isSelected } = useIssueListContext()
const [headerOwner, setHeaderOwner] = useState<string>(owner)
const [headerRepo, setHeaderRepo] = useState<string>(repo)

useEffect(() => {
setHeaderOwner(owner)
setHeaderRepo(repo)
}, [isSelected])

return (
<S.Header>
<h1>
{owner} / {repo}
{headerOwner} / {headerRepo}
</h1>
</S.Header>
)
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/useIssue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const useIssue = () => {
const [isLoading, setIsLoading] = useState<boolean>(false)
const [pageNo, setpageNo] = useState<number>(1)
const [isPageEnd, setIsPageEnd] = useState(false)
const [isSelected, setIsSelected] = useState<boolean>(false)

const filterPureIssue = (data: IssueDTO[]) => data.filter((issue) => !issue.pull_request)
const updateIssueList = (newData: IssueDTO[]) => {
Expand Down Expand Up @@ -43,6 +44,8 @@ const useIssue = () => {
getIssueList(filterPureIssue(res.data))
}
setpageNo(pageNo + 1)

setIsSelected(mode === 'select')
return
}
throw Error
Expand Down Expand Up @@ -73,6 +76,7 @@ const useIssue = () => {
isLoading,
setIsLoading,
isPageEnd,
isSelected,
getIssuesApiCall,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/store/IssuesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IssuesContextType {
isLoading: boolean
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>
isPageEnd: boolean
isSelected: boolean
getIssuesApiCall: (mode: string) => Promise<void>
}

Expand Down

0 comments on commit 170768f

Please sign in to comment.