Skip to content

Commit

Permalink
Merge pull request Team-fast4ward#144 from dokimion24/typescript
Browse files Browse the repository at this point in the history
[2/26 20:56] PR
  • Loading branch information
jaehafe authored Mar 5, 2023
2 parents 2afe970 + 96aafba commit 4a94edc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/ts/page/admin/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const setDashBoardChartAmount = (
const thisWeek: number[] = [];

for (let i = 0; i < 7; i++) {
thisWeek.unshift(Number(getDate().today) - i);
thisWeek.unshift(Number(getDate(i).date));
}

const amountOfthisWeek: number[] = [];
Expand Down
20 changes: 11 additions & 9 deletions src/ts/page/admin/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@ export const handleOrderPage = async (): Promise<void> => {
'.order-container__search-container--input input',
);

const searchedOrderBtn = $<HTMLButtonElement>(
'.order-container__search-container--input input',
);

const searchOrderHandler = (): void => {
const filteredOrder = orders.filter((order) =>
order.user.displayName.includes(searchedOrderInput.value),
order.user.displayName
.trim()
.toLowerCase()
.includes(searchedOrderInput.value),
);

orders = filteredOrder;

orderList.innerHTML = ``;
renderPageBtn(orderPageBtn, filteredOrder, 1, itemsPerPage, 1);
newOrders = getOrderCurrentPage(filteredOrder, 1, itemsPerPage);
Expand All @@ -67,19 +72,16 @@ export const handleOrderPage = async (): Promise<void> => {

/** 거래내역 검색(enter) 이벤트 리스너 */
searchedOrderInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.isComposing) {
if (e.key === 'Enter') {
searchOrderHandler();
}
});

searchedOrderInput.addEventListener('input', async () => {
searchedOrderInput.value === '' ? (orders = await getAllOrder()) : orders;
/** 거래내역 검색(버튼 클릭) 이벤트 리스너 */
searchedOrderBtn.addEventListener('click', async () => {
searchOrderHandler();
});

/** 거래내역 검색(버튼 클릭) 이벤트 리스너 */
// searchedOrderBtn.addEventListener('click', searchOrderHandler);

/** 버튼 클릭 페이지 이동 이벤트 리스너 */
orderPageBtn.addEventListener('click', (e: MouseEvent) => {
if ((e.target as HTMLButtonElement).classList.contains('btn-page')) return;
Expand Down
38 changes: 14 additions & 24 deletions src/ts/page/admin/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,29 @@ let newProducts = getProductCurrentPage(

/** 상품관리 페이지 핸들러 */
export const handleProductPage = async (): Promise<void> => {
const productList = $('.product-container__list') as HTMLUListElement;
const checkProductAll = $(
const productList = $<HTMLUListElement>('.product-container__list');
const checkProductAll = $<HTMLInputElement>(
'.product-container__title input',
) as HTMLInputElement;
const productPageBtn = $('.product-container__btn-page') as HTMLButtonElement;
);
const productPageBtn = $<HTMLButtonElement>('.product-container__btn-page');

products = await getAllProducts();

setUpUI(productPageBtn, productList);

const searchedProductInput = $(
const searchedProductInput = $<HTMLInputElement>(
'.product-container__search-container--input input',
) as HTMLInputElement;
);

const searchedProductBtn = $<HTMLButtonElement>(
'.product-container__search-container--input input',
);

const searchProductHandler = (): void => {
const filteredProduct = products.filter((product) =>
product.title.toLowerCase().includes(searchedProductInput.value),
product.title.trim().toLowerCase().includes(searchedProductInput.value),
);

products = filteredProduct;
productList.innerHTML = ``;
renderPageBtn(productPageBtn, filteredProduct, 1, itemsPerPage, 1);
newProducts = getProductCurrentPage(filteredProduct, 1, itemsPerPage);
Expand All @@ -68,21 +71,16 @@ export const handleProductPage = async (): Promise<void> => {

/** 상품 검색(enter) 이벤트 리스너 */
searchedProductInput.addEventListener('keydown', (e: KeyboardEvent) => {
if (e.key === 'Enter' && !e.isComposing) {
if (e.key === 'Enter') {
searchProductHandler();
}
});

searchedProductInput.addEventListener('input', async () => {
searchedProductInput.value === ''
? (products = await getAllProducts())
: products;
/** 상품 검색 이벤트 리스너 */
searchedProductBtn.addEventListener('click', async () => {
searchProductHandler();
});

/** 상품 검색(버튼 클릭) 이벤트 리스너 */
// searchedProductBtn.addEventListener('click', searchProductHandler);

/** 페이지 버튼 클릭 이벤트 리스너 */
productPageBtn.addEventListener('click', (e: MouseEvent) => {
if (
Expand Down Expand Up @@ -168,14 +166,6 @@ export const handleProductPage = async (): Promise<void> => {
}

if (confirm('선택한 상품을 삭제하시겠습니까? ')) {
// async function deleteProductPromise(newProductsEl) {
// const productsMap = newProductsEl.map(async (newProductEl) => {
// return await deleteProduct(newProductEl.dataset.id);
// });
// return productsMap;
// }

// await deleteProductPromise(newProductsEl);
await Promise.all(
newProductsEl.map(
async (newProductEl: any) =>
Expand Down
27 changes: 21 additions & 6 deletions src/ts/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
interface getDateInterface {
date: Date;
year: string;
month: string;
today: string;
date: string;
}

export const getDate = (): getDateInterface => {
export const getDate = (prevDateNum: number = 0): getDateInterface => {
const today = new Date();

const dateObj: getDateInterface = {
date: today,
year: String(today.getFullYear()),
month: String(today.getMonth() + 1).padStart(2, '0'),
today: String(today.getDate()).padStart(2, '0'),
date: String(today.getDate()).padStart(2, '0'),
};

return dateObj;
if (!prevDateNum) return dateObj;
else {
const prevDate = new Date(
Number(dateObj.year),
Number(dateObj.month) - 1,
Number(dateObj.date) - prevDateNum,
);

const prevDateObj: getDateInterface = {
year: String(prevDate.getFullYear()),
month: String(prevDate.getMonth() + 1).padStart(2, '0'),
date: String(prevDate.getDate()).padStart(2, '0'),
};

return prevDateObj;
}
};

0 comments on commit 4a94edc

Please sign in to comment.