Skip to content

Commit

Permalink
🚀 feat(boiler) : 페이지네이션 예시 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNM committed Jul 17, 2022
1 parent c6e2458 commit 0e0cf1a
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 199 deletions.
106 changes: 58 additions & 48 deletions src/components/MainLayout/MainLayout.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
import { Layout, Menu, Breadcrumb } from "antd";
import { Layout, Menu, Breadcrumb } from 'antd';
import {
SortAscendingOutlined,
GlobalOutlined,
UserOutlined,
IdcardOutlined,
CompassOutlined,
} from "@ant-design/icons";
import React from "react";
import { withNavigation } from "../../hoc/withRouterForClass";
import { Route, Routes } from "react-router-dom";
import "./MainLayout.css";
import LandingPage from "../LandingPage/LandingPage";
import UsersPage from "../Tables/UsersPage/UsersPage";
import TicketsPage from "../Tables/TicketsPage/TicketsPage";
import OrdersPage from "../Tables/OrdersPage/OrdersPage";
import EnterPage from "../Tickets/EnterPage/EnterPage";
import CheckPage from "../Tickets/CheckPage/CheckPage";
import AccoutPage from "../AccountPage/AccoutPage";
CompassOutlined
} from '@ant-design/icons';
import React from 'react';
import { withNavigation } from '../../hoc/withRouterForClass';
import { Route, Routes } from 'react-router-dom';
import './MainLayout.css';
import LandingPage from '../LandingPage/LandingPage';
import UsersPage from '../Tables/UsersPage/UsersPage';
import TicketsPage from '../Tables/TicketsPage/TicketsPage';
import OrdersPage from '../Tables/OrdersPage/OrdersPage';
import EnterPage from '../Tickets/EnterPage/EnterPage';
import CheckPage from '../Tickets/CheckPage/CheckPage';
import AccoutPage from '../AccountPage/AccoutPage';
import ExamplePage from '../Tables/ExamplePage/ExamplePage';

const { Content, Footer, Sider } = Layout;

const keyToInfo = {
main1: { text: "랜딩 페이지", link: "/landing" },
main2: { text: "유저 페이지", link: "/table/users" },
main3: { text: "주문목록 페이지", link: "/table/orders" },
main4: { text: "티켓 페이지", link: "/table/tickets" },
main5: { text: "실시간 티켓 입장확인", link: "/tickets/enter" },
main6: { text: "카메라 입장 확인", link: "/tickets/check" },
main7: { text: "계정", link: "/accounts" },
main1: { text: '랜딩 페이지', link: '/landing' },
main2: { text: '유저 페이지', link: '/table/users' },
main3: { text: '주문목록 페이지', link: '/table/orders' },
main4: { text: '티켓 페이지', link: '/table/tickets' },
main5: { text: '실시간 티켓 입장확인', link: '/tickets/enter' },
main6: { text: '카메라 입장 확인', link: '/tickets/check' },
main7: { text: '계정', link: '/accounts' },
main8: { text: '예시페이지네이션', link: '/example' }
};

let clickedkeyPath = ["main1"];
let clickedkeyPath = ['main1'];
for (let key in keyToInfo) {
if (keyToInfo[key].link === window.location.pathname)
clickedkeyPath = [`${key}`];
Expand All @@ -39,10 +41,10 @@ for (let key in keyToInfo) {
class MainLayout extends React.Component {
state = {
collapsed: false,
clickedkeyPath: clickedkeyPath,
clickedkeyPath: clickedkeyPath
};

onCollapse = (collapsed) => {
onCollapse = collapsed => {
console.log(collapsed);
this.setState({ collapsed });
};
Expand All @@ -56,18 +58,18 @@ class MainLayout extends React.Component {
const { collapsed, clickedkeyPath } = this.state;
console.log(window.location.pathname);
return (
<Layout style={{ minHeight: "100vh" }}>
<Layout style={{ minHeight: '100vh' }}>
<Sider
// theme={"light"}
collapsible
collapsed={collapsed}
onCollapse={this.onCollapse}
style={{
display: "flex",
flexDirection: "column",
alignItems: "stretch",
height: "%100",
background: "black",
display: 'flex',
flexDirection: 'column',
alignItems: 'stretch',
height: '%100',
background: 'black'
}}
>
<div className="logo"> zetciti </div>
Expand All @@ -78,56 +80,63 @@ class MainLayout extends React.Component {
style={{
// display: "flex",
// flexDirection: "column",
background: "black",
background: 'black',

marginTop: "auto 0",
height: "%100",
marginTop: 'auto 0',
height: '%100'
}}
onClick={this.menuClick}
>
<Menu.Item key="main1" icon={<UserOutlined />}>
{keyToInfo["main1"].text}
{keyToInfo['main1'].text}
</Menu.Item>
<Menu.Item key="main2" icon={<GlobalOutlined />}>
{keyToInfo["main2"].text}
{keyToInfo['main2'].text}
</Menu.Item>
<Menu.Item key="main3" icon={<CompassOutlined />}>
{keyToInfo["main3"].text}
{keyToInfo['main3'].text}
</Menu.Item>
<Menu.Item
key="main4"
icon={<SortAscendingOutlined />}
style={{ marginTop: "auto" }}
style={{ marginTop: 'auto' }}
>
{keyToInfo["main4"].text}
{keyToInfo['main4'].text}
</Menu.Item>
<Menu.Item
key="main5"
icon={<IdcardOutlined />}
style={{ marginTop: "auto" }}
style={{ marginTop: 'auto' }}
>
{keyToInfo["main5"].text}
{keyToInfo['main5'].text}
</Menu.Item>
<Menu.Item
key="main6"
icon={<IdcardOutlined />}
style={{ marginTop: "auto" }}
style={{ marginTop: 'auto' }}
>
{keyToInfo["main6"].text}
{keyToInfo['main6'].text}
</Menu.Item>
<Menu.Item
key="main7"
icon={<IdcardOutlined />}
style={{ marginTop: "auto" }}
style={{ marginTop: 'auto' }}
>
{keyToInfo["main7"].text}
{keyToInfo['main7'].text}
</Menu.Item>
<Menu.Item
key="main8"
icon={<IdcardOutlined />}
style={{ marginTop: 'auto' }}
>
{keyToInfo['main8'].text}
</Menu.Item>
</Menu>
</Sider>
<Layout className="site-layout">
<Content style={{ margin: "0 16px" }}>
<Breadcrumb style={{ margin: "16px 0" }}>
{clickedkeyPath.map((e) => {
<Content style={{ margin: '0 16px' }}>
<Breadcrumb style={{ margin: '16px 0' }}>
{clickedkeyPath.map(e => {
return (
<Breadcrumb.Item key={keyToInfo[e].text}>
{keyToInfo[e].text}
Expand All @@ -147,10 +156,11 @@ class MainLayout extends React.Component {
<Route exact path="/tickets/enter" element={<EnterPage />} />
<Route exact path="/tickets/check" element={<CheckPage />} />
<Route exact path="/accounts" element={<AccoutPage />} />
<Route exact path="/example" element={<ExamplePage />} />
</Routes>
</div>
</Content>
<Footer style={{ textAlign: "center" }}>
<Footer style={{ textAlign: 'center' }}>
gosrock ©2022 Created by gosrock
</Footer>
</Layout>
Expand Down
12 changes: 12 additions & 0 deletions src/components/Tables/ExamplePage/ExamplePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import TableExample from './Table';

function ExamplePage() {
return (
<div>
<TableExample />
</div>
);
}

export default ExamplePage;
102 changes: 102 additions & 0 deletions src/components/Tables/ExamplePage/Table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React, { useState, useEffect } from 'react';

import { useSelector, useDispatch } from 'react-redux';
import { Avatar, Table } from 'antd';
import { examplePagination } from '../../../state/actions-creators/examplePagination';
const { Column } = Table;

function TableExample() {
const dispatch = useDispatch();
const { data, pending } = useSelector(state => state.examplePagination);
const [page, setPage] = useState(1);

const onPageChange = e => {
// 페이지네이션 번호 바뀔때 뜸.
console.log(e);
setPage(e);
dispatch(
examplePagination({
requestPage: e
})
);
};

useEffect(() => {
dispatch(
examplePagination({
page: 0
})
);
}, [dispatch]);

// 받을 수 있는 정보 목록
// {
// "albumId": 1,
// "id": 11,
// "title": "nihil at amet non hic quia qui",
// "url": "https://via.placeholder.com/600/1ee8a4",
// "thumbnailUrl": "https://via.placeholder.com/150/1ee8a4"
// },

return (
<>
<Table
loading={pending}
pagination={{
current: page,
pageSize: 10,
total: data ? data.total : 0,
showSizeChanger: false,
onChange: onPageChange
}}
key="id"
rowKey="id"
// onRow={(record, rowIndex) => {
// return {
// onClick: event => {
// console.log(event, record);
// onStopClickHandler(record);
// } // click row
// };
// }}
pageSize={10}
dataSource={data ? data.photoList : []}
>
<Column
title="썸네일"
dataIndex="thumbnailUrl"
key="id"
render={element => {
return <Avatar src={element} />;
}}
/>
<Column title="앨범 아이디" dataIndex="id" key="id" />
<Column title="제목" dataIndex="title" key="id" />

<Column
title="관리"
// dataindex 정보를 안주면 render 의 element 가 행 하나의 값이 들어가게됨
dataIndex=""
key="id"
render={element => {
return (
<button
key={element.id}
style={{
backgroundColor: 'inherit',
border: 'none',
fontWeight: 700
}}
onClick={() => console.log(element)}
>
클릭 이벤트 콘솔 창 확인
</button>
);
}}
/>
</Table>
</>
);
}

export default TableExample;
4 changes: 4 additions & 0 deletions src/state/action-types/examplePagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//유저 조회 디스패치 관련
export const EXAMPLE_PAGINATION_PENDING = 'EXAMPLE_PAGINATION_PENDING';
export const EXAMPLE_PAGINATION_SUCCESS = 'EXAMPLE_PAGINATION_SUCCESS';
export const EXAMPLE_PAGINATION_ERROR = 'EXAMPLE_PAGINATION_ERROR';
7 changes: 4 additions & 3 deletions src/state/action-types/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./slackMessage";
export * from "./slackValidation";
export * from "./logout";
export * from './slackMessage';
export * from './slackValidation';
export * from './logout';
export * from './examplePagination';
3 changes: 0 additions & 3 deletions src/state/action-types/keywordList.js

This file was deleted.

39 changes: 39 additions & 0 deletions src/state/actions-creators/examplePagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import axios from 'axios';
import {
EXAMPLE_PAGINATION_PENDING,
EXAMPLE_PAGINATION_SUCCESS,
EXAMPLE_PAGINATION_ERROR
} from '../action-types';

export const examplePagination =
({ requestPage }, callback) =>
async dispatch => {
try {
dispatch({ type: EXAMPLE_PAGINATION_PENDING });

const response = await axios.get(
'https://jsonplaceholder.typicode.com/photos',
{
params: {
_page: requestPage,
_limit: 10
}
}
);
console.log('포토 조회액션', response);

const data = {
total: 5000,
currentPage: requestPage,
photoList: response.data
};

dispatch({ type: EXAMPLE_PAGINATION_SUCCESS, payload: data });

// 자동으로 피쳐로 넘어가게끔
// callback();
} catch (e) {
//400 ~
dispatch({ type: EXAMPLE_PAGINATION_ERROR, payload: '조회 실패' });
}
};
Loading

0 comments on commit 0e0cf1a

Please sign in to comment.