Skip to content

Commit

Permalink
Merge pull request #1 from Original-Gimchi/refactor/code-review
Browse files Browse the repository at this point in the history
코드리뷰
  • Loading branch information
Ubinquitous authored Mar 26, 2023
2 parents 1e9e256 + af161a2 commit fd7c59c
Show file tree
Hide file tree
Showing 38 changed files with 558 additions and 487 deletions.
2 changes: 2 additions & 0 deletions api/getDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const getVersionDocs = async (title: string) => {
},
})
).data
// 기본값 추가
// return data || { user : null }
}

export const getBaseDocs = async (docsType: string) => {
Expand Down
6 changes: 6 additions & 0 deletions assets/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions assets/footerLogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/prev.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 2 additions & 10 deletions components/AccodianMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@ const AccodianMenu = ({ children, name, isOpen }: AccodianType) => {
const [detail, setDetail] = React.useState<boolean>(true)
const [opacity, setOpacity] = React.useState<number>(1)

React.useEffect(() => {
if (isOpen === false) {
setDetail(false)
setOpacity(0.4)
}
// eslint-disable-next-line
}, [])

const onClickDetail = () => {
setDetail((detail) => !detail)
if (opacity === 1) setOpacity(0.4)
else setOpacity(1)
if (opacity === 1) return setOpacity(0.4)
setOpacity(1)
}

return (
Expand Down
20 changes: 6 additions & 14 deletions components/Aside/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import * as api from '@/api/getDocs'

import React from 'react'
import Docs from '@/types/docs.type'
import PrevLogo from 'assets/prev.svg'
import NextLogo from 'assets/next.svg'
import { useQuery } from 'react-query'

const Aside = () => {
Expand All @@ -28,22 +30,12 @@ const Aside = () => {
))}
<S.AsidePageWrap>
<S.AsidePageButton onClick={() => setPage(page > 0 ? page - 1 : page)}>
<svg width="11" height="20" viewBox="0 0 11 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M8.773 19.3793L0.347998 10.9793C0.247998 10.8793 0.177331 10.771 0.135998 10.6543C0.093998 10.5377 0.072998 10.4127 0.072998 10.2793C0.072998 10.146 0.093998 10.021 0.135998 9.90432C0.177331 9.78766 0.247998 9.67932 0.347998 9.57932L8.773 1.15432C9.00633 0.920988 9.298 0.804321 9.648 0.804321C9.998 0.804321 10.298 0.929321 10.548 1.17932C10.798 1.42932 10.923 1.72099 10.923 2.05432C10.923 2.38765 10.798 2.67932 10.548 2.92932L3.198 10.2793L10.548 17.6293C10.7813 17.8627 10.898 18.15 10.898 18.4913C10.898 18.8333 10.773 19.1293 10.523 19.3793C10.273 19.6293 9.98133 19.7543 9.648 19.7543C9.31466 19.7543 9.023 19.6293 8.773 19.3793Z"
fill="#274168"
/>
</svg>
<span>이전</span>
<S.AsideImage src={PrevLogo} alt="" />
<S.AsidePageText>이전</S.AsidePageText>
</S.AsidePageButton>
<S.AsidePageButton onClick={() => setPage(data.length < 12 ? page : page + 1)}>
<span>다음</span>
<svg width="11" height="20" viewBox="0 0 11 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M2.22233 1.17949L10.6479 9.57893C10.7479 9.67892 10.8186 9.78725 10.8599 9.90391C10.9019 10.0206 10.9229 10.1456 10.9229 10.2789C10.923 10.4122 10.902 10.5372 10.86 10.6539C10.8186 10.7706 10.748 10.8789 10.648 10.9789L2.22356 19.4045C1.99024 19.6378 1.69858 19.7545 1.34858 19.7546C0.998584 19.7546 0.698576 19.6296 0.448559 19.3796C0.198542 19.1296 0.0735227 18.838 0.0735002 18.5046C0.0734777 18.1713 0.198458 17.8796 0.448441 17.6296L7.79794 10.2791L0.447449 2.92961C0.2141 2.69629 0.0974137 2.40897 0.0973907 2.06764C0.0973676 1.72564 0.222348 1.42963 0.472331 1.17961C0.722314 0.929594 1.01397 0.804574 1.34731 0.804552C1.68064 0.804529 1.97231 0.929509 2.22233 1.17949Z"
fill="#274168"
/>
</svg>
<S.AsidePageText>다음</S.AsidePageText>
<S.AsideImage src={NextLogo} alt="" />
</S.AsidePageButton>
</S.AsidePageWrap>
</S.AsideWrap>
Expand Down
17 changes: 10 additions & 7 deletions components/Aside/style.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Image from 'next/image'
import Link from 'next/link'
import styled from 'styled-components'

Expand Down Expand Up @@ -79,17 +80,19 @@ export const AsidePageButton = styled.div`
height: 10px;
}
span {
margin: 0 2px 0 2px;
&::selection {
background-color: transparent;
}
}
&:first-child {
margin-left: 0;
}
&:last-child {
margin-right: 0;
}
`

export const AsidePageText = styled.span`
margin: 0 2px 0 2px;
&::selection {
background-color: transparent;
}
`

export const AsideImage = styled(Image)``
4 changes: 1 addition & 3 deletions components/Button/Authority/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const Authority = ({ email }: AuthorityProps) => {
})

const onClickAuthorityUser = (authority: string) => {
if (window.confirm(`유저 권한을 ${authority}(으)로 변경하시겠습니까?`)) {
mutate({ email, authority })
}
if (window.confirm(`유저 권한을 ${authority}(으)로 변경하시겠습니까?`)) return mutate({ email, authority })
}

return (
Expand Down
23 changes: 5 additions & 18 deletions components/Button/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useRecoilState, useRecoilValue } from 'recoil'
import userState from '@/context/userState'
import { MutationFunction, useMutation, useQueryClient } from 'react-query'
import { useRouter } from 'next/router'
import useUser from '@/hooks/useUser'

interface DetailBtnProps {
docsId: number
Expand All @@ -17,18 +18,7 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => {
const { query } = router
const [docsName, setDocsName] = React.useState('')
const queryClient = useQueryClient()
const [user, setUser] = useRecoilState(userState)

React.useEffect(() => {
;(async () => {
try {
const res = await userApi.getUser()
if (!user.id) setUser(res)
} catch (err) {
console.log(err)
}
})()
}, [setUser, user])
const { user: userInfo, isLogined } = useUser()

const updateDocsTitleMutation = useMutation(api.updateDocsTitle, {
onSuccess: (res) => {
Expand All @@ -40,7 +30,7 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => {

const onClickNavigatePage = (type: string) => {
if (type === 'VERSION') router.push(`/version/${query.title}`)
else if (type === 'UPDATE' && !user.id) alert('로그인 후 편집하실 수 있습니다!')
else if (type === 'UPDATE' && !isLogined) alert('로그인 후 편집하실 수 있습니다!')
else router.push(`/update/${query.title}`)
}

Expand All @@ -52,10 +42,7 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => {
})

const onClickChangeDocsName = async () => {
if (!docsName.length) {
alert('내용이 없습니다.')
return
}
if (!docsName.length) return alert('내용이 없습니다.')
updateDocsTitleMutation.mutate({ title: router.pathname as string, docsName })
}

Expand All @@ -66,7 +53,7 @@ const DetailBtn = ({ docsId }: DetailBtnProps) => {

return (
<S.DetailButtonWrap>
{user.authority === 'ADMIN' && (
{userInfo.authority === 'ADMIN' && (
<>
<S.DetailWrap onClick={onClickDeleteDocs}>
<S.DetailButton>
Expand Down
4 changes: 2 additions & 2 deletions components/Section/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const Footer = () => {
return (
<S.FooterWrap>
<S.FooterLogoWrap>
<S.FooterLink href={'https://github.com/Original-Gimchi'} target={'_blank'} rel="noreferrer">
<S.FooterLink href="https://github.com/Original-Gimchi" target="_blank" rel="noreferrer">
<S.FooterLogo src={github} alt="" />
</S.FooterLink>
<S.FooterLine />
<S.FooterLink href={'https://www.instagram.com/#'} target={'_blank'} rel="noreferrer">
<S.FooterLink href="https://www.instagram.com/#" target="_blank" rel="noreferrer">
<S.FooterLogo src={instagram} alt="" />
</S.FooterLink>
</S.FooterLogoWrap>
Expand Down
101 changes: 23 additions & 78 deletions components/Section/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,18 @@ import userState from '@/context/userState'
import React from 'react'
import { useRouter } from 'next/router'
import { useRecoilState } from 'recoil'
import useUser from '@/hooks/useUser'
import { headerInitState, subheaderInitState } from '@/state/headerInitState'

const Header = () => {
const [search, setSearch] = React.useState('')
const [isHover, setIsHover] = React.useState(false)
const [user, setUser] = useRecoilState(userState)
const { user: userInfo, isLogined, logout } = useUser()
const router = useRouter()

React.useEffect(() => {
;(async () => {
try {
const res = await api.getUser()
if (!user.id) setUser(res)
} catch (err) {
console.log(err)
}
})()
}, [setUser, user])

const navigateSearchResult = () => {
if (search.length) return router.push(`/search/${search}`)
alert('검색할 문서명을 입력해주세요!')
return alert('검색할 문서명을 입력해주세요!')
}

return (
Expand All @@ -41,23 +32,13 @@ const Header = () => {
<S.HeaderLogo src="/images/logo.png" width="1000" height="1000" alt="logo" />
</S.HeaderLink>
<S.HeaderSectionWrap>
<S.HeaderSection>
<S.HeaderSectionLogo src={Student} alt="" />
<S.HeaderSectionText>공지</S.HeaderSectionText>
</S.HeaderSection>
<S.HeaderSection>
<S.HeaderSectionLogo src={Teacher} alt="" />
<S.HeaderSectionText>학교</S.HeaderSectionText>
</S.HeaderSection>
<S.HeaderSection>
<S.HeaderSectionLogo src={Accident} alt="" />
<S.HeaderSectionText>기타</S.HeaderSectionText>
</S.HeaderSection>
<S.HeaderSection>
<S.HeaderSectionLogo src={Club} alt="" />
<S.HeaderSectionText>외부 서비스</S.HeaderSectionText>
</S.HeaderSection>
{user.id && (
{headerInitState.map((header, index) => (
<S.HeaderSection key={index}>
<S.HeaderSectionLogo src={header.image} alt="" />
<S.HeaderSectionText>{header.title}</S.HeaderSectionText>
</S.HeaderSection>
))}
{isLogined && (
<S.HeaderSectionLink href={`/create`}>
<S.HeaderSectionLogo src={Create} alt="" />
<S.HeaderSectionText>문서 생성</S.HeaderSectionText>
Expand All @@ -72,7 +53,7 @@ const Header = () => {
</S.HeaderSearchButton>
</S.HeaderSearchForm>
<S.HeaderLoginWrap>
{user.id ? (
{isLogined ? (
<S.HeaderMypageText href="/mypage">마이페이지</S.HeaderMypageText>
) : (
<S.HeaderLoginText href="https://auth.bssm.kro.kr/oauth?clientId=a1a16261&redirectURI=http://bumawiki.kro.kr/oauth">
Expand All @@ -87,53 +68,17 @@ const Header = () => {
<S.HeaderLogo src="/images/logo.png" width="1000" height="1000" alt="logo" />
</S.SubHeaderPlace>
<S.HeaderSectionWrap>
<S.SubHeaderSectionWrap>
<S.SubHeaderSection href="/docs/부마위키%20업데이트%20내용">
<S.HeaderSectionText display="true">공지사항</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="/docs/부마위키%20방명록">
<S.HeaderSectionText display="true">방명록</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="/docs/부마위키%20개인정보처리방침">
<S.HeaderSectionText>처리방침</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="https://forms.gle/DzAP7XSYH4ubK43FA" target="_blank">
<S.HeaderSectionText display="true">문의하기</S.HeaderSectionText>
</S.SubHeaderSection>
</S.SubHeaderSectionWrap>
<S.SubHeaderSectionWrap>
<S.SubHeaderSection href="/student">
<S.HeaderSectionText display="true">학생</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="/teacher">
<S.HeaderSectionText display="true">선생님</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="/club">
<S.HeaderSectionText display="true">동아리</S.HeaderSectionText>
</S.SubHeaderSection>
</S.SubHeaderSectionWrap>
<S.SubHeaderSectionWrap margin="1.2vw">
<S.SubHeaderSection href="/frame">
<S.HeaderSectionText display="true"></S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="/accident">
<S.HeaderSectionText display="true">사건</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="/popular">
<S.HeaderSectionText display="true">인기문서</S.HeaderSectionText>
</S.SubHeaderSection>
</S.SubHeaderSectionWrap>
<S.SubHeaderSectionWrap>
<S.SubHeaderSection href="">
<S.HeaderSectionText display="true">BSM</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="">
<S.HeaderSectionText display="true">BGIT</S.HeaderSectionText>
</S.SubHeaderSection>
<S.SubHeaderSection href="">
<S.HeaderSectionText display="true">심청이</S.HeaderSectionText>
</S.SubHeaderSection>
</S.SubHeaderSectionWrap>
{[
subheaderInitState.map((subheader, index) => (
<S.SubHeaderSectionWrap margin={index === 2 ? '1vw' : ''} key={index}>
{subheader.map((info, index) => (
<S.SubHeaderSection href={info.href} target={info.target} key={index}>
<S.HeaderSectionText display="true">{info.title}</S.HeaderSectionText>
</S.SubHeaderSection>
))}
</S.SubHeaderSectionWrap>
)),
]}
</S.HeaderSectionWrap>
</S.SubHeaderWrap>
</S.HeaderContainer>
Expand Down
1 change: 1 addition & 0 deletions components/Section/SubFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const SubFooter = () => {
<S.SubFooterWrap>
<S.SubFooterLine />
<S.SubFooterNoticeWrap>
{/* 보수작업 필요 */}
<S.SubFooterNoticeLogo
width="130"
height="92"
Expand Down
3 changes: 2 additions & 1 deletion context/userState.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { atom } from 'recoil'
import ContributeDocsType from '@/types/contributeDocs.type'

export const initUserState = {
id: 0,
email: '',
nickName: '',
authority: '',
contributeDocs: [],
contributeDocs: [] as ContributeDocsType[],
isLogin: false,
}

Expand Down
Loading

0 comments on commit fd7c59c

Please sign in to comment.