Commit 1df94f68 authored by 백승민's avatar 백승민
Browse files

slide 편집 전 pagination done

parent f4ab4299
import React, { useRef, useState } from "react";
type num = {
total: number,
page: number,
setPage: Function,
style: string,
setStyle: Function,
// slides : any[],
}
export function MySlide({ total, page, setPage, style, setStyle}: num) {
const numPages = Math.ceil(total / 15);
const firstLeftClick = useRef(true);
const firstRightClick = useRef(true);
const slide = useRef(1);
const leftClick = () => {
if (firstLeftClick.current) {
firstLeftClick.current = false;
firstRightClick.current = true;
} else {
setPage(page - 1)
}
slide.current -= 1;
setStyle("-translate-x-full animate-slidetoright");
};
const rightClick = () => {
if (firstRightClick.current) {
firstLeftClick.current = true;
firstRightClick.current = false;
} else {
setPage(page + 1)
}
slide.current += 1;
setStyle("animate-slidetoleft");
};
return (
<div>
<button onClick={leftClick} disabled={slide.current === 1}>
&lt;{slide.current}
</button>
<button onClick={rightClick} disabled={slide.current === numPages}>
&gt;
</button>
</div>
);
};
{/* {Array(numPages)
.fill(1)
.map((_, i) => (
<button key={i + 1} onClick={() => setPage(i + 1)}>
{i + 1}
</button>
))} */}
\ No newline at end of file
// import React, { useRef, useState} from "react";
// type num = {
// total: number,
// page: number,
// setPage: Function
// }
// export function Pagination({ total, page, setPage}: num) {
// const numPages = Math.ceil(total / 15);
// const firstLeftClick = useRef(true);
// const firstRightClick = useRef(true);
// const leftClick = () => {
// if (firstLeftClick.current) {
// firstLeftClick.current = false;
// firstRightClick.current = true;
// } else {
// setPage(page - 1)
// }
// };
// const rightClick = () => {
// if (firstRightClick.current) {
// firstLeftClick.current = true;
// firstRightClick.current = false;
// } else {
// setPage(page + 1)
// }
// };
// };
// return (
// <div>
// <button onClick={leftClick} disabled={page === 1}>
// &lt;{page}
// </button>
// <button onClick={rightClick} disabled={page === numPages}>
// &gt;
// </button>
// </div>
// );
// };
// export function PaginationRight({ total, page, setPage }: num) {
// const numPages = Math.ceil(total / 15);
// const firstLeftClick = useRef(true);
// const firstRightClick = useRef(true);
// const right = () => {
// if (firstRightClick.current) {
// firstLeftClick.current = true;
// firstRightClick.current = false;
// } else {
// setPage(page + 1)
// }
// };
// return (
// <div>
// <button onClick={right} disabled={page === numPages}>
// &gt;
// </button>
// </div>
// );
// };
{/* {Array(numPages)
.fill(1)
.map((_, i) => (
<button key={i + 1} onClick={() => setPage(i + 1)}>
{i + 1}
</button>
))} */}
\ No newline at end of file
...@@ -3,18 +3,17 @@ import { Outlet, useSearchParams } from "react-router-dom"; ...@@ -3,18 +3,17 @@ import { Outlet, useSearchParams } from "react-router-dom";
import Theme from "./theme"; import Theme from "./theme";
import Citylist from "../Pages/citylist"; import Citylist from "../Pages/citylist";
import { getPicure } from "../Pages/pic"; import { getPicure } from "../Pages/pic";
// import { Pagination} from "../Pages/picpagination"; import { MySlide } from "../Pages/myslide";
const initSearchParams = { theme: "", city: "" }; const initSearchParams = { theme: "", city: "" };
export default function Body() { export default function Body() {
let limit = 15; let limit = 15;
const [searchParams, setSearchParams] = useSearchParams(initSearchParams); const [searchParams, setSearchParams] = useSearchParams(initSearchParams);
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const [style, setStyle] = useState(""); const [style, setStyle] = useState("");
const firstRightClick = useRef(true);
const firstLeftClick = useRef(true);
const slide = useRef(1);
const offset1 = (page - 1) * limit; const offset1 = (page - 1) * limit;
const offset2 = page * limit; const offset2 = page * limit;
const offset3 = (page + 1) * limit; const offset3 = (page + 1) * limit;
...@@ -42,30 +41,7 @@ export default function Body() { ...@@ -42,30 +41,7 @@ export default function Body() {
}); });
}; };
const leftClick = () => { //picture insert
if (firstLeftClick.current) {
firstLeftClick.current = false;
firstRightClick.current = true;
} else {
setPage(page - 1)
}
slide.current -= 1;
setStyle("-translate-x-full animate-slidetoright");
};
const rightClick = () => {
if (firstRightClick.current) {
firstLeftClick.current = true;
firstRightClick.current = false;
} else {
setPage(page + 1)
}
slide.current += 1;
setStyle("animate-slidetoleft");
};
console.log(`page: ${slide.current}`);
console.log(`style: ${style}`);
let themechange = searchParams.get("theme"); let themechange = searchParams.get("theme");
let citylistchange = searchParams.get("city"); let citylistchange = searchParams.get("city");
...@@ -79,6 +55,27 @@ export default function Body() { ...@@ -79,6 +55,27 @@ export default function Body() {
}); });
const numPages = Math.ceil(Idpics.length / 15); const numPages = Math.ceil(Idpics.length / 15);
console.log(page)
// const slides = []
// for (let i = 0; i < numPages + 1; i++) {
// const k =[
// <div key={Math.random()} className="min-w-full">
// <div className={`inline-grid grid-cols-5 ${style}`}>
// {Idpics.slice(i * limit, i * limit + limit).map((pic, index: number) => (
// <div
// className={`m-1 shrink-0 bg-gray-200 rounded shadow-md `}
// key={index}>
// <img
// src={pic.url}
// className="w-full h-10 md:h-20 object-center"
// />
// <p className="text-center text-xs">{pic.name}</p>
// </div>
// ))}
// </div>
// </div>]
// slides.push(k);
// }
return ( return (
<div className="flex flex-col px-1 py-1"> <div className="flex flex-col px-1 py-1">
...@@ -88,14 +85,7 @@ export default function Body() { ...@@ -88,14 +85,7 @@ export default function Body() {
<Citylist handleClick={cityHandleClick} /> <Citylist handleClick={cityHandleClick} />
</div> </div>
<div className="flex flex-col overflow-hidden"> <div className="flex flex-col overflow-hidden">
<div> <MySlide total={Idpics.length} page={page} setPage={setPage} style={style} setStyle={setStyle}/>
<button onClick={leftClick} disabled={slide.current === 1}>
&lt;{slide.current}
</button>
<button onClick={rightClick} disabled={slide.current === numPages}>
&gt;
</button>
</div>
<div className={`md:mr-10 md:basis-4/5 flex flex-row relative w-full `}> <div className={`md:mr-10 md:basis-4/5 flex flex-row relative w-full `}>
<div key={Math.random()} className="min-w-full"> <div key={Math.random()} className="min-w-full">
<div className={`inline-grid grid-cols-5 ${style}`}> <div className={`inline-grid grid-cols-5 ${style}`}>
......
...@@ -21,8 +21,8 @@ module.exports = { ...@@ -21,8 +21,8 @@ module.exports = {
}, },
}, },
animation: { animation: {
slidetoleft: "slidetoleft 3s linear forwards", slidetoleft: "slidetoleft 2s linear forwards",
slidetoright: "slidetoright 3s linear forwards", slidetoright: "slidetoright 2s linear forwards",
}, },
}, },
}, },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment