Skip to content

Commit

Permalink
🔨 chore: Add comments in codes
Browse files Browse the repository at this point in the history
- include comments to make the code easier to understand.

Related issue: #43
  • Loading branch information
Regulus0811 committed Feb 20, 2024
1 parent a9a264f commit 042c6df
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/prompts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const MyPdfViewer = () => {
const [inputValue, setInputValue] = useState<string>('1');
const pageRefs = useRef<(React.RefObject<HTMLDivElement> | null)[]>([]);

// PDFファイルが読み込まれたときの処理
function onDocumentLoadSuccess({numPages}: {numPages: number}) {
setNumPages(numPages);
pageRefs.current = Array(numPages)
.fill(null)
.map(() => React.createRef());
}

// ファイルを選択したときの処理
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
Expand All @@ -33,6 +35,7 @@ const MyPdfViewer = () => {
}
};

// ページが表示されたときの処理
const observePage = (pageIndex: number) => {
const observer = new IntersectionObserver(
entries => {
Expand All @@ -43,6 +46,8 @@ const MyPdfViewer = () => {
},
{threshold: 0.5}
);

// ページが表示されたときにページ番号を更新する
const pageElement = pageRefs.current[pageIndex]?.current;
if (pageElement) {
observer.observe(pageElement);
Expand All @@ -54,13 +59,15 @@ const MyPdfViewer = () => {
};
};

// ページ番号を指定してページに移動する
const goToPage = (page: number) => {
const pageElement = pageRefs.current[page - 1]?.current;
if (pageElement) {
pageElement.scrollIntoView();
}
};

// ページ数が変わったときにページの表示を監視する
useEffect(() => {
const cleanupFunctions = Array(numPages || 0)
.fill(null)
Expand Down

0 comments on commit 042c6df

Please sign in to comment.