-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: AdminPage SSR로 수정 * refactor: useSWR 제거 * refactor: admin쪽 훅 분리
- Loading branch information
Showing
22 changed files
with
137 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,33 @@ | ||
'use server'; | ||
|
||
import { ImportantPreview, SlidePreview } from '@/types/admin'; | ||
|
||
import { getRequest } from './network/client'; | ||
import { getRequest, patchRequest } from './network/server'; | ||
|
||
// GET | ||
|
||
export const getSlides = (pageNum: number) => | ||
getRequest( | ||
'/admin/slide', | ||
{ pageNum }, | ||
{ | ||
next: { tags: ['slide'] }, | ||
}, | ||
) as Promise<{ | ||
getRequest('/admin/slide', { pageNum }, { next: { tags: ['slide'] } }) as Promise<{ | ||
slides: SlidePreview[]; | ||
total: number; | ||
}>; | ||
|
||
export const getImportants = (pageNum: number) => | ||
getRequest( | ||
'/admin/important', | ||
{ pageNum }, | ||
{ | ||
next: { tags: ['important'] }, | ||
}, | ||
) as Promise<{ | ||
getRequest('/admin/important', { pageNum }, { next: { tags: ['important'] } }) as Promise<{ | ||
importants: ImportantPreview[]; | ||
total: number; | ||
}>; | ||
|
||
// export const getSlides = async ( | ||
// pageNum: number, | ||
// ): Promise<{ slides: SlidePreview[]; total: number }> => ({ | ||
// slides: [], | ||
// total: 0, | ||
// }); | ||
|
||
// export const getImportants = async ( | ||
// pageNum: number, | ||
// ): Promise<{ importants: ImportantPreview[]; total: number }> => ({ | ||
// importants: [], | ||
// total: 0, | ||
// }); | ||
|
||
// export const patchMultipleSlides = (newsIdList: number[]) => | ||
// patchRequest('/admin/slide', { | ||
// headers: { 'Content-Type': 'application/json' }, | ||
// body: JSON.stringify({ newsIdList }), | ||
// }); | ||
|
||
// export const patchMultipleImportants = (targetInfos: { id: number; category: string }[]) => | ||
// patchRequest('/admin/important', { | ||
// headers: { 'Content-Type': 'application/json' }, | ||
// body: JSON.stringify({ targetInfos }), | ||
// }); | ||
// PATCH | ||
|
||
export const patchMultipleSlides = (newsIdList: number[]) => | ||
patchRequest('/admin/slide', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ newsIdList }), | ||
}); | ||
|
||
export const patchMultipleImportants = (targetInfos: { id: number; category: string }[]) => | ||
patchRequest('/admin/important', { | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ targetInfos }), | ||
}); |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useReducer } from 'react'; | ||
|
||
import { ImportantCategory, ImportantPostIdentifier } from '@/types/admin'; | ||
|
||
export default function useImportantSelect() { | ||
const value = useReducer(reducer, []); | ||
return value; | ||
} | ||
|
||
type ReducerAction = | ||
| { type: 'ADD' | 'DELETE'; identifier: { id: number; category: ImportantCategory } } | ||
| { type: 'RESET' }; | ||
|
||
const reducer = (state: ImportantPostIdentifier[], action: ReducerAction) => { | ||
switch (action.type) { | ||
case 'ADD': | ||
return [...state, action.identifier]; | ||
case 'DELETE': | ||
return state.filter( | ||
(info) => | ||
!(info.id === action.identifier.id && info.category === action.identifier.category), | ||
); | ||
case 'RESET': | ||
return []; | ||
default: | ||
throw new Error('undefined action'); | ||
} | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.