Skip to content

Commit

Permalink
Fix: 옮기변서 생긴 에러 수정 및 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
nightowlzz committed May 13, 2024
1 parent 82aaa22 commit 06b13bf
Show file tree
Hide file tree
Showing 29 changed files with 407 additions and 268 deletions.
57 changes: 41 additions & 16 deletions components/common/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,53 @@
import { useState } from "react";
import useFetch from "@/src/hook/useFetch";
import { IHeaderUserLoginInfoApi } from "./interface";
import { BASE_URL } from "@/src/constant/api";
import { useEffect, useState } from "react";
import axios from "@/lib/axios";
import { Email, HeaderControl, HeaderInner, HeaderLogo, HeaderUserInfo, HeaderWrap } from "./headerStyle";
import Link from "next/link";
import { useRouter } from "next/router";
import { Profile } from "@/styles/commonStyle";
import LinkButton from "./atoms/LinkButton";
import Link from "next/link";

const logo = '/assets/logo/logo.svg';

function Header() {
// const { pathname } = useLocation();
const { value } = useFetch<IHeaderUserLoginInfoApi>(BASE_URL);
export interface IHeaderUser {
id:number,
email:string,
name?:string,
image_source?:string,
created_at?:string,
auth_id:string
}

export interface IHeaderUserLoginInfoApi {
userInfo?: {
data: IHeaderUser[];
};
}

export async function getStaticProps() {
const res = await axios.get(``);
const userInfo = res.data;

return {
props:{
userInfo,
}
}
}

function Header({userInfo}:IHeaderUserLoginInfoApi) {
const {pathname} = useRouter();
const [fixed, setFixed] = useState(true);
// useEffect(() => {
// if (pathname === '/folder') {
// setFixed(false);
// }
// }, [pathname]);
const userInfo = value?.data[0] ?? undefined;

useEffect(() => {
if (pathname === '/folder') {
setFixed(false);
}
}, [pathname]);

return (
<HeaderWrap className="head__wrap" $position={fixed}>
<HeaderInner>
<HeaderLogo>
<HeaderLogo className="head__logo">
<Link href="/">
<img src={logo} alt="linkbrary" />
</Link>
Expand All @@ -31,7 +56,7 @@ function Header() {
{userInfo ? (
<HeaderUserInfo>
<Profile></Profile>
<Email>{userInfo?.email}</Email>
<Email>{userInfo?.data[0].email}</Email>
</HeaderUserInfo>
) : (
<LinkButton $link={'/signin'} $linkClass={'link--gradient link--login large'}>
Expand Down
5 changes: 3 additions & 2 deletions components/common/atoms/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ButtonHTMLAttributes } from 'react';
import { ButtonModule } from './buttonStyle';
interface IButtonModule {
children: React.ReactNode;
$btnClass: string;
$BeforButtonIcon?: string;
$id?: string | number;
$id?: string;
$afterButtonIcon?: string;
$type?: 'button' | 'reset' | 'submit' | undefined;
$type?: ButtonHTMLAttributes<HTMLButtonElement>['type'];
onclick?: () => void;
}

Expand Down
2 changes: 1 addition & 1 deletion components/common/atoms/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ICheckBoxData {
}

function CheckBox({ $data }: ICheckBoxData) {
if (typeof $data) {
if ($data?.data) {
return (
<CheckBoxWrap className="chk--list-type1">
{$data &&
Expand Down
5 changes: 3 additions & 2 deletions components/common/atoms/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ChangeEvent, ReactNode, useEffect, useRef, useState } from 'react';
import { InputModule } from './inputStyle';
import Button from './Button';
import { SearchResults } from '@/pages/folder/folderStyle';
import { Relative } from '@/styles/commonStyle';

interface IButtonModule {
$type?: string;
Expand Down Expand Up @@ -47,7 +48,7 @@ function Input({

return (
<>
<div style={{position:'relative'}}>
<Relative>
<InputModule
type={$type}
className={$inputClass}
Expand All @@ -62,7 +63,7 @@ function Input({
{children}
</Button>
)}
</div>
</Relative>
{value && <SearchResults><span>{value}</span>으로 검색한 결과입니다.</SearchResults>}
</>
);
Expand Down
4 changes: 3 additions & 1 deletion components/common/atoms/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ interface IButtonModule {
children: React.ReactNode;
$link: string;
$linkClass: string;
$target?: string;
}

export default function LinkButton({
children,
$link,
$linkClass,
$target="_self"
}: IButtonModule) {
return (
<LinkModule href={$link} className={$linkClass}>
<LinkModule href={$link} className={$linkClass} target="$target">
{children}
</LinkModule>
);
Expand Down
6 changes: 6 additions & 0 deletions components/common/atoms/LinkButtonStyle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from "styled-components";
import { theme } from "@/styles/theme";
import Link from "next/link";
import { font24 } from "@/styles/commonStyle";


export const LinkModule = styled(Link)`
Expand All @@ -21,6 +22,11 @@ export const LinkModule = styled(Link)`
width: 80px;
}
}
&--title {
&-text {
${font24}
}
}
}
&.full {
width: 100% !important;
Expand Down
13 changes: 0 additions & 13 deletions components/common/interface.ts

This file was deleted.

27 changes: 0 additions & 27 deletions components/folder/ContantList.tsx

This file was deleted.

10 changes: 5 additions & 5 deletions components/folder/FolderButtonList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import { IFolderMenuButtonApi } from '@/pages/folder/interface';

interface IButtonList {
$menu: IFolderMenuButtonApi | null;
$btnActive: number | string;
$activeBtnId: number;
onClick: (id:number) => void;
}

function FolderButtonList({
$menu,
$btnActive,
$activeBtnId,
onClick,
}: IButtonList) {

return (
<BookMarkBtnList>
<Button
$id={-1}
$btnClass={`button--outlined ${$btnActive === -1 ? 'active' : ''}`}
$id={`-1`}
$btnClass={`button--outlined ${$activeBtnId === -1 ? 'active' : ''}`}
onclick={() => onClick(-1)}
>
전체
Expand All @@ -30,7 +30,7 @@ function FolderButtonList({
key={item.id}
$id={`${item.id}`}
$btnClass={`button--outlined ${
$btnActive === item.id ? 'active' : ''
$activeBtnId === item.id ? 'active' : ''
}`}
onclick={() => onClick(item.id)}
>
Expand Down
12 changes: 9 additions & 3 deletions components/folder/FolderContentControll.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { memo } from 'react';
import Button from '../common/atoms/Button';
import Link from 'next/link';
import { ShareBox } from '../share/shareStyle';
import { ShareListBtn } from '@/pages/folder/folderStyle';
import LinkButton from '../common/atoms/LinkButton';
import { Font } from '@/styles/commonStyle';

const folderControlBtn = [
{
Expand All @@ -27,17 +28,22 @@ const folderControlBtn = [

interface iControll {
$title: string;
onclick: (type: any) => void;
onclick: (type: string) => void;
$id?:number
}

function FolderContentControll({ $title, onclick, $id }: iControll) {
const handleModalOpen = (type: any) => {
onclick(type);
};

return (
<ShareBox>
<Link href={`/shared/${$id}`} target='_blank'>{$title}</Link>
{
$id &&
$id === -1 ? <Font as='strong' className='font--size-ls tab-title'>{$title}</Font>:
<LinkButton $link={`/shared/${$id}`} $linkClass="link--title-text tab-title" $target='_blank'>{$title}</LinkButton>
}
{$title === '전체' || (
<ShareListBtn>
{folderControlBtn.map((btn) => (
Expand Down
32 changes: 5 additions & 27 deletions components/folder/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { IFolderContent, IFolderMenuButtonApi } from "@/pages/folder/interface";
import useFetch from "@/src/hook/useFetch";
import { useMemo, useState } from "react";
import Link from "next/link";
import { IFolderContent} from "@/pages/folder/interface";
import { IModal } from "../modal/interface";
import { FOLDER_MENU_LIST_API } from "@/src/constant/api";
import { BookMarkBtn, CardMenu, CardWrap } from "./PostCardStyle";
import Link from "next/link";
import { DFlaxAlignCenterBtw, EllipsisLine } from "@/styles/commonStyle";
import { calculateTimeAgo } from "@/src/utils/calcTilmAgo";
import Modal from "../modal/Modal";
import { modalOrder } from "@/src/constant/modal";
import { DFlaxAlignCenterBtw, EllipsisLine } from "@/styles/commonStyle";

const emptyImg = '/assets/logo/logo.svg';

function useFatchDataLoad<T>(api: string) {
return useFetch<T>(api);
}

export default function PostCard({ image_source, description, created_at}: IFolderContent) {
const [bookMark, setBookMark] = useState(false);
const [cardMenuShow, setCardMenuShow] = useState(false);
Expand All @@ -28,25 +21,10 @@ export default function PostCard({ image_source, description, created_at}: IFold
$buttonText: null,
$modalData: null,
});
const { value: menu, isLoading: menuLoading } =
useFatchDataLoad<IFolderMenuButtonApi>(FOLDER_MENU_LIST_API);

const handelerBookMarkActive = () => setBookMark((prev) => !prev);
const handelerCardDropdown = () => setCardMenuShow((prev) => !prev);

const handleModalOpen = (type: string) => {
let modalInfo = modalOrder[type];
if (type === 'folderInAdd') {
modalInfo = {
...modalInfo,
$modalData: menu,
};
}
setModalInfo(modalInfo);
setModalShow(true);
setCardMenuShow(false);
};

const handleModalClose = () => {
setModalShow(false);
};
Expand Down Expand Up @@ -93,7 +71,7 @@ export default function PostCard({ image_source, description, created_at}: IFold
</button>
{cardMenuShow && (
<div className="card__dropdown-menu">
<button
{/* <button
className="card__menu-btn"
onClick={() => handleModalOpen('folderDelete')}
>
Expand All @@ -104,7 +82,7 @@ export default function PostCard({ image_source, description, created_at}: IFold
onClick={() => handleModalOpen('folderInAdd')}
>
폴더에 추가
</button>
</button> */}
</div>
)}
</CardMenu>
Expand Down
21 changes: 21 additions & 0 deletions components/folder/PostCardList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { memo } from 'react';
import { IFolderContent } from '@/pages/folder/interface';
import PostCard from './PostCard';
import { EmptyBox, PostCardWrap } from '@/pages/folder/folderStyle';


interface IFolderList {
$content: IFolderContent[] | undefined | null;
}

function PostCardList({ $content }: IFolderList) {
if(!$content) return <EmptyBox>저장된 링크가 없습니다.</EmptyBox>
return (
<PostCardWrap>
{$content?.map((data) => (
<PostCard key={data.id} {...data} />
))}
</PostCardWrap>
);
}
export default memo(PostCardList);
2 changes: 1 addition & 1 deletion components/share/ShareModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { snsShare } from '../../constant/share';
import { snsShare } from '@/src/constant/share';
import Button from '../common/atoms/Button';
import { ShareBox } from './shareStyle';

Expand Down
16 changes: 15 additions & 1 deletion components/share/shareStyle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { DFlaxAlignCenterBtw } from "@/styles/commonStyle";
import { theme } from "@/styles/theme";
import styled from "styled-components";

export const ShareBox = styled(DFlaxAlignCenterBtw)``
export const ShareBox = styled(DFlaxAlignCenterBtw)`
.tab-title {
margin-bottom: 1.5rem;
font-weight: 700;
}
@media screen and (max-width: ${theme.screenSize.moLarge}) {
flex-direction: column;
align-items: flex-start;
padding-bottom: 1.15rem;
.tab-title {
margin-bottom: 0.75rem;
}
}
`
Loading

0 comments on commit 06b13bf

Please sign in to comment.