@@ -13,7 +13,6 @@ import { DeleteModal } from "@/components/modal/DeleteModal";
1313import { TEAM_ID } from "@/constants/team" ;
1414import { Search } from "lucide-react" ;
1515import { toast } from "react-toastify" ;
16-
1716import {
1817 DndContext ,
1918 closestCenter ,
@@ -28,6 +27,7 @@ import {
2827 arrayMove ,
2928} from "@dnd-kit/sortable" ;
3029import SortableCardButton from "@/components/button/SortableCardButton" ;
30+ import { dashboardOrdersTable } from "@/lib/dashboardOrderDB" ;
3131
3232interface Dashboard {
3333 id : number ;
@@ -56,7 +56,7 @@ export default function MyDashboardPage() {
5656 const [ isDeleteModalOpen , setIsDeleteModalOpen ] = useState ( false ) ;
5757 const [ isConfirmDeleteModalOpen , setIsConfirmDeleteModalOpen ] =
5858 useState ( false ) ;
59- const itemsPerPage = 6 ; // 버튼 포함 6개
59+ const itemsPerPage = 6 ;
6060
6161 const sensors = useSensors (
6262 useSensor ( PointerSensor , {
@@ -80,7 +80,18 @@ export default function MyDashboardPage() {
8080 const fetchDashboards = async ( ) => {
8181 try {
8282 const res = await getDashboards ( { } ) ;
83- setDashboardList ( res . dashboards ) ;
83+ const localOrder = await dashboardOrdersTable . get ( TEAM_ID ) ;
84+
85+ let orderedList = res . dashboards ;
86+ if ( localOrder ?. order ) {
87+ orderedList = res . dashboards
88+ . slice ( )
89+ . sort (
90+ ( a , b ) =>
91+ localOrder . order . indexOf ( a . id ) - localOrder . order . indexOf ( b . id )
92+ ) ;
93+ }
94+ setDashboardList ( orderedList ) ;
8495 } catch ( error ) {
8596 console . error ( "대시보드 불러오기 실패:" , error ) ;
8697 }
@@ -121,7 +132,7 @@ export default function MyDashboardPage() {
121132 setSelectedDashboardId ( null ) ;
122133 } ;
123134
124- const handleDragEnd = ( event : DragEndEvent ) => {
135+ const handleDragEnd = async ( event : DragEndEvent ) => {
125136 const { active, over } = event ;
126137 if ( ! over || active . id === over . id ) return ;
127138
@@ -130,6 +141,12 @@ export default function MyDashboardPage() {
130141
131142 const newOrder = arrayMove ( dashboardList , oldIndex , newIndex ) ;
132143 setDashboardList ( newOrder ) ;
144+
145+ //D&D 로컬 순서 저장
146+ await dashboardOrdersTable . put ( {
147+ teamId : TEAM_ID ,
148+ order : newOrder . map ( ( d ) => d . id ) ,
149+ } ) ;
133150 } ;
134151
135152 return (
0 commit comments