Skip to content

Commit

Permalink
Merge pull request #26 from a-company-jp/feature/eslins-fix
Browse files Browse the repository at this point in the history
ESLintのエラーを直す
  • Loading branch information
Najah7 authored Apr 14, 2024
2 parents a57bbd8 + 299666e commit 68aeaf2
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function App() {

const [activePage, setActivePage] = useState(1);
const [uploaded, setUploaded] = useState(false);
const { LGTMUrls, loading, error } = useLGTMFetch(activePage, uploaded, setUploaded);
const {LGTMUrls} = useLGTMFetch(activePage, uploaded, setUploaded);

return (
<UIProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ export const Pagination = ({ activePage, setActivePage }: PaginationProps) => {
return (
activePage === pageNum ? (
<li className={styles.itemBox}>
<a
<button
onClick={() => clickHandler(pageNum)}
className={styles.active}
>
{pageNum}
</a>
</button>
</li>
) : (
<li className={styles.itemBox}>
<a
<button
onClick={() => clickHandler(pageNum)}
className={styles.item}
>
{pageNum}
</a>
</button>
</li>
)
)
Expand Down
2 changes: 0 additions & 2 deletions src/components/atoms/ButtonToChromeExtension/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { config } from "process";

const ButtonToChromeExtension = (): JSX.Element => {

// TODO: set environment variable
Expand Down
4 changes: 2 additions & 2 deletions src/components/atoms/NextButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const NextButton = ({ clickHandler }: NextButtonProps) => {

return (
<li>
<a
<button
onClick={clickHandler}
className={styles.nextButton}
>
Expand All @@ -26,7 +26,7 @@ const NextButton = ({ clickHandler }: NextButtonProps) => {
clip-rule="evenodd"
/>
</svg>
</a>
</button>
</li>
)
}
Expand Down
6 changes: 2 additions & 4 deletions src/components/atoms/PrevButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { click } from "@testing-library/user-event/dist/click";

type PrevButtonProps = {
clickHandler: () => void;
}
Expand All @@ -9,7 +7,7 @@ const PrevButton = ({ clickHandler }: PrevButtonProps) => {
prevButton: 'inline-flex size-12 items-center justify-center rounded border border-gray-100 bg-white text-gray-900 rtl:rotate-180 hover:bg-gray-200',
}
return (
<a
<button
onClick={clickHandler}
className={styles.prevButton}
>
Expand All @@ -26,7 +24,7 @@ const PrevButton = ({ clickHandler }: PrevButtonProps) => {
clip-rule="evenodd"
/>
</svg>
</a>
</button>
)
}

Expand Down
32 changes: 10 additions & 22 deletions src/hooks/useDisplayPage.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { useEffect, useState } from 'react';
import { useEffect, useState, useCallback } from 'react';

type UsePaginationProps = {
activePage: number;
setActivePage: (num: number) => void;
}

const useDisplayPageNums = ({ activePage, setActivePage }: UsePaginationProps) => {

// TODO: make it dynamic
const NUM_MAX_PAGE = parseInt(process.env.REACT_APP_MAX_PAGE || '20');
const NUM_DISPLAY_PAGE = 5;

const [pageNums, setPageNums] = useState<number[]>([1, 2, 3, 4, 5]);

const generatePageNums = useCallback((numActivePage: number): number[] => {
if (numActivePage < 3) {
return [1, 2, 3, 4, 5];
} else if (numActivePage > NUM_MAX_PAGE - 3) {
return Array.from({ length: NUM_DISPLAY_PAGE }, (_, index) => NUM_MAX_PAGE - 4 + index);
}
return Array.from({ length: NUM_DISPLAY_PAGE }, (_, index) => numActivePage - 2 + index);
}, [NUM_MAX_PAGE, NUM_DISPLAY_PAGE]);

useEffect(() => {
if (activePage < 1) {
Expand All @@ -24,25 +30,7 @@ const useDisplayPageNums = ({ activePage, setActivePage }: UsePaginationProps) =
} else {
setPageNums(generatePageNums(activePage));
}
}, [activePage]);

const generatePageNums = (numActivePage: number): number[] => {
// small page number case
if (numActivePage < 3) {
return [1, 2, 3, 4, 5];
} else if (numActivePage > NUM_MAX_PAGE - 3) { // large page number case
return Array.from({ length: NUM_DISPLAY_PAGE }, (_, index) => {
return NUM_MAX_PAGE - 4 + index;
});
}

// usual case
return Array.from({ length: NUM_DISPLAY_PAGE }, (_, index) => {
return numActivePage - 2 + index;
});
}


}, [activePage, generatePageNums, NUM_MAX_PAGE, setActivePage]);

return { pageNums };
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLGTMFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const useLGTMFetch = (activePage: number, uploaded: boolean, setUploaded: (uploa
};

fetchData();
}, [activePage, uploaded]);
}, [activePage, uploaded, setUploaded]);

return { LGTMUrls, loading, error };
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSendImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from 'react';
import { set, useForm } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import { post } from '../fetch/LGTM'

export const IMAGE_ID = 'image';
Expand Down

0 comments on commit 68aeaf2

Please sign in to comment.