260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
@@ -6,33 +6,25 @@ interface UsePaginationProps {
|
||||
paginationItemsToDisplay?: number
|
||||
}
|
||||
|
||||
export function usePagination({
|
||||
currentPage,
|
||||
totalPages,
|
||||
paginationItemsToDisplay = 5
|
||||
}: UsePaginationProps) {
|
||||
const { pages, showLeftEllipsis, showRightEllipsis } = useMemo(() => {
|
||||
const halfDisplay = Math.floor(paginationItemsToDisplay / 2)
|
||||
|
||||
let startPage = Math.max(1, currentPage - halfDisplay)
|
||||
let endPage = Math.min(totalPages, currentPage + halfDisplay)
|
||||
|
||||
if (currentPage <= halfDisplay) {
|
||||
endPage = Math.min(paginationItemsToDisplay, totalPages)
|
||||
export function usePagination({ currentPage, totalPages, paginationItemsToDisplay = 5 }: UsePaginationProps) {
|
||||
return useMemo(() => {
|
||||
if (totalPages <= 0) {
|
||||
return { pages: [] as number[], showLeftEllipsis: false, showRightEllipsis: false }
|
||||
}
|
||||
|
||||
if (currentPage > totalPages - halfDisplay) {
|
||||
startPage = Math.max(1, totalPages - paginationItemsToDisplay + 1)
|
||||
}
|
||||
const visibleCount = Math.max(1, paginationItemsToDisplay)
|
||||
const half = Math.floor(visibleCount / 2)
|
||||
let startPage = Math.max(1, currentPage - half)
|
||||
let endPage = Math.min(totalPages, startPage + visibleCount - 1)
|
||||
|
||||
const pages = Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i)
|
||||
if (endPage - startPage + 1 < visibleCount) {
|
||||
startPage = Math.max(1, endPage - visibleCount + 1)
|
||||
}
|
||||
|
||||
return {
|
||||
pages,
|
||||
pages: Array.from({ length: endPage - startPage + 1 }, (_, index) => startPage + index),
|
||||
showLeftEllipsis: startPage > 1,
|
||||
showRightEllipsis: endPage < totalPages
|
||||
showRightEllipsis: endPage < totalPages,
|
||||
}
|
||||
}, [currentPage, totalPages, paginationItemsToDisplay])
|
||||
|
||||
return { pages, showLeftEllipsis, showRightEllipsis }
|
||||
}
|
||||
}, [currentPage, paginationItemsToDisplay, totalPages])
|
||||
}
|
||||
|
||||
@@ -1,48 +1,37 @@
|
||||
import * as React from "react";
|
||||
import * as React from 'react'
|
||||
|
||||
export const usePreventClickOnDrag = (thresholdPx = 6) => {
|
||||
const s = React.useRef({ x: 0, y: 0, dragging: false });
|
||||
export function usePreventClickOnDrag(thresholdPx = 6) {
|
||||
const state = React.useRef({ x: 0, y: 0, dragging: false })
|
||||
|
||||
const onPointerDown = React.useCallback((e: React.PointerEvent) => {
|
||||
// 좌클릭만
|
||||
if (e.button !== 0) return;
|
||||
s.current.x = e.clientX;
|
||||
s.current.y = e.clientY;
|
||||
s.current.dragging = false;
|
||||
}, []);
|
||||
const onPointerDown = React.useCallback((event: React.PointerEvent) => {
|
||||
if (event.button !== 0) return
|
||||
state.current = { x: event.clientX, y: event.clientY, dragging: false }
|
||||
}, [])
|
||||
|
||||
const onPointerMove = React.useCallback(
|
||||
(e: React.PointerEvent) => {
|
||||
// 누르고 있을 때만
|
||||
if (e.buttons === 0) return;
|
||||
|
||||
const dx = e.clientX - s.current.x;
|
||||
const dy = e.clientY - s.current.y;
|
||||
|
||||
if (dx * dx + dy * dy >= thresholdPx * thresholdPx) {
|
||||
s.current.dragging = true;
|
||||
}
|
||||
},
|
||||
[thresholdPx]
|
||||
);
|
||||
const onPointerMove = React.useCallback((event: React.PointerEvent) => {
|
||||
if (event.buttons === 0) return
|
||||
const dx = event.clientX - state.current.x
|
||||
const dy = event.clientY - state.current.y
|
||||
if (dx * dx + dy * dy >= thresholdPx * thresholdPx) state.current.dragging = true
|
||||
}, [thresholdPx])
|
||||
|
||||
const onPointerUp = React.useCallback(() => {
|
||||
// click은 pointerup 다음에 발생하므로 "다음 tick"에 false로 복구
|
||||
setTimeout(() => {
|
||||
s.current.dragging = false;
|
||||
}, 0);
|
||||
}, []);
|
||||
state.current.dragging = false
|
||||
}, 0)
|
||||
}, [])
|
||||
|
||||
const wrapClick =
|
||||
(fn: () => void) =>
|
||||
(e: React.MouseEvent) => {
|
||||
if (s.current.dragging) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
fn();
|
||||
};
|
||||
const wrapClick = React.useCallback(
|
||||
(callback: () => void) => (event: React.MouseEvent) => {
|
||||
if (state.current.dragging) {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
return
|
||||
}
|
||||
callback()
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
return { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp, wrapClick };
|
||||
}
|
||||
return { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp, wrapClick }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user