Skip to content

Commit

Permalink
Merge pull request #932 from peer-42seoul/1.0.3/C-MAIN/querystring-911
Browse files Browse the repository at this point in the history
[C-MAIN] 메인페이지 스터디/프로젝트 선택을 url 쿼리스트링에 저장 / 모집글 마감 시 지원버튼 텍스트 수정
  • Loading branch information
hyeon81 authored Feb 13, 2024
2 parents 23380bf + 3d0c5a8 commit aece636
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 24 deletions.
32 changes: 20 additions & 12 deletions src/app/panel/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import PwaInstallBanner from './PwaInstallBanner'
import MainBanner from '@/app/panel/main-page/MainBanner'
import Tutorial from '@/components/Tutorial'
import { MainPageTutorial } from '@/components/tutorialContent/MainPageTutorial'
import useHeaderStore from '@/states/useHeaderStore'
import NoDataDolphin from '@/components/NoDataDolphin'
import {
cardStyle,
Expand Down Expand Up @@ -61,12 +60,11 @@ export interface IDetailOption {
const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
const searchParams = useSearchParams()
const keyword = searchParams.get('keyword') ?? ''
const searchType = searchParams.get('type') === 'STUDY' ? 'STUDY' : 'PROJECT'
const searchType =
searchParams.get('type') === 'PROJECT' ? 'PROJECT' : 'STUDY'
const router = useRouter()
const [page, setPage] = useState<number>(1)
const [type, setType] = useState<ProjectType | undefined>(
keyword !== '' ? searchType : undefined,
) //'STUDY'
const [type, setType] = useState<ProjectType>(searchType) //'STUDY'
const [openOption, setOpenOption] = useState<boolean>(false)
const [sort, setSort] = useState<ProjectSort | undefined>(undefined) //'latest'
const [detailOption, setDetailOption] = useState<IDetailOption>({
Expand All @@ -85,15 +83,13 @@ const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
const [prevScrollHeight, setPrevScrollHeight] = useState<number | undefined>(
undefined,
)
const { headerTitle, setHeaderTitle } = useHeaderStore()
const [init, setInit] = useState<boolean>(true)

useEffect(() => {
if (keyword !== '') {
setHeaderTitle(keyword + ' 검색 결과')
setType(searchType)
setInit(false)
} else setHeaderTitle('')
}
}, [keyword, searchType])

/* page가 1이면 서버가 가져온 데이터(initData)로 렌더링 */
Expand All @@ -118,7 +114,12 @@ const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
}&tag=${detailOption.tag}`

const isInit =
page == 1 && !type && !sort && detailOption.isInit && keyword == '' && init
page == 1 &&
type === 'STUDY' &&
!sort &&
detailOption.isInit &&
keyword == '' &&
init

const { data: favoriteData } = useSWR<IFavorite[]>(
isInit && isLogin
Expand Down Expand Up @@ -186,6 +187,7 @@ const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
(newData?.last || initData?.last) ?? true, //isEnd
page,
)

const handleType = useCallback(
(value: ProjectType) => {
setType(value)
Expand All @@ -201,7 +203,7 @@ const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
tag: '',
})
setSort('latest')
router.push('/')
router.replace(`?type=${value}`)
},
[router],
)
Expand Down Expand Up @@ -251,7 +253,10 @@ const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
justifyContent={'space-between'}
my={'0.75rem'}
>
<Typography variant={'Body1'}>{headerTitle}</Typography>
<Stack direction="row" gap={'0.25rem'}>
<Typography variant={'Body1Emphasis'}>{keyword}</Typography>
<Typography variant={'Body1'}>검색 결과</Typography>
</Stack>
<SelectSort sort={sort} setSort={handleSort} />
</Stack>
)}
Expand Down Expand Up @@ -337,7 +342,10 @@ const MainPage = ({ initData }: { initData: IPagination<IPost[]> }) => {
justifyContent={'space-between'}
mb={'0.75rem'}
>
<Typography variant={'Body1'}>{headerTitle}</Typography>
<Stack direction="row" gap={'0.25rem'}>
<Typography variant={'Body1Emphasis'}>{keyword}</Typography>
<Typography variant={'Body1'}>검색 결과 </Typography>
</Stack>
<SelectSort sort={sort} setSort={handleSort} />
</Stack>
)}
Expand Down
14 changes: 11 additions & 3 deletions src/app/panel/layout-panel/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ const Header = ({ pathname }: { pathname?: string }) => {
const [title, setTitle] = useState('')
const searchParams = useSearchParams()
const keyword = searchParams.get('keyword') ?? ''
const type = searchParams.get('type') ?? 'STUDY'
const regex = /^\/recruit\/\d+\/edit$/

useEffect(() => {
if (!pathname) return setTitle('')
if (pathname === '/') {
setTitle('메인')
if (keyword !== '') setTitle('검색 결과')
else setTitle('메인')
} else if (pathname.startsWith('/login')) {
setTitle('로그인')
} else if (pathname === '/recruit/write') {
Expand All @@ -67,7 +69,9 @@ const Header = ({ pathname }: { pathname?: string }) => {

// 타이틀만 보여주고 싶은 경우 (뒤로 가기 버튼이 보이지 않았으면 하는 경우)
const onlyTitle =
title === '마이페이지' || title === '나의 팀' || title === '로그인'
pathname?.startsWith('/my-page') ||
pathname?.startsWith('/team-list') ||
pathname?.startsWith('/login')

return (
<AppBar position="fixed" sx={mobileHeader}>
Expand All @@ -89,7 +93,11 @@ const Header = ({ pathname }: { pathname?: string }) => {
) : (
<Stack sx={style.mobileHeaderStack}>
<IconButton
onClick={() => router.back()}
onClick={() => {
if (pathname === '/' && keyword !== '') {
router.replace(`?type=${type}`)
} else router.back()
}}
sx={{
visibility: onlyTitle ? 'hidden' : 'visible',
}}
Expand Down
2 changes: 1 addition & 1 deletion src/app/panel/main-page/MainCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const MainCard = ({
mt={1}
direction={'row'}
sx={{
height: `${1.5 * tagMaxLine + 0.5}rem`,
height: `${1.5 * tagMaxLine + 0.25}rem`,
overflow: 'auto',
flexWrap: 'wrap',
'&::-webkit-scrollbar': {
Expand Down
2 changes: 1 addition & 1 deletion src/app/panel/main-page/MainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ISearchOptionPanel {
openOption: boolean
setOpenOption: (value: boolean) => void
handleOption: (value: IDetailOption) => void
type: ProjectType | undefined
type: ProjectType
sort: ProjectSort | undefined
handleSort: (value: ProjectSort) => void
isPc?: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/app/panel/main-page/SearchOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SearchOption = ({
openOption: boolean
setOpenOption: any
setDetailOption: any
type: ProjectType | undefined
type: ProjectType
}) => {
const { isPc } = useMedia()
const typeTitle = type === 'PROJECT' ? '프로젝트' : '스터디'
Expand Down
4 changes: 2 additions & 2 deletions src/app/panel/main-page/SelectType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const SelectType = ({
type,
setType,
}: {
type: ProjectType | undefined
type: ProjectType
setType: (value: ProjectType) => void
}) => {
{
Expand All @@ -14,7 +14,7 @@ const SelectType = ({
return (
<Stack flexDirection={'row'} gap={'0.75rem'} alignItems={'center'}>
<Typography
color={!type || type === 'STUDY' ? 'text.strong' : 'text.assistive'}
color={type === 'STUDY' ? 'text.strong' : 'text.assistive'}
variant={'Title1'}
onClick={() => {
setType('STUDY')
Expand Down
2 changes: 1 addition & 1 deletion src/app/recruit/[id]/panel/ApplyDefaultButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ApplyDefaultButton = ({
disabled={disabled}
>
<Typography variant={'Body1'} color={'white'}>
지원하기
{disabled ? '마감' : '지원하기'}
</Typography>
</Button>
)
Expand Down
2 changes: 1 addition & 1 deletion src/app/recruit/[id]/panel/ApplyDrawerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ApplyDrawerButton = ({
}}
>
<Typography variant={'Body1'} color={'white'}>
지원하기
{disabled ? '마감' : '지원하기'}
</Typography>
</Button>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/app/recruit/[id]/panel/ApplyMenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ApplyMenuButton = ({
sx={sx}
>
<Typography variant={'Body1'} color={'white'}>
지원하기
{disabled ? '마감' : '지원하기'}
</Typography>
</Button>
<Menu
Expand Down
2 changes: 1 addition & 1 deletion src/types/IPostDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IMainCard {
tagList: ITag[]
favorite?: boolean
recruit_id: number
type: ProjectType | undefined
type: ProjectType
href?: string
onFavorite?: () => void
sx?: SxProps
Expand Down

0 comments on commit aece636

Please sign in to comment.