Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/f 35 pdf preview implementation #14

Merged

Conversation

bohdangarchu
Copy link
Collaborator

@Tschonti please approve if it is ok that I add "react/jsx-no-bind": "off" to our linter config. I think we need it for defining functions inside components like handleScroll (see PdfViewer.tsx).

@@ -1,3 +1,8 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

/* PdfViewer.css */
canvas.react-pdf__Page__canvas {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to use css here to add padding between pages

@Tschonti
Copy link
Collaborator

Tschonti commented Nov 5, 2024

Yeah I think it's okay, I'm not even sure how you're supposed to respect this rule in a functional component

Copy link
Collaborator

@marinovl7 marinovl7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall great job! Take a look at my comments, just smal code styling issues I found. Also few things to add here:

  1. Can you please add the download PDF Functionality?
  2. Can you think how we can get the documents from this endpoint https://static.hungermapdata.org/insight-reports/latest/country.json and display them in the previewer?
  3. add border to the navbar and the color could be like light gray in light mode and dark grey in dark mode.

But overall quality and functionality is great! Good job!

Comment on lines 23 to 39
const handleScroll = () => {
const pages = document.querySelectorAll('.react-pdf__Page');
let currentPage = pageNumber;

pages.forEach((page, index) => {
const rect = page.getBoundingClientRect();
const pageTop = rect.top;
const pageBottom = rect.bottom;
const viewportMidpoint = window.innerHeight / 2;

if (pageTop < viewportMidpoint && pageBottom > viewportMidpoint) {
currentPage = index + 1;
}
});

setPageNumber(currentPage);
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be exported to an operations file in operations/pdf-previewer/PdfPreviewerOperations.ts

const [selectionText, setSelectionText] = useState<string | null>(null);
const [tooltipPosition, setTooltipPosition] = useState<{ top: number; left: number } | null>(null);

const handleScroll = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precise naming handleDocumentScroll + return type of the function is missing

Comment on lines 41 to 44
function onDocumentLoadSuccess({ numPages }: { numPages: number }): void {
setTotalPages(numPages);
window.addEventListener('scroll', handleScroll);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not use arrow function declaration and function declaration in the same file. Chose one of both approaches and be consistent

Comment on lines 46 to 48
function onSelectStart() {
setSelectionText(null);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

window.addEventListener('scroll', handleScroll);
}

function onSelectStart() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type of the function is missing

setSelectionText(null);
}

function onSelectEnd() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here + return type

@@ -26,7 +28,7 @@ module.exports = {
light: {
colors: {
primary: { DEFAULT: '#157DBC', foreground: '#F5F5F5' },
secondary: '#EEEEEE',
secondary: '#666666',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this corresponds to our secondary color used in figma designs

Copy link
Collaborator

@marinovl7 marinovl7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job!

@marinovl7 marinovl7 merged commit 0a13259 into main Nov 8, 2024
1 check passed
@marinovl7 marinovl7 deleted the feature/f-35-pdf-preview-library-research-and-implementation branch November 8, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants